From 52774b9a07f9f9bd2f8b7f79aeacb9c5a43287fe Mon Sep 17 00:00:00 2001 From: Viktor Stanchev Date: Sat, 23 Apr 2022 23:39:39 +0000 Subject: [PATCH 1/8] use "embed" in generated code --- codegen/generated!.gotpl | 14 +- codegen/root_.gotpl | 15 +- .../followschema/root_.generated.go | 678 +----------------- codegen/testserver/singlefile/generated.go | 677 +---------------- 4 files changed, 102 insertions(+), 1282 deletions(-) diff --git a/codegen/generated!.gotpl b/codegen/generated!.gotpl index 5df5efef276..1c509b4d03b 100644 --- a/codegen/generated!.gotpl +++ b/codegen/generated!.gotpl @@ -7,6 +7,7 @@ {{ reserveImport "sync/atomic" }} {{ reserveImport "errors" }} {{ reserveImport "bytes" }} +{{ reserveImport "embed" }} {{ reserveImport "github.com/vektah/gqlparser/v2" "gqlparser" }} {{ reserveImport "github.com/vektah/gqlparser/v2/ast" }} @@ -235,9 +236,20 @@ return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } + //go:embed{{- range $source := .Config.Sources }} {{$source.Name|quote}}{{- end }} + var sourcesFS embed.FS + + func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) + } + var sources = []*ast.Source{ {{- range $source := .Config.Sources }} - {Name: {{$source.Name|quote}}, Input: {{$source.Input|rawQuote}}, BuiltIn: {{$source.BuiltIn}}}, + {Name: {{$source.Name|quote}}, Input: sourceData({{$source.Name|quote}}), BuiltIn: {{$source.BuiltIn}}}, {{- end }} } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/codegen/root_.gotpl b/codegen/root_.gotpl index 0d6dc0eb15d..b34f174617e 100644 --- a/codegen/root_.gotpl +++ b/codegen/root_.gotpl @@ -7,6 +7,7 @@ {{ reserveImport "sync/atomic" }} {{ reserveImport "errors" }} {{ reserveImport "bytes" }} +{{ reserveImport "embed" }} {{ reserveImport "github.com/vektah/gqlparser/v2" "gqlparser" }} {{ reserveImport "github.com/vektah/gqlparser/v2/ast" }} @@ -202,9 +203,21 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } + +//go:embed{{- range $source := .Config.Sources }} {{$source.Name|quote}}{{- end }} +var sourcesFS embed.FS + +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) +} + var sources = []*ast.Source{ {{- range $source := .Config.Sources }} - {Name: {{$source.Name|quote}}, Input: {{$source.Input|rawQuote}}, BuiltIn: {{$source.BuiltIn}}}, + {Name: {{$source.Name|quote}}, Input: sourceData({{$source.Name|quote}}), BuiltIn: {{$source.BuiltIn}}}, {{- end }} } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/codegen/testserver/followschema/root_.generated.go b/codegen/testserver/followschema/root_.generated.go index e1c3b6f2a61..c8f6b11a8fb 100644 --- a/codegen/testserver/followschema/root_.generated.go +++ b/codegen/testserver/followschema/root_.generated.go @@ -5,7 +5,9 @@ package followschema import ( "bytes" "context" + "embed" "errors" + "fmt" "github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql/introspection" @@ -2009,648 +2011,44 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var sources = []*ast.Source{ - {Name: "builtinscalar.graphql", Input: ` -""" -Since gqlgen defines default implementation for a Map scalar, this tests that the builtin is _not_ -added to the TypeMap -""" -type Map { - id: ID! -} -`, BuiltIn: false}, - {Name: "complexity.graphql", Input: `extend type Query { - overlapping: OverlappingFields -} - -type OverlappingFields { - oneFoo: Int! @goField(name: "foo") - twoFoo: Int! @goField(name: "foo") - oldFoo: Int! @goField(name: "foo", forceResolver: true) - newFoo: Int! - new_foo: Int! -} -`, BuiltIn: false}, - {Name: "defaults.graphql", Input: `extend type Query { - defaultParameters( - falsyBoolean: Boolean = false - truthyBoolean: Boolean = true - ): DefaultParametersMirror! -} - -extend type Mutation { - defaultInput(input: DefaultInput!): DefaultParametersMirror! -} - -input DefaultInput { - falsyBoolean: Boolean = false - truthyBoolean: Boolean = true -} - -type DefaultParametersMirror { - falsyBoolean: Boolean - truthyBoolean: Boolean -} -`, BuiltIn: false}, - {Name: "directive.graphql", Input: `directive @length(min: Int!, max: Int, message: String) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | FIELD_DEFINITION -directive @range(min: Int = 0, max: Int) on ARGUMENT_DEFINITION -directive @custom on ARGUMENT_DEFINITION -directive @logged(id: UUID!) on FIELD -directive @toNull on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | FIELD_DEFINITION -directive @directive1 on FIELD_DEFINITION -directive @directive2 on FIELD_DEFINITION -directive @directive3 on INPUT_OBJECT -directive @unimplemented on FIELD_DEFINITION -directive @order1(location: String!) repeatable on FIELD_DEFINITION | OBJECT -directive @order2(location: String!) on OBJECT - -extend type Query { - directiveArg(arg: String! @length(min:1, max: 255, message: "invalid length")): String - directiveNullableArg(arg: Int @range(min:0), arg2: Int @range, arg3: String @toNull): String - directiveInputNullable(arg: InputDirectives): String - directiveInput(arg: InputDirectives!): String - directiveInputType(arg: InnerInput! @custom): String - directiveObject: ObjectDirectives @order1(location: "Query_field") - directiveObjectWithCustomGoModel: ObjectDirectivesWithCustomGoModel - directiveFieldDef(ret: String!): String! @length(min: 1, message: "not valid") - directiveField: String - directiveDouble: String @directive1 @directive2 - directiveUnimplemented: String @unimplemented -} - -extend type Subscription { - directiveArg(arg: String! @length(min:1, max: 255, message: "invalid length")): String - directiveNullableArg(arg: Int @range(min:0), arg2: Int @range, arg3: String @toNull): String - directiveDouble: String @directive1 @directive2 - directiveUnimplemented: String @unimplemented -} - -input InputDirectives @directive3 { - text: String! @length(min: 0, max: 7, message: "not valid") - nullableText: String @toNull - inner: InnerDirectives! - innerNullable: InnerDirectives - thirdParty: ThirdParty @length(min: 0, max: 7) -} - -input InnerDirectives { - message: String! @length(min: 1, message: "not valid") -} - -type ObjectDirectives @order1(location: "order1_1") @order1(location: "order1_2") @order2(location: "order2_1") { - text: String! @length(min: 0, max: 7, message: "not valid") - nullableText: String @toNull - order: [String!]! -} - -type ObjectDirectivesWithCustomGoModel { - nullableText: String @toNull -} -`, BuiltIn: false}, - {Name: "embedded.graphql", Input: `extend type Query { - embeddedCase1: EmbeddedCase1 - embeddedCase2: EmbeddedCase2 - embeddedCase3: EmbeddedCase3 -} - -type EmbeddedCase1 @goModel(model:"followschema.EmbeddedCase1") { - exportedEmbeddedPointerExportedMethod: String! -} - -type EmbeddedCase2 @goModel(model:"followschema.EmbeddedCase2") { - unexportedEmbeddedPointerExportedMethod: String! -} - -type EmbeddedCase3 @goModel(model:"followschema.EmbeddedCase3") { - unexportedEmbeddedInterfaceExportedMethod: String! -} -`, BuiltIn: false}, - {Name: "enum.graphql", Input: `enum EnumTest { - OK - NG -} - -input InputWithEnumValue { - enum: EnumTest! -} - -extend type Query { - enumInInput(input: InputWithEnumValue): EnumTest! -} -`, BuiltIn: false}, - {Name: "interfaces.graphql", Input: `extend type Query { - shapes: [Shape] - noShape: Shape @makeNil - node: Node! - noShapeTypedNil: Shape @makeTypedNil - animal: Animal @makeTypedNil - notAnInterface: BackedByInterface -} - -interface Animal { - species: String! -} - -type BackedByInterface { - id: String! - thisShouldBind: String! - thisShouldBindWithError: String! -} - -type Dog implements Animal { - species: String! - dogBreed: String! -} - -type Cat implements Animal { - species: String! - catBreed: String! -} - -type Coordinates { - x: Float! - y: Float! -} -interface Shape { - area: Float - coordinates: Coordinates -} - -type Circle implements Shape { - radius: Float - area: Float - coordinates: Coordinates -} -type Rectangle implements Shape { - length: Float - width: Float - area: Float - coordinates: Coordinates -} -union ShapeUnion @goModel(model: "followschema.ShapeUnion") = Circle | Rectangle - -directive @makeNil on FIELD_DEFINITION -directive @makeTypedNil on FIELD_DEFINITION - -interface Node { - id: ID! - child: Node! -} - -type ConcreteNodeA implements Node { - id: ID! - child: Node! - name: String! -} - -" Implements the Node interface with another interface " -type ConcreteNodeInterface implements Node { - id: ID! - child: Node! -} -`, BuiltIn: false}, - {Name: "issue896.graphql", Input: `# This example should build stable output. If the file content starts -# alternating nondeterministically between two outputs, then see -# https://github.com/99designs/gqlgen/issues/896. - -extend schema { - query: Query - subscription: Subscription -} - -type CheckIssue896 {id: Int} - -extend type Query { - issue896a: [CheckIssue896!] # Note the "!" or lack thereof. -} - -extend type Subscription { - issue896b: [CheckIssue896] # Note the "!" or lack thereof. -} -`, BuiltIn: false}, - {Name: "loops.graphql", Input: `type LoopA { - b: LoopB! -} - -type LoopB { - a: LoopA! -} -`, BuiltIn: false}, - {Name: "maps.graphql", Input: `extend type Query { - mapStringInterface(in: MapStringInterfaceInput): MapStringInterfaceType - mapNestedStringInterface(in: NestedMapInput): MapStringInterfaceType -} - -type MapStringInterfaceType @goModel(model: "map[string]interface{}") { - a: String - b: Int -} - -input MapStringInterfaceInput @goModel(model: "map[string]interface{}") { - a: String - b: Int -} - -input NestedMapInput { - map: MapStringInterfaceInput -} -`, BuiltIn: false}, - {Name: "mutation_with_custom_scalar.graphql", Input: `extend type Mutation { - updateSomething(input: SpecialInput!): String! -} - -scalar Email - -input SpecialInput { - nesting: NestedInput! -} - -input NestedInput { - field: Email! -} -`, BuiltIn: false}, - {Name: "nulls.graphql", Input: `extend type Query { - errorBubble: Error - errorBubbleList: [Error!] - errorList: [Error] - errors: Errors - valid: String! -} - -extend type Subscription { - errorRequired: Error! -} - -type Errors { - a: Error! - b: Error! - c: Error! - d: Error! - e: Error! -} - -type Error { - id: ID! - errorOnNonRequiredField: String - errorOnRequiredField: String! - nilOnRequiredField: String! -} -`, BuiltIn: false}, - {Name: "panics.graphql", Input: `extend type Query { - panics: Panics -} - -type Panics { - fieldScalarMarshal: [MarshalPanic!]! - fieldFuncMarshal(u: [MarshalPanic!]!): [MarshalPanic!]! - argUnmarshal(u: [MarshalPanic!]!): Boolean! - -} - -scalar MarshalPanic -`, BuiltIn: false}, - {Name: "primitive_objects.graphql", Input: `extend type Query { - primitiveObject: [Primitive!]! - primitiveStringObject: [PrimitiveString!]! -} +//go:embed "builtinscalar.graphql" "complexity.graphql" "defaults.graphql" "directive.graphql" "embedded.graphql" "enum.graphql" "interfaces.graphql" "issue896.graphql" "loops.graphql" "maps.graphql" "mutation_with_custom_scalar.graphql" "nulls.graphql" "panics.graphql" "primitive_objects.graphql" "ptr_to_ptr_input.graphql" "ptr_to_slice.graphql" "scalar_context.graphql" "scalar_default.graphql" "schema.graphql" "slices.graphql" "typefallback.graphql" "useptr.graphql" "v-ok.graphql" "validtypes.graphql" "variadic.graphql" "weird_type_cases.graphql" "wrapped_type.graphql" +var sourcesFS embed.FS -type Primitive { - value: Int! - squared: Int! -} - -type PrimitiveString { - value: String! - doubled: String! - len: Int! -} -`, BuiltIn: false}, - {Name: "ptr_to_ptr_input.graphql", Input: `type PtrToPtrOuter { - name: String! - inner: PtrToPtrInner - stupidInner: PtrToPtrInner -} - -type PtrToPtrInner { - key: String! - value: String! -} - -input UpdatePtrToPtrOuter { - name: String - inner: UpdatePtrToPtrInner - stupidInner: UpdatePtrToPtrInner -} - -input UpdatePtrToPtrInner { - key: String - value: String -} - -extend type Mutation { - updatePtrToPtr(input: UpdatePtrToPtrOuter!): PtrToPtrOuter! -} -`, BuiltIn: false}, - {Name: "ptr_to_slice.graphql", Input: `type PtrToSliceContainer { - ptrToSlice: [String!] -} - -extend type Query { - ptrToSliceContainer: PtrToSliceContainer! -} -`, BuiltIn: false}, - {Name: "scalar_context.graphql", Input: `extend type Query { - infinity: Float! - stringFromContextInterface: StringFromContextInterface! - stringFromContextFunction: StringFromContextFunction! -} - -scalar StringFromContextInterface -scalar StringFromContextFunction -`, BuiltIn: false}, - {Name: "scalar_default.graphql", Input: `extend type Query { - defaultScalar(arg: DefaultScalarImplementation! = "default"): DefaultScalarImplementation! -} - -""" This doesnt have an implementation in the typemap, so it should act like a string """ -scalar DefaultScalarImplementation - -type EmbeddedDefaultScalar { - value: DefaultScalarImplementation -} -`, BuiltIn: false}, - {Name: "schema.graphql", Input: `directive @goModel( - model: String - models: [String!] -) on OBJECT | INPUT_OBJECT | SCALAR | ENUM | INTERFACE | UNION -directive @goField( - forceResolver: Boolean - name: String -) on INPUT_FIELD_DEFINITION | FIELD_DEFINITION - -type Query { - invalidIdentifier: InvalidIdentifier - collision: It - mapInput(input: Changes): Boolean - recursive(input: RecursiveInputSlice): Boolean - nestedInputs(input: [[OuterInput]] = [[{ inner: { id: 1 } }]]): Boolean - nestedOutputs: [[OuterObject]] - modelMethods: ModelMethods - user(id: Int!): User! - nullableArg(arg: Int = 123): String - inputSlice(arg: [String!]!): Boolean! - inputNullableSlice(arg: [String!]): Boolean! - shapeUnion: ShapeUnion! - autobind: Autobind - deprecatedField: String! @deprecated(reason: "test deprecated directive") -} - -type Subscription { - updated: String! - initPayload: String! -} - -type Pet { - id: Int! - friends(limit: Int): [Pet!] @goField(forceResolver: true) -} - -type User { - id: Int! - friends: [User!]! @goField(forceResolver: true) - created: Time! - updated: Time - pets(limit: Int): [Pet!] @goField(forceResolver: true) -} - -type Autobind { - int: Int! - int32: Int! - int64: Int! - - idStr: ID! - idInt: ID! -} - -type ModelMethods { - resolverField: Boolean! - noContext: Boolean! - withContext: Boolean! -} - -type InvalidIdentifier { - id: Int! -} - -type It { - id: ID! -} - -input Changes @goModel(model: "map[string]interface{}") { - a: Int - b: Int -} - -input RecursiveInputSlice { - self: [RecursiveInputSlice!] -} - -input InnerInput { - id: Int! -} - -input OuterInput { - inner: InnerInput! -} - -scalar ThirdParty @goModel(model:"followschema.ThirdParty") - -type OuterObject { - inner: InnerObject! -} - -type InnerObject { - id: Int! -} - -type ForcedResolver { - field: Circle @goField(forceResolver: true) -} - -type EmbeddedPointer @goModel(model:"followschema.EmbeddedPointerModel") { - ID: String - Title: String -} - -scalar UUID - -enum Status { - OK - ERROR -} - -scalar Time -`, BuiltIn: false}, - {Name: "slices.graphql", Input: `extend type Query { - slices: Slices - scalarSlice: Bytes! -} - -type Slices { - test1: [String] - test2: [String!] - test3: [String]! - test4: [String!]! -} - -scalar Bytes -`, BuiltIn: false}, - {Name: "typefallback.graphql", Input: `extend type Query { - fallback(arg: FallbackToStringEncoding!): FallbackToStringEncoding! -} - -enum FallbackToStringEncoding { - A - B - C -} -`, BuiltIn: false}, - {Name: "useptr.graphql", Input: `type A { - id: ID! -} - -type B { - id: ID! -} - -union TestUnion = A | B - -extend type Query { - optionalUnion: TestUnion -} -`, BuiltIn: false}, - {Name: "v-ok.graphql", Input: `extend type Query { - vOkCaseValue: VOkCaseValue - vOkCaseNil: VOkCaseNil -} - -type VOkCaseValue @goModel(model:"followschema.VOkCaseValue") { - value: String -} - -type VOkCaseNil @goModel(model:"followschema.VOkCaseNil") { - value: String -} -`, BuiltIn: false}, - {Name: "validtypes.graphql", Input: `extend type Query { - validType: ValidType -} - -""" These things are all valid, but without care generate invalid go code """ -type ValidType { - differentCase: String! - different_case: String! @goField(name:"DifferentCaseOld") - validInputKeywords(input: ValidInput): Boolean! - validArgs( - break: String!, - default: String!, - func: String!, - interface: String!, - select: String!, - case: String!, - defer: String!, - go: String!, - map: String!, - struct: String!, - chan: String!, - else: String!, - goto: String!, - package: String!, - switch: String!, - const: String!, - fallthrough: String!, - if: String!, - range: String!, - type: String!, - continue: String!, - for: String!, - import: String!, - return: String!, - var: String!, - _: String!, - ): Boolean! -} - -input ValidInput { - break: String! - default: String! - func: String! - interface: String! - select: String! - case: String! - defer: String! - go: String! - map: String! - struct: String! - chan: String! - else: String! - goto: String! - package: String! - switch: String! - const: String! - fallthrough: String! - if: String! - range: String! - type: String! - continue: String! - for: String! - import: String! - return: String! - var: String! - _: String! @goField(name: "Underscore") -} - -# see https://github.com/99designs/gqlgen/issues/694 -type Content_User { - foo: String -} - -type Content_Post { - foo: String -} - -union Content_Child = Content_User | Content_Post -`, BuiltIn: false}, - {Name: "variadic.graphql", Input: `extend type Query { - variadicModel: VariadicModel -} - -type VariadicModel { - value(rank: Int!): String -} -`, BuiltIn: false}, - {Name: "weird_type_cases.graphql", Input: `# regression test for https://github.com/99designs/gqlgen/issues/583 - -type asdfIt { id: ID! } -type iIt { id: ID! } -type AIt { id: ID! } -type XXIt { id: ID! } -type AbIt { id: ID! } -type XxIt { id: ID! } -`, BuiltIn: false}, - {Name: "wrapped_type.graphql", Input: `# regression test for https://github.com/99designs/gqlgen/issues/721 - -extend type Query { - wrappedStruct: WrappedStruct! - wrappedScalar: WrappedScalar! - wrappedMap: WrappedMap! - wrappedSlice: WrappedSlice! +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) } -type WrappedStruct { name: WrappedScalar!, desc: WrappedScalar } -scalar WrappedScalar -type WrappedMap { get(key: String!): String! } -type WrappedSlice { get(idx: Int!): String! } -`, BuiltIn: false}, +var sources = []*ast.Source{ + {Name: "builtinscalar.graphql", Input: sourceData("builtinscalar.graphql"), BuiltIn: false}, + {Name: "complexity.graphql", Input: sourceData("complexity.graphql"), BuiltIn: false}, + {Name: "defaults.graphql", Input: sourceData("defaults.graphql"), BuiltIn: false}, + {Name: "directive.graphql", Input: sourceData("directive.graphql"), BuiltIn: false}, + {Name: "embedded.graphql", Input: sourceData("embedded.graphql"), BuiltIn: false}, + {Name: "enum.graphql", Input: sourceData("enum.graphql"), BuiltIn: false}, + {Name: "interfaces.graphql", Input: sourceData("interfaces.graphql"), BuiltIn: false}, + {Name: "issue896.graphql", Input: sourceData("issue896.graphql"), BuiltIn: false}, + {Name: "loops.graphql", Input: sourceData("loops.graphql"), BuiltIn: false}, + {Name: "maps.graphql", Input: sourceData("maps.graphql"), BuiltIn: false}, + {Name: "mutation_with_custom_scalar.graphql", Input: sourceData("mutation_with_custom_scalar.graphql"), BuiltIn: false}, + {Name: "nulls.graphql", Input: sourceData("nulls.graphql"), BuiltIn: false}, + {Name: "panics.graphql", Input: sourceData("panics.graphql"), BuiltIn: false}, + {Name: "primitive_objects.graphql", Input: sourceData("primitive_objects.graphql"), BuiltIn: false}, + {Name: "ptr_to_ptr_input.graphql", Input: sourceData("ptr_to_ptr_input.graphql"), BuiltIn: false}, + {Name: "ptr_to_slice.graphql", Input: sourceData("ptr_to_slice.graphql"), BuiltIn: false}, + {Name: "scalar_context.graphql", Input: sourceData("scalar_context.graphql"), BuiltIn: false}, + {Name: "scalar_default.graphql", Input: sourceData("scalar_default.graphql"), BuiltIn: false}, + {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, + {Name: "slices.graphql", Input: sourceData("slices.graphql"), BuiltIn: false}, + {Name: "typefallback.graphql", Input: sourceData("typefallback.graphql"), BuiltIn: false}, + {Name: "useptr.graphql", Input: sourceData("useptr.graphql"), BuiltIn: false}, + {Name: "v-ok.graphql", Input: sourceData("v-ok.graphql"), BuiltIn: false}, + {Name: "validtypes.graphql", Input: sourceData("validtypes.graphql"), BuiltIn: false}, + {Name: "variadic.graphql", Input: sourceData("variadic.graphql"), BuiltIn: false}, + {Name: "weird_type_cases.graphql", Input: sourceData("weird_type_cases.graphql"), BuiltIn: false}, + {Name: "wrapped_type.graphql", Input: sourceData("wrapped_type.graphql"), BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/codegen/testserver/singlefile/generated.go b/codegen/testserver/singlefile/generated.go index a573d7e097f..469384111b9 100644 --- a/codegen/testserver/singlefile/generated.go +++ b/codegen/testserver/singlefile/generated.go @@ -5,6 +5,7 @@ package singlefile import ( "bytes" "context" + "embed" "errors" "fmt" "io" @@ -2149,649 +2150,45 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var sources = []*ast.Source{ - {Name: "builtinscalar.graphql", Input: ` -""" -Since gqlgen defines default implementation for a Map scalar, this tests that the builtin is _not_ -added to the TypeMap -""" -type Map { - id: ID! -} -`, BuiltIn: false}, - {Name: "complexity.graphql", Input: `extend type Query { - overlapping: OverlappingFields -} - -type OverlappingFields { - oneFoo: Int! @goField(name: "foo") - twoFoo: Int! @goField(name: "foo") - oldFoo: Int! @goField(name: "foo", forceResolver: true) - newFoo: Int! - new_foo: Int! -} -`, BuiltIn: false}, - {Name: "defaults.graphql", Input: `extend type Query { - defaultParameters( - falsyBoolean: Boolean = false - truthyBoolean: Boolean = true - ): DefaultParametersMirror! -} - -extend type Mutation { - defaultInput(input: DefaultInput!): DefaultParametersMirror! -} - -input DefaultInput { - falsyBoolean: Boolean = false - truthyBoolean: Boolean = true -} - -type DefaultParametersMirror { - falsyBoolean: Boolean - truthyBoolean: Boolean -} -`, BuiltIn: false}, - {Name: "directive.graphql", Input: `directive @length(min: Int!, max: Int, message: String) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | FIELD_DEFINITION -directive @range(min: Int = 0, max: Int) on ARGUMENT_DEFINITION -directive @custom on ARGUMENT_DEFINITION -directive @logged(id: UUID!) on FIELD -directive @toNull on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | FIELD_DEFINITION -directive @directive1 on FIELD_DEFINITION -directive @directive2 on FIELD_DEFINITION -directive @directive3 on INPUT_OBJECT -directive @unimplemented on FIELD_DEFINITION -directive @order1(location: String!) repeatable on FIELD_DEFINITION | OBJECT -directive @order2(location: String!) on OBJECT - -extend type Query { - directiveArg(arg: String! @length(min:1, max: 255, message: "invalid length")): String - directiveNullableArg(arg: Int @range(min:0), arg2: Int @range, arg3: String @toNull): String - directiveInputNullable(arg: InputDirectives): String - directiveInput(arg: InputDirectives!): String - directiveInputType(arg: InnerInput! @custom): String - directiveObject: ObjectDirectives @order1(location: "Query_field") - directiveObjectWithCustomGoModel: ObjectDirectivesWithCustomGoModel - directiveFieldDef(ret: String!): String! @length(min: 1, message: "not valid") - directiveField: String - directiveDouble: String @directive1 @directive2 - directiveUnimplemented: String @unimplemented -} - -extend type Subscription { - directiveArg(arg: String! @length(min:1, max: 255, message: "invalid length")): String - directiveNullableArg(arg: Int @range(min:0), arg2: Int @range, arg3: String @toNull): String - directiveDouble: String @directive1 @directive2 - directiveUnimplemented: String @unimplemented -} - -input InputDirectives @directive3 { - text: String! @length(min: 0, max: 7, message: "not valid") - nullableText: String @toNull - inner: InnerDirectives! - innerNullable: InnerDirectives - thirdParty: ThirdParty @length(min: 0, max: 7) -} - -input InnerDirectives { - message: String! @length(min: 1, message: "not valid") -} - -type ObjectDirectives @order1(location: "order1_1") @order1(location: "order1_2") @order2(location: "order2_1") { - text: String! @length(min: 0, max: 7, message: "not valid") - nullableText: String @toNull - order: [String!]! -} - -type ObjectDirectivesWithCustomGoModel { - nullableText: String @toNull -} -`, BuiltIn: false}, - {Name: "embedded.graphql", Input: `extend type Query { - embeddedCase1: EmbeddedCase1 - embeddedCase2: EmbeddedCase2 - embeddedCase3: EmbeddedCase3 -} - -type EmbeddedCase1 @goModel(model:"singlefile.EmbeddedCase1") { - exportedEmbeddedPointerExportedMethod: String! -} - -type EmbeddedCase2 @goModel(model:"singlefile.EmbeddedCase2") { - unexportedEmbeddedPointerExportedMethod: String! -} - -type EmbeddedCase3 @goModel(model:"singlefile.EmbeddedCase3") { - unexportedEmbeddedInterfaceExportedMethod: String! -} -`, BuiltIn: false}, - {Name: "enum.graphql", Input: `enum EnumTest { - OK - NG -} - -input InputWithEnumValue { - enum: EnumTest! -} - -extend type Query { - enumInInput(input: InputWithEnumValue): EnumTest! -} -`, BuiltIn: false}, - {Name: "interfaces.graphql", Input: `extend type Query { - shapes: [Shape] - noShape: Shape @makeNil - node: Node! - noShapeTypedNil: Shape @makeTypedNil - animal: Animal @makeTypedNil - notAnInterface: BackedByInterface -} - -interface Animal { - species: String! -} - -type BackedByInterface { - id: String! - thisShouldBind: String! - thisShouldBindWithError: String! -} - -type Dog implements Animal { - species: String! - dogBreed: String! -} - -type Cat implements Animal { - species: String! - catBreed: String! -} - -type Coordinates { - x: Float! - y: Float! -} -interface Shape { - area: Float - coordinates: Coordinates -} - -type Circle implements Shape { - radius: Float - area: Float - coordinates: Coordinates -} -type Rectangle implements Shape { - length: Float - width: Float - area: Float - coordinates: Coordinates -} -union ShapeUnion @goModel(model: "singlefile.ShapeUnion") = Circle | Rectangle - -directive @makeNil on FIELD_DEFINITION -directive @makeTypedNil on FIELD_DEFINITION - -interface Node { - id: ID! - child: Node! -} - -type ConcreteNodeA implements Node { - id: ID! - child: Node! - name: String! -} - -" Implements the Node interface with another interface " -type ConcreteNodeInterface implements Node { - id: ID! - child: Node! -} -`, BuiltIn: false}, - {Name: "issue896.graphql", Input: `# This example should build stable output. If the file content starts -# alternating nondeterministically between two outputs, then see -# https://github.com/99designs/gqlgen/issues/896. - -extend schema { - query: Query - subscription: Subscription -} - -type CheckIssue896 {id: Int} - -extend type Query { - issue896a: [CheckIssue896!] # Note the "!" or lack thereof. -} - -extend type Subscription { - issue896b: [CheckIssue896] # Note the "!" or lack thereof. -} -`, BuiltIn: false}, - {Name: "loops.graphql", Input: `type LoopA { - b: LoopB! -} - -type LoopB { - a: LoopA! -} -`, BuiltIn: false}, - {Name: "maps.graphql", Input: `extend type Query { - mapStringInterface(in: MapStringInterfaceInput): MapStringInterfaceType - mapNestedStringInterface(in: NestedMapInput): MapStringInterfaceType -} - -type MapStringInterfaceType @goModel(model: "map[string]interface{}") { - a: String - b: Int -} - -input MapStringInterfaceInput @goModel(model: "map[string]interface{}") { - a: String - b: Int -} - -input NestedMapInput { - map: MapStringInterfaceInput -} -`, BuiltIn: false}, - {Name: "mutation_with_custom_scalar.graphql", Input: `extend type Mutation { - updateSomething(input: SpecialInput!): String! -} - -scalar Email - -input SpecialInput { - nesting: NestedInput! -} - -input NestedInput { - field: Email! -} -`, BuiltIn: false}, - {Name: "nulls.graphql", Input: `extend type Query { - errorBubble: Error - errorBubbleList: [Error!] - errorList: [Error] - errors: Errors - valid: String! -} - -extend type Subscription { - errorRequired: Error! -} - -type Errors { - a: Error! - b: Error! - c: Error! - d: Error! - e: Error! -} - -type Error { - id: ID! - errorOnNonRequiredField: String - errorOnRequiredField: String! - nilOnRequiredField: String! -} -`, BuiltIn: false}, - {Name: "panics.graphql", Input: `extend type Query { - panics: Panics -} - -type Panics { - fieldScalarMarshal: [MarshalPanic!]! - fieldFuncMarshal(u: [MarshalPanic!]!): [MarshalPanic!]! - argUnmarshal(u: [MarshalPanic!]!): Boolean! - -} - -scalar MarshalPanic -`, BuiltIn: false}, - {Name: "primitive_objects.graphql", Input: `extend type Query { - primitiveObject: [Primitive!]! - primitiveStringObject: [PrimitiveString!]! -} - -type Primitive { - value: Int! - squared: Int! -} - -type PrimitiveString { - value: String! - doubled: String! - len: Int! -} -`, BuiltIn: false}, - {Name: "ptr_to_ptr_input.graphql", Input: `type PtrToPtrOuter { - name: String! - inner: PtrToPtrInner - stupidInner: PtrToPtrInner -} - -type PtrToPtrInner { - key: String! - value: String! -} - -input UpdatePtrToPtrOuter { - name: String - inner: UpdatePtrToPtrInner - stupidInner: UpdatePtrToPtrInner -} - -input UpdatePtrToPtrInner { - key: String - value: String -} - -extend type Mutation { - updatePtrToPtr(input: UpdatePtrToPtrOuter!): PtrToPtrOuter! -} -`, BuiltIn: false}, - {Name: "ptr_to_slice.graphql", Input: `type PtrToSliceContainer { - ptrToSlice: [String!] -} - -extend type Query { - ptrToSliceContainer: PtrToSliceContainer! -} -`, BuiltIn: false}, - {Name: "scalar_context.graphql", Input: `extend type Query { - infinity: Float! - stringFromContextInterface: StringFromContextInterface! - stringFromContextFunction: StringFromContextFunction! -} - -scalar StringFromContextInterface -scalar StringFromContextFunction -`, BuiltIn: false}, - {Name: "scalar_default.graphql", Input: `extend type Query { - defaultScalar(arg: DefaultScalarImplementation! = "default"): DefaultScalarImplementation! -} - -""" This doesnt have an implementation in the typemap, so it should act like a string """ -scalar DefaultScalarImplementation - -type EmbeddedDefaultScalar { - value: DefaultScalarImplementation -} -`, BuiltIn: false}, - {Name: "schema.graphql", Input: `directive @goModel( - model: String - models: [String!] -) on OBJECT | INPUT_OBJECT | SCALAR | ENUM | INTERFACE | UNION -directive @goField( - forceResolver: Boolean - name: String -) on INPUT_FIELD_DEFINITION | FIELD_DEFINITION - -type Query { - invalidIdentifier: InvalidIdentifier - collision: It - mapInput(input: Changes): Boolean - recursive(input: RecursiveInputSlice): Boolean - nestedInputs(input: [[OuterInput]] = [[{ inner: { id: 1 } }]]): Boolean - nestedOutputs: [[OuterObject]] - modelMethods: ModelMethods - user(id: Int!): User! - nullableArg(arg: Int = 123): String - inputSlice(arg: [String!]!): Boolean! - inputNullableSlice(arg: [String!]): Boolean! - shapeUnion: ShapeUnion! - autobind: Autobind - deprecatedField: String! @deprecated(reason: "test deprecated directive") -} - -type Subscription { - updated: String! - initPayload: String! -} - -type Pet { - id: Int! - friends(limit: Int): [Pet!] @goField(forceResolver: true) -} - -type User { - id: Int! - friends: [User!]! @goField(forceResolver: true) - created: Time! - updated: Time - pets(limit: Int): [Pet!] @goField(forceResolver: true) -} - -type Autobind { - int: Int! - int32: Int! - int64: Int! - - idStr: ID! - idInt: ID! -} - -type ModelMethods { - resolverField: Boolean! - noContext: Boolean! - withContext: Boolean! -} - -type InvalidIdentifier { - id: Int! -} +//go:embed "builtinscalar.graphql" "complexity.graphql" "defaults.graphql" "directive.graphql" "embedded.graphql" "enum.graphql" "interfaces.graphql" "issue896.graphql" "loops.graphql" "maps.graphql" "mutation_with_custom_scalar.graphql" "nulls.graphql" "panics.graphql" "primitive_objects.graphql" "ptr_to_ptr_input.graphql" "ptr_to_slice.graphql" "scalar_context.graphql" "scalar_default.graphql" "schema.graphql" "slices.graphql" "typefallback.graphql" "useptr.graphql" "v-ok.graphql" "validtypes.graphql" "variadic.graphql" "weird_type_cases.graphql" "wrapped_type.graphql" +var sourcesFS embed.FS -type It { - id: ID! -} - -input Changes @goModel(model: "map[string]interface{}") { - a: Int - b: Int -} - -input RecursiveInputSlice { - self: [RecursiveInputSlice!] -} - -input InnerInput { - id: Int! -} - -input OuterInput { - inner: InnerInput! -} - -scalar ThirdParty @goModel(model:"singlefile.ThirdParty") - -type OuterObject { - inner: InnerObject! -} - -type InnerObject { - id: Int! -} - -type ForcedResolver { - field: Circle @goField(forceResolver: true) -} - -type EmbeddedPointer @goModel(model:"singlefile.EmbeddedPointerModel") { - ID: String - Title: String -} - -scalar UUID - -enum Status { - OK - ERROR -} - -scalar Time -`, BuiltIn: false}, - {Name: "slices.graphql", Input: `extend type Query { - slices: Slices - scalarSlice: Bytes! -} - -type Slices { - test1: [String] - test2: [String!] - test3: [String]! - test4: [String!]! -} - -scalar Bytes -`, BuiltIn: false}, - {Name: "typefallback.graphql", Input: `extend type Query { - fallback(arg: FallbackToStringEncoding!): FallbackToStringEncoding! -} - -enum FallbackToStringEncoding { - A - B - C -} -`, BuiltIn: false}, - {Name: "useptr.graphql", Input: `type A { - id: ID! -} - -type B { - id: ID! -} - -union TestUnion = A | B - -extend type Query { - optionalUnion: TestUnion -} -`, BuiltIn: false}, - {Name: "v-ok.graphql", Input: `extend type Query { - vOkCaseValue: VOkCaseValue - vOkCaseNil: VOkCaseNil -} - -type VOkCaseValue @goModel(model:"singlefile.VOkCaseValue") { - value: String -} - -type VOkCaseNil @goModel(model:"singlefile.VOkCaseNil") { - value: String -} -`, BuiltIn: false}, - {Name: "validtypes.graphql", Input: `extend type Query { - validType: ValidType +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) } -""" These things are all valid, but without care generate invalid go code """ -type ValidType { - differentCase: String! - different_case: String! @goField(name:"DifferentCaseOld") - validInputKeywords(input: ValidInput): Boolean! - validArgs( - break: String!, - default: String!, - func: String!, - interface: String!, - select: String!, - case: String!, - defer: String!, - go: String!, - map: String!, - struct: String!, - chan: String!, - else: String!, - goto: String!, - package: String!, - switch: String!, - const: String!, - fallthrough: String!, - if: String!, - range: String!, - type: String!, - continue: String!, - for: String!, - import: String!, - return: String!, - var: String!, - _: String!, - ): Boolean! -} - -input ValidInput { - break: String! - default: String! - func: String! - interface: String! - select: String! - case: String! - defer: String! - go: String! - map: String! - struct: String! - chan: String! - else: String! - goto: String! - package: String! - switch: String! - const: String! - fallthrough: String! - if: String! - range: String! - type: String! - continue: String! - for: String! - import: String! - return: String! - var: String! - _: String! @goField(name: "Underscore") -} - -# see https://github.com/99designs/gqlgen/issues/694 -type Content_User { - foo: String -} - -type Content_Post { - foo: String -} - -union Content_Child = Content_User | Content_Post -`, BuiltIn: false}, - {Name: "variadic.graphql", Input: `extend type Query { - variadicModel: VariadicModel -} - -type VariadicModel { - value(rank: Int!): String -} -`, BuiltIn: false}, - {Name: "weird_type_cases.graphql", Input: `# regression test for https://github.com/99designs/gqlgen/issues/583 - -type asdfIt { id: ID! } -type iIt { id: ID! } -type AIt { id: ID! } -type XXIt { id: ID! } -type AbIt { id: ID! } -type XxIt { id: ID! } -`, BuiltIn: false}, - {Name: "wrapped_type.graphql", Input: `# regression test for https://github.com/99designs/gqlgen/issues/721 - -extend type Query { - wrappedStruct: WrappedStruct! - wrappedScalar: WrappedScalar! - wrappedMap: WrappedMap! - wrappedSlice: WrappedSlice! -} - -type WrappedStruct { name: WrappedScalar!, desc: WrappedScalar } -scalar WrappedScalar -type WrappedMap { get(key: String!): String! } -type WrappedSlice { get(idx: Int!): String! } -`, BuiltIn: false}, +var sources = []*ast.Source{ + {Name: "builtinscalar.graphql", Input: sourceData("builtinscalar.graphql"), BuiltIn: false}, + {Name: "complexity.graphql", Input: sourceData("complexity.graphql"), BuiltIn: false}, + {Name: "defaults.graphql", Input: sourceData("defaults.graphql"), BuiltIn: false}, + {Name: "directive.graphql", Input: sourceData("directive.graphql"), BuiltIn: false}, + {Name: "embedded.graphql", Input: sourceData("embedded.graphql"), BuiltIn: false}, + {Name: "enum.graphql", Input: sourceData("enum.graphql"), BuiltIn: false}, + {Name: "interfaces.graphql", Input: sourceData("interfaces.graphql"), BuiltIn: false}, + {Name: "issue896.graphql", Input: sourceData("issue896.graphql"), BuiltIn: false}, + {Name: "loops.graphql", Input: sourceData("loops.graphql"), BuiltIn: false}, + {Name: "maps.graphql", Input: sourceData("maps.graphql"), BuiltIn: false}, + {Name: "mutation_with_custom_scalar.graphql", Input: sourceData("mutation_with_custom_scalar.graphql"), BuiltIn: false}, + {Name: "nulls.graphql", Input: sourceData("nulls.graphql"), BuiltIn: false}, + {Name: "panics.graphql", Input: sourceData("panics.graphql"), BuiltIn: false}, + {Name: "primitive_objects.graphql", Input: sourceData("primitive_objects.graphql"), BuiltIn: false}, + {Name: "ptr_to_ptr_input.graphql", Input: sourceData("ptr_to_ptr_input.graphql"), BuiltIn: false}, + {Name: "ptr_to_slice.graphql", Input: sourceData("ptr_to_slice.graphql"), BuiltIn: false}, + {Name: "scalar_context.graphql", Input: sourceData("scalar_context.graphql"), BuiltIn: false}, + {Name: "scalar_default.graphql", Input: sourceData("scalar_default.graphql"), BuiltIn: false}, + {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, + {Name: "slices.graphql", Input: sourceData("slices.graphql"), BuiltIn: false}, + {Name: "typefallback.graphql", Input: sourceData("typefallback.graphql"), BuiltIn: false}, + {Name: "useptr.graphql", Input: sourceData("useptr.graphql"), BuiltIn: false}, + {Name: "v-ok.graphql", Input: sourceData("v-ok.graphql"), BuiltIn: false}, + {Name: "validtypes.graphql", Input: sourceData("validtypes.graphql"), BuiltIn: false}, + {Name: "variadic.graphql", Input: sourceData("variadic.graphql"), BuiltIn: false}, + {Name: "weird_type_cases.graphql", Input: sourceData("weird_type_cases.graphql"), BuiltIn: false}, + {Name: "wrapped_type.graphql", Input: sourceData("wrapped_type.graphql"), BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) From 84200764ddfa80b7bbe56dd2dc75f9e2e1d29e71 Mon Sep 17 00:00:00 2001 From: Viktor Stanchev Date: Sun, 24 Apr 2022 17:56:29 +0000 Subject: [PATCH 2/8] don't use embed for builtins --- codegen/generated!.gotpl | 4 ++-- codegen/root_.gotpl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/codegen/generated!.gotpl b/codegen/generated!.gotpl index 1c509b4d03b..be15a800640 100644 --- a/codegen/generated!.gotpl +++ b/codegen/generated!.gotpl @@ -236,7 +236,7 @@ return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } - //go:embed{{- range $source := .Config.Sources }} {{$source.Name|quote}}{{- end }} + //go:embed{{- range $source := .Config.Sources }}{{if (not $source.BuiltIn)}} {{$source.Name|quote}}{{end}}{{- end }} var sourcesFS embed.FS func sourceData(filename string) string { @@ -249,7 +249,7 @@ var sources = []*ast.Source{ {{- range $source := .Config.Sources }} - {Name: {{$source.Name|quote}}, Input: sourceData({{$source.Name|quote}}), BuiltIn: {{$source.BuiltIn}}}, + {Name: {{$source.Name|quote}}, Input: {{if $source.BuiltIn}}{{$source.Input|rawQuote}}{{else}}sourceData({{$source.Name|quote}}){{end}}, BuiltIn: {{$source.BuiltIn}}}, {{- end }} } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/codegen/root_.gotpl b/codegen/root_.gotpl index b34f174617e..89d647f7453 100644 --- a/codegen/root_.gotpl +++ b/codegen/root_.gotpl @@ -204,7 +204,7 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er } -//go:embed{{- range $source := .Config.Sources }} {{$source.Name|quote}}{{- end }} +//go:embed{{- range $source := .Config.Sources }}{{if (not $source.BuiltIn)}} {{$source.Name|quote}}{{end}}{{- end }} var sourcesFS embed.FS func sourceData(filename string) string { @@ -217,7 +217,7 @@ func sourceData(filename string) string { var sources = []*ast.Source{ {{- range $source := .Config.Sources }} - {Name: {{$source.Name|quote}}, Input: sourceData({{$source.Name|quote}}), BuiltIn: {{$source.BuiltIn}}}, + {Name: {{$source.Name|quote}}, Input: {{if $source.BuiltIn}}{{$source.Input|rawQuote}}{{else}}sourceData({{$source.Name|quote}}){{end}}, BuiltIn: {{$source.BuiltIn}}}, {{- end }} } var parsedSchema = gqlparser.MustLoadSchema(sources...) From 2e131210a3c3965c0a966882265dc17b32fc0a18 Mon Sep 17 00:00:00 2001 From: Viktor Stanchev Date: Mon, 25 Apr 2022 01:33:21 +0000 Subject: [PATCH 3/8] working poc --- _examples/chat/generated.go | 37 +- _examples/config/generated.go | 47 +- _examples/dataloader/generated.go | 42 +- .../accounts/graph/generated/generated.go | 28 +- .../products/graph/generated/generated.go | 28 +- .../reviews/graph/generated/generated.go | 28 +- _examples/fileupload/generated.go | 40 +- _examples/scalars/generated.go | 51 +- _examples/selection/generated.go | 34 +- _examples/starwars/generated/exec.go | 14 +- _examples/todo/generated.go | 50 +- _examples/type-system-extension/generated.go | 92 +-- codegen/data.go | 40 ++ codegen/generated!.gotpl | 6 +- codegen/root_.gotpl | 6 +- codegen/testserver/singlefile/generated.go | 671 +++++++++++++++++- integration/generated.go | 16 +- .../testdata/entityresolver/generated/exec.go | 18 +- 18 files changed, 907 insertions(+), 341 deletions(-) diff --git a/_examples/chat/generated.go b/_examples/chat/generated.go index 0afa8a8de87..5c20ffe54af 100644 --- a/_examples/chat/generated.go +++ b/_examples/chat/generated.go @@ -5,6 +5,7 @@ package chat import ( "bytes" "context" + "embed" "errors" "fmt" "io" @@ -259,35 +260,19 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var sources = []*ast.Source{ - {Name: "schema.graphql", Input: `type Chatroom { - name: String! - messages: [Message!]! -} - -type Message { - id: ID! - text: String! - createdBy: String! - createdAt: Time! -} - -type Query { - room(name:String!): Chatroom -} +//go:embed "schema.graphql" +var sourcesFS embed.FS -type Mutation { - post(text: String!, username: String!, roomName: String!): Message! -} - -type Subscription { - messageAdded(roomName: String!): Message! +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) } -scalar Time - -directive @user(username: String!) on SUBSCRIPTION -`, BuiltIn: false}, +var sources = []*ast.Source{ + {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/_examples/config/generated.go b/_examples/config/generated.go index 4ebbe67c18f..95ccb91b5d3 100644 --- a/_examples/config/generated.go +++ b/_examples/config/generated.go @@ -5,6 +5,7 @@ package config import ( "bytes" "context" + "embed" "errors" "fmt" "strconv" @@ -250,43 +251,21 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var sources = []*ast.Source{ - {Name: "schema.graphql", Input: `directive @goModel(model: String, models: [String!]) on OBJECT | INPUT_OBJECT | SCALAR | ENUM | INTERFACE | UNION -directive @goField(forceResolver: Boolean, name: String) on INPUT_FIELD_DEFINITION | FIELD_DEFINITION - -type Query { - todos: [Todo!]! -} - -type Mutation { - createTodo(input: NewTodo!): Todo! -} -`, BuiltIn: false}, - {Name: "todo.graphql", Input: `type Todo { - id: ID! @goField(forceResolver: true) - databaseId: Int! - text: String! - done: Boolean! - user: User! -} +//go:embed "schema.graphql" "todo.graphql" "user.graphql" +var sourcesFS embed.FS -input NewTodo { - text: String! - userId: String! -} -`, BuiltIn: false}, - {Name: "user.graphql", Input: `type User -@goModel(model:"github.com/99designs/gqlgen/_examples/config.User") { - id: ID! - name: String! @goField(name:"FullName") - role: role! +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) } -type role -@goModel(model:"github.com/99designs/gqlgen/_examples/config.UserRole") { - name: String! -} -`, BuiltIn: false}, +var sources = []*ast.Source{ + {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, + {Name: "todo.graphql", Input: sourceData("todo.graphql"), BuiltIn: false}, + {Name: "user.graphql", Input: sourceData("user.graphql"), BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/_examples/dataloader/generated.go b/_examples/dataloader/generated.go index 837e7b7bec1..92fa3f49603 100644 --- a/_examples/dataloader/generated.go +++ b/_examples/dataloader/generated.go @@ -5,6 +5,7 @@ package dataloader import ( "bytes" "context" + "embed" "errors" "fmt" "strconv" @@ -270,40 +271,19 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var sources = []*ast.Source{ - {Name: "schema.graphql", Input: `type Query { - customers: [Customer!] - - # these methods are here to test code generation of nested arrays - torture1d(customerIds: [Int!]): [Customer!] - torture2d(customerIds: [[Int!]]): [[Customer!]] -} +//go:embed "schema.graphql" +var sourcesFS embed.FS -type Customer { - id: Int! - name: String! - address: Address - orders: [Order!] -} - -type Address { - id: Int! - street: String! - country: String! -} - -type Order { - id: Int! - date: Time! - amount: Float! - items: [Item!] +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) } -type Item { - name: String! -} -scalar Time -`, BuiltIn: false}, +var sources = []*ast.Source{ + {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/_examples/federation/accounts/graph/generated/generated.go b/_examples/federation/accounts/graph/generated/generated.go index f10ab3e9326..fdd92ef9436 100644 --- a/_examples/federation/accounts/graph/generated/generated.go +++ b/_examples/federation/accounts/graph/generated/generated.go @@ -5,6 +5,7 @@ package generated import ( "bytes" "context" + "embed" "errors" "fmt" "strconv" @@ -246,8 +247,19 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } +//go:embed +var sourcesFS embed.FS + +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) +} + var sources = []*ast.Source{ - {Name: "graph/schema.graphqls", Input: `extend type Query { + {Name: "../schema.graphqls", Input: `extend type Query { me: User } @@ -263,6 +275,7 @@ type User @key(fields: "id") { username: String! } `, BuiltIn: false}, +<<<<<<< HEAD {Name: "federation/directives.graphql", Input: ` scalar _Any scalar _FieldSet @@ -273,8 +286,19 @@ type User @key(fields: "id") { directive @extends on OBJECT | INTERFACE directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE +======= + {Name: "../../federation/directives.graphql", Input: ` +scalar _Any +scalar _FieldSet + +directive @external on FIELD_DEFINITION +directive @requires(fields: _FieldSet!) on FIELD_DEFINITION +directive @provides(fields: _FieldSet!) on FIELD_DEFINITION +directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE +directive @extends on OBJECT | INTERFACE +>>>>>>> c657a54f (working poc) `, BuiltIn: true}, - {Name: "federation/entity.graphql", Input: ` + {Name: "../../federation/entity.graphql", Input: ` # a union of all types that use the @key directive union _Entity = EmailHost | User diff --git a/_examples/federation/products/graph/generated/generated.go b/_examples/federation/products/graph/generated/generated.go index 4367a960637..9122d31685f 100644 --- a/_examples/federation/products/graph/generated/generated.go +++ b/_examples/federation/products/graph/generated/generated.go @@ -5,6 +5,7 @@ package generated import ( "bytes" "context" + "embed" "errors" "fmt" "strconv" @@ -273,8 +274,19 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } +//go:embed +var sourcesFS embed.FS + +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) +} + var sources = []*ast.Source{ - {Name: "graph/schema.graphqls", Input: `extend type Query { + {Name: "../schema.graphqls", Input: `extend type Query { topProducts(first: Int = 5): [Product] } @@ -291,6 +303,7 @@ type Product @key(fields: "manufacturer { id } id") @key(fields: "upc") { price: Int! } `, BuiltIn: false}, +<<<<<<< HEAD {Name: "federation/directives.graphql", Input: ` scalar _Any scalar _FieldSet @@ -301,8 +314,19 @@ type Product @key(fields: "manufacturer { id } id") @key(fields: "upc") { directive @extends on OBJECT | INTERFACE directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE +======= + {Name: "../../federation/directives.graphql", Input: ` +scalar _Any +scalar _FieldSet + +directive @external on FIELD_DEFINITION +directive @requires(fields: _FieldSet!) on FIELD_DEFINITION +directive @provides(fields: _FieldSet!) on FIELD_DEFINITION +directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE +directive @extends on OBJECT | INTERFACE +>>>>>>> c657a54f (working poc) `, BuiltIn: true}, - {Name: "federation/entity.graphql", Input: ` + {Name: "../../federation/entity.graphql", Input: ` # a union of all types that use the @key directive union _Entity = Manufacturer | Product diff --git a/_examples/federation/reviews/graph/generated/generated.go b/_examples/federation/reviews/graph/generated/generated.go index afa89ec9726..12cc95f7d01 100644 --- a/_examples/federation/reviews/graph/generated/generated.go +++ b/_examples/federation/reviews/graph/generated/generated.go @@ -5,6 +5,7 @@ package generated import ( "bytes" "context" + "embed" "errors" "fmt" "strconv" @@ -295,8 +296,19 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } +//go:embed +var sourcesFS embed.FS + +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) +} + var sources = []*ast.Source{ - {Name: "graph/schema.graphqls", Input: `type Review { + {Name: "../schema.graphqls", Input: `type Review { body: String! author: User! @provides(fields: "username") product: Product! @@ -323,6 +335,7 @@ extend type Product @key(fields: " manufacturer{ id} id") { reviews: [Review] } `, BuiltIn: false}, +<<<<<<< HEAD {Name: "federation/directives.graphql", Input: ` scalar _Any scalar _FieldSet @@ -333,8 +346,19 @@ extend type Product @key(fields: " manufacturer{ id} id") { directive @extends on OBJECT | INTERFACE directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE +======= + {Name: "../../federation/directives.graphql", Input: ` +scalar _Any +scalar _FieldSet + +directive @external on FIELD_DEFINITION +directive @requires(fields: _FieldSet!) on FIELD_DEFINITION +directive @provides(fields: _FieldSet!) on FIELD_DEFINITION +directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE +directive @extends on OBJECT | INTERFACE +>>>>>>> c657a54f (working poc) `, BuiltIn: true}, - {Name: "federation/entity.graphql", Input: ` + {Name: "../../federation/entity.graphql", Input: ` # a union of all types that use the @key directive union _Entity = EmailHost | Manufacturer | Product | User diff --git a/_examples/fileupload/generated.go b/_examples/fileupload/generated.go index fa78f2bb49f..986aef9ea84 100644 --- a/_examples/fileupload/generated.go +++ b/_examples/fileupload/generated.go @@ -5,6 +5,7 @@ package fileupload import ( "bytes" "context" + "embed" "errors" "fmt" "strconv" @@ -239,38 +240,19 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var sources = []*ast.Source{ - {Name: "schema.graphql", Input: `"The ` + "`" + `Upload` + "`" + ` scalar type represents a multipart file upload." -scalar Upload - -"The ` + "`" + `File` + "`" + ` type, represents the response of uploading a file." -type File { - id: Int! - name: String! - content: String! - contentType: String! -} - -"The ` + "`" + `UploadFile` + "`" + ` type, represents the request for uploading a file with certain payload." -input UploadFile { - id: Int! - file: Upload! -} +//go:embed "schema.graphql" +var sourcesFS embed.FS -"The ` + "`" + `Query` + "`" + ` type, represents all of the entry points into our object graph." -type Query { - empty: String! -} - -"The ` + "`" + `Mutation` + "`" + ` type, represents all updates we can make to our data." -type Mutation { - singleUpload(file: Upload!): File! - singleUploadWithPayload(req: UploadFile!): File! - multipleUpload(files: [Upload!]!): [File!]! - multipleUploadWithPayload(req: [UploadFile!]!): [File!]! +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) } -`, BuiltIn: false}, +var sources = []*ast.Source{ + {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/_examples/scalars/generated.go b/_examples/scalars/generated.go index 1d96d5cdc01..e2b69dd4747 100644 --- a/_examples/scalars/generated.go +++ b/_examples/scalars/generated.go @@ -5,6 +5,7 @@ package scalars import ( "bytes" "context" + "embed" "errors" "fmt" "strconv" @@ -277,49 +278,19 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var sources = []*ast.Source{ - {Name: "schema.graphql", Input: `type Query { - user(id: ID!): User - search(input: SearchArgs = {location: "37,144", isBanned: false}): [User!]! - userByTier(tier: Tier!, darkMode: DarkMode!): [User!]! -} - -type User { - id: ID! - name: String! - created: Timestamp - modified: Timestamp - valPrefs: DarkMode - ptrPrefs: DarkMode - isBanned: Banned! - primitiveResolver: String! - customResolver: Point! - address: Address - tier: Tier -} - -type Address { - id: ID! - location: Point -} +//go:embed "schema.graphql" +var sourcesFS embed.FS -input SearchArgs { - location: Point - createdAfter: Timestamp - isBanned: Banned # TODO: This can be a Boolean again once multiple backing types are allowed -} - -enum Tier { - A - B - C +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) } -scalar Timestamp -scalar Point -scalar Banned -scalar DarkMode -`, BuiltIn: false}, +var sources = []*ast.Source{ + {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/_examples/selection/generated.go b/_examples/selection/generated.go index 0118a6ac5d3..ee3a0f2f824 100644 --- a/_examples/selection/generated.go +++ b/_examples/selection/generated.go @@ -5,6 +5,7 @@ package selection import ( "bytes" "context" + "embed" "errors" "fmt" "strconv" @@ -194,32 +195,19 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var sources = []*ast.Source{ - {Name: "schema.graphql", Input: `interface Event { - selection: [String!] - collected: [String!] -} +//go:embed "schema.graphql" +var sourcesFS embed.FS -type Post implements Event { - message: String! - sent: Time! - selection: [String!] - collected: [String!] -} - -type Like implements Event { - reaction: String! - sent: Time! - selection: [String!] - collected: [String!] -} - -type Query { - events: [Event!] +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) } -scalar Time -`, BuiltIn: false}, +var sources = []*ast.Source{ + {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/_examples/starwars/generated/exec.go b/_examples/starwars/generated/exec.go index 6b8e9eae426..7feccd993e9 100644 --- a/_examples/starwars/generated/exec.go +++ b/_examples/starwars/generated/exec.go @@ -5,6 +5,7 @@ package generated import ( "bytes" "context" + "embed" "errors" "fmt" "strconv" @@ -554,8 +555,19 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } +//go:embed +var sourcesFS embed.FS + +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) +} + var sources = []*ast.Source{ - {Name: "schema.graphql", Input: `# The query type, represents all of the entry points into our object graph + {Name: "../schema.graphql", Input: `# The query type, represents all of the entry points into our object graph type Query { hero(episode: Episode = NEWHOPE): Character reviews(episode: Episode!, since: Time): [Review!]! diff --git a/_examples/todo/generated.go b/_examples/todo/generated.go index 382641cba87..2fd43e5cc10 100644 --- a/_examples/todo/generated.go +++ b/_examples/todo/generated.go @@ -5,6 +5,7 @@ package todo import ( "bytes" "context" + "embed" "errors" "fmt" "strconv" @@ -231,48 +232,19 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var sources = []*ast.Source{ - {Name: "schema.graphql", Input: `schema { - query: MyQuery - mutation: MyMutation -} - -type MyQuery { - todo(id: ID!): Todo - lastTodo: Todo - todos: [Todo!]! -} - -type MyMutation { - createTodo(todo: TodoInput!): Todo! - updateTodo(id: ID!, changes: Map!): Todo -} - -type Todo { - id: ID! - text: String! - done: Boolean! @hasRole(role: OWNER) # only the owner can see if a todo is done -} +//go:embed "schema.graphql" +var sourcesFS embed.FS -"Passed to createTodo to create a new todo" -input TodoInput { - "The body text" - text: String! - "Is it done already?" - done: Boolean +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) } -scalar Map - -"Prevents access to a field if the user doesnt have the matching role" -directive @hasRole(role: Role!) on FIELD_DEFINITION -directive @user(id: ID!) on MUTATION | QUERY | FIELD - -enum Role { - ADMIN - OWNER -} -`, BuiltIn: false}, +var sources = []*ast.Source{ + {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/_examples/type-system-extension/generated.go b/_examples/type-system-extension/generated.go index e4e0ebf39f8..a4d50d2e185 100644 --- a/_examples/type-system-extension/generated.go +++ b/_examples/type-system-extension/generated.go @@ -5,6 +5,7 @@ package type_system_extension import ( "bytes" "context" + "embed" "errors" "fmt" "strconv" @@ -217,82 +218,27 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var sources = []*ast.Source{ - {Name: "schemas/enum-extension.graphql", Input: `directive @enumLogging on ENUM - -extend enum State @enumLogging -`, BuiltIn: false}, - {Name: "schemas/input-object-extension.graphql", Input: `directive @inputLogging on INPUT_OBJECT - -extend input TodoInput @inputLogging -`, BuiltIn: false}, - {Name: "schemas/interface-extension.graphql", Input: `directive @interfaceLogging on INTERFACE - -extend interface Node @interfaceLogging -`, BuiltIn: false}, - {Name: "schemas/object-extension.graphql", Input: `directive @objectLogging on OBJECT - -extend type Todo @objectLogging -`, BuiltIn: false}, - {Name: "schemas/scalar-extension.graphql", Input: `directive @scalarLogging on SCALAR - -extend scalar ID @scalarLogging -`, BuiltIn: false}, - {Name: "schemas/schema-extension.graphql", Input: `extend schema { - mutation: MyMutation -} +//go:embed "schemas/enum-extension.graphql" "schemas/input-object-extension.graphql" "schemas/interface-extension.graphql" "schemas/object-extension.graphql" "schemas/scalar-extension.graphql" "schemas/schema-extension.graphql" "schemas/schema.graphql" "schemas/type-extension.graphql" "schemas/union-extension.graphql" +var sourcesFS embed.FS -extend type MyQuery { - todo(id: ID!): Todo -} - -type MyMutation { - createTodo(todo: TodoInput!): Todo! -} - -input TodoInput { - text: String! -} -`, BuiltIn: false}, - {Name: "schemas/schema.graphql", Input: `# GraphQL schema example -# -# https://gqlgen.com/getting-started/ - -schema { - query: MyQuery -} - -interface Node { - id: ID! -} - -type Todo implements Node { - id: ID! - text: String! - state: State! -} - -type MyQuery { - todos: [Todo!]! -} - -union Data = Todo - -enum State { - NOT_YET - DONE -} -`, BuiltIn: false}, - {Name: "schemas/type-extension.graphql", Input: `directive @fieldLogging on FIELD_DEFINITION - -extend type Todo { - verified: Boolean! @fieldLogging +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) } -`, BuiltIn: false}, - {Name: "schemas/union-extension.graphql", Input: `directive @unionLogging on UNION -extend union Data @unionLogging -`, BuiltIn: false}, +var sources = []*ast.Source{ + {Name: "schemas/enum-extension.graphql", Input: sourceData("schemas/enum-extension.graphql"), BuiltIn: false}, + {Name: "schemas/input-object-extension.graphql", Input: sourceData("schemas/input-object-extension.graphql"), BuiltIn: false}, + {Name: "schemas/interface-extension.graphql", Input: sourceData("schemas/interface-extension.graphql"), BuiltIn: false}, + {Name: "schemas/object-extension.graphql", Input: sourceData("schemas/object-extension.graphql"), BuiltIn: false}, + {Name: "schemas/scalar-extension.graphql", Input: sourceData("schemas/scalar-extension.graphql"), BuiltIn: false}, + {Name: "schemas/schema-extension.graphql", Input: sourceData("schemas/schema-extension.graphql"), BuiltIn: false}, + {Name: "schemas/schema.graphql", Input: sourceData("schemas/schema.graphql"), BuiltIn: false}, + {Name: "schemas/type-extension.graphql", Input: sourceData("schemas/type-extension.graphql"), BuiltIn: false}, + {Name: "schemas/union-extension.graphql", Input: sourceData("schemas/union-extension.graphql"), BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/codegen/data.go b/codegen/data.go index e12fb104730..b757d21fcec 100644 --- a/codegen/data.go +++ b/codegen/data.go @@ -2,7 +2,10 @@ package codegen import ( "fmt" + "os" + "path/filepath" "sort" + "strings" "github.com/vektah/gqlparser/v2/ast" @@ -32,6 +35,43 @@ type Data struct { SubscriptionRoot *Object } +func (d *Data) AugmentedSources() []AugmentedSource { + sources := []AugmentedSource{} + for _, s := range d.Config.Sources { + + wd, err := os.Getwd() + if err != nil { + panic(err) + } + outputDir := filepath.Dir(d.Config.Exec.Filename) + outputDir = filepath.Join(wd, outputDir) + relative, err := filepath.Rel(outputDir, filepath.Join(wd, s.Name)) + if err != nil { + panic("TODO: handle" + err.Error() + " inputs:" + d.Config.Exec.Filename + " and " + filepath.Join(wd, s.Name)) + } + embeddable := true + if strings.HasPrefix(relative, "..") { + embeddable = false + } + sources = append(sources, AugmentedSource{ + RelativePath: relative, + Embeddable: embeddable, + BuiltIn: s.BuiltIn, + Source: s.Input, // TODO: remove this + }) + } + return sources +} + +// AugmentedSource contains extra information about graphql schema files which is not known directly from the Config.Sources data +type AugmentedSource struct { + // path relative to Config.Exec.Filename + RelativePath string + Embeddable bool + BuiltIn bool + Source string +} + type builder struct { Config *config.Config Schema *ast.Schema diff --git a/codegen/generated!.gotpl b/codegen/generated!.gotpl index be15a800640..bed873e842d 100644 --- a/codegen/generated!.gotpl +++ b/codegen/generated!.gotpl @@ -236,7 +236,7 @@ return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } - //go:embed{{- range $source := .Config.Sources }}{{if (not $source.BuiltIn)}} {{$source.Name|quote}}{{end}}{{- end }} + //go:embed{{- range $source := .AugmentedSources }}{{if $source.Embeddable}} {{$source.RelativePath|quote}}{{end}}{{- end }} var sourcesFS embed.FS func sourceData(filename string) string { @@ -248,8 +248,8 @@ } var sources = []*ast.Source{ - {{- range $source := .Config.Sources }} - {Name: {{$source.Name|quote}}, Input: {{if $source.BuiltIn}}{{$source.Input|rawQuote}}{{else}}sourceData({{$source.Name|quote}}){{end}}, BuiltIn: {{$source.BuiltIn}}}, + {{- range $source := .AugmentedSources }} + {Name: {{$source.RelativePath|quote}}, Input: {{if (not $source.Embeddable)}}{{$source.Source|rawQuote}}{{else}}sourceData({{$source.RelativePath|quote}}){{end}}, BuiltIn: {{$source.BuiltIn}}}, {{- end }} } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/codegen/root_.gotpl b/codegen/root_.gotpl index 89d647f7453..26603957692 100644 --- a/codegen/root_.gotpl +++ b/codegen/root_.gotpl @@ -204,7 +204,7 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er } -//go:embed{{- range $source := .Config.Sources }}{{if (not $source.BuiltIn)}} {{$source.Name|quote}}{{end}}{{- end }} +//go:embed{{- range $source := .AugmentedSources }}{{if $source.Embeddable}} {{$source.RelativePath|quote}}{{end}}{{- end }} var sourcesFS embed.FS func sourceData(filename string) string { @@ -216,8 +216,8 @@ func sourceData(filename string) string { } var sources = []*ast.Source{ -{{- range $source := .Config.Sources }} - {Name: {{$source.Name|quote}}, Input: {{if $source.BuiltIn}}{{$source.Input|rawQuote}}{{else}}sourceData({{$source.Name|quote}}){{end}}, BuiltIn: {{$source.BuiltIn}}}, +{{- range $source := .AugmentedSources }} + {Name: {{$source.RelativePath|quote}}, Input: {{if (not $source.Embeddable)}}{{$source.Source|rawQuote}}{{else}}sourceData({{$source.RelativePath|quote}}){{end}}, BuiltIn: {{$source.BuiltIn}}}, {{- end }} } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/codegen/testserver/singlefile/generated.go b/codegen/testserver/singlefile/generated.go index 469384111b9..0b6cac1c076 100644 --- a/codegen/testserver/singlefile/generated.go +++ b/codegen/testserver/singlefile/generated.go @@ -2150,7 +2150,7 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -//go:embed "builtinscalar.graphql" "complexity.graphql" "defaults.graphql" "directive.graphql" "embedded.graphql" "enum.graphql" "interfaces.graphql" "issue896.graphql" "loops.graphql" "maps.graphql" "mutation_with_custom_scalar.graphql" "nulls.graphql" "panics.graphql" "primitive_objects.graphql" "ptr_to_ptr_input.graphql" "ptr_to_slice.graphql" "scalar_context.graphql" "scalar_default.graphql" "schema.graphql" "slices.graphql" "typefallback.graphql" "useptr.graphql" "v-ok.graphql" "validtypes.graphql" "variadic.graphql" "weird_type_cases.graphql" "wrapped_type.graphql" +//go:embed var sourcesFS embed.FS func sourceData(filename string) string { @@ -2162,33 +2162,648 @@ func sourceData(filename string) string { } var sources = []*ast.Source{ - {Name: "builtinscalar.graphql", Input: sourceData("builtinscalar.graphql"), BuiltIn: false}, - {Name: "complexity.graphql", Input: sourceData("complexity.graphql"), BuiltIn: false}, - {Name: "defaults.graphql", Input: sourceData("defaults.graphql"), BuiltIn: false}, - {Name: "directive.graphql", Input: sourceData("directive.graphql"), BuiltIn: false}, - {Name: "embedded.graphql", Input: sourceData("embedded.graphql"), BuiltIn: false}, - {Name: "enum.graphql", Input: sourceData("enum.graphql"), BuiltIn: false}, - {Name: "interfaces.graphql", Input: sourceData("interfaces.graphql"), BuiltIn: false}, - {Name: "issue896.graphql", Input: sourceData("issue896.graphql"), BuiltIn: false}, - {Name: "loops.graphql", Input: sourceData("loops.graphql"), BuiltIn: false}, - {Name: "maps.graphql", Input: sourceData("maps.graphql"), BuiltIn: false}, - {Name: "mutation_with_custom_scalar.graphql", Input: sourceData("mutation_with_custom_scalar.graphql"), BuiltIn: false}, - {Name: "nulls.graphql", Input: sourceData("nulls.graphql"), BuiltIn: false}, - {Name: "panics.graphql", Input: sourceData("panics.graphql"), BuiltIn: false}, - {Name: "primitive_objects.graphql", Input: sourceData("primitive_objects.graphql"), BuiltIn: false}, - {Name: "ptr_to_ptr_input.graphql", Input: sourceData("ptr_to_ptr_input.graphql"), BuiltIn: false}, - {Name: "ptr_to_slice.graphql", Input: sourceData("ptr_to_slice.graphql"), BuiltIn: false}, - {Name: "scalar_context.graphql", Input: sourceData("scalar_context.graphql"), BuiltIn: false}, - {Name: "scalar_default.graphql", Input: sourceData("scalar_default.graphql"), BuiltIn: false}, - {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, - {Name: "slices.graphql", Input: sourceData("slices.graphql"), BuiltIn: false}, - {Name: "typefallback.graphql", Input: sourceData("typefallback.graphql"), BuiltIn: false}, - {Name: "useptr.graphql", Input: sourceData("useptr.graphql"), BuiltIn: false}, - {Name: "v-ok.graphql", Input: sourceData("v-ok.graphql"), BuiltIn: false}, - {Name: "validtypes.graphql", Input: sourceData("validtypes.graphql"), BuiltIn: false}, - {Name: "variadic.graphql", Input: sourceData("variadic.graphql"), BuiltIn: false}, - {Name: "weird_type_cases.graphql", Input: sourceData("weird_type_cases.graphql"), BuiltIn: false}, - {Name: "wrapped_type.graphql", Input: sourceData("wrapped_type.graphql"), BuiltIn: false}, + {Name: "../../../../../../builtinscalar.graphql", Input: ` +""" +Since gqlgen defines default implementation for a Map scalar, this tests that the builtin is _not_ +added to the TypeMap +""" +type Map { + id: ID! +} +`, BuiltIn: false}, + {Name: "../../../../../../complexity.graphql", Input: `extend type Query { + overlapping: OverlappingFields +} + +type OverlappingFields { + oneFoo: Int! @goField(name: "foo") + twoFoo: Int! @goField(name: "foo") + oldFoo: Int! @goField(name: "foo", forceResolver: true) + newFoo: Int! + new_foo: Int! +} +`, BuiltIn: false}, + {Name: "../../../../../../defaults.graphql", Input: `extend type Query { + defaultParameters( + falsyBoolean: Boolean = false + truthyBoolean: Boolean = true + ): DefaultParametersMirror! +} + +extend type Mutation { + defaultInput(input: DefaultInput!): DefaultParametersMirror! +} + +input DefaultInput { + falsyBoolean: Boolean = false + truthyBoolean: Boolean = true +} + +type DefaultParametersMirror { + falsyBoolean: Boolean + truthyBoolean: Boolean +} +`, BuiltIn: false}, + {Name: "../../../../../../directive.graphql", Input: `directive @length(min: Int!, max: Int, message: String) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | FIELD_DEFINITION +directive @range(min: Int = 0, max: Int) on ARGUMENT_DEFINITION +directive @custom on ARGUMENT_DEFINITION +directive @logged(id: UUID!) on FIELD +directive @toNull on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | FIELD_DEFINITION +directive @directive1 on FIELD_DEFINITION +directive @directive2 on FIELD_DEFINITION +directive @directive3 on INPUT_OBJECT +directive @unimplemented on FIELD_DEFINITION +directive @order1(location: String!) repeatable on FIELD_DEFINITION | OBJECT +directive @order2(location: String!) on OBJECT + +extend type Query { + directiveArg(arg: String! @length(min:1, max: 255, message: "invalid length")): String + directiveNullableArg(arg: Int @range(min:0), arg2: Int @range, arg3: String @toNull): String + directiveInputNullable(arg: InputDirectives): String + directiveInput(arg: InputDirectives!): String + directiveInputType(arg: InnerInput! @custom): String + directiveObject: ObjectDirectives @order1(location: "Query_field") + directiveObjectWithCustomGoModel: ObjectDirectivesWithCustomGoModel + directiveFieldDef(ret: String!): String! @length(min: 1, message: "not valid") + directiveField: String + directiveDouble: String @directive1 @directive2 + directiveUnimplemented: String @unimplemented +} + +extend type Subscription { + directiveArg(arg: String! @length(min:1, max: 255, message: "invalid length")): String + directiveNullableArg(arg: Int @range(min:0), arg2: Int @range, arg3: String @toNull): String + directiveDouble: String @directive1 @directive2 + directiveUnimplemented: String @unimplemented +} + +input InputDirectives @directive3 { + text: String! @length(min: 0, max: 7, message: "not valid") + nullableText: String @toNull + inner: InnerDirectives! + innerNullable: InnerDirectives + thirdParty: ThirdParty @length(min: 0, max: 7) +} + +input InnerDirectives { + message: String! @length(min: 1, message: "not valid") +} + +type ObjectDirectives @order1(location: "order1_1") @order1(location: "order1_2") @order2(location: "order2_1") { + text: String! @length(min: 0, max: 7, message: "not valid") + nullableText: String @toNull + order: [String!]! +} + +type ObjectDirectivesWithCustomGoModel { + nullableText: String @toNull +} +`, BuiltIn: false}, + {Name: "../../../../../../embedded.graphql", Input: `extend type Query { + embeddedCase1: EmbeddedCase1 + embeddedCase2: EmbeddedCase2 + embeddedCase3: EmbeddedCase3 +} + +type EmbeddedCase1 @goModel(model:"singlefile.EmbeddedCase1") { + exportedEmbeddedPointerExportedMethod: String! +} + +type EmbeddedCase2 @goModel(model:"singlefile.EmbeddedCase2") { + unexportedEmbeddedPointerExportedMethod: String! +} + +type EmbeddedCase3 @goModel(model:"singlefile.EmbeddedCase3") { + unexportedEmbeddedInterfaceExportedMethod: String! +} +`, BuiltIn: false}, + {Name: "../../../../../../enum.graphql", Input: `enum EnumTest { + OK + NG +} + +input InputWithEnumValue { + enum: EnumTest! +} + +extend type Query { + enumInInput(input: InputWithEnumValue): EnumTest! +} +`, BuiltIn: false}, + {Name: "../../../../../../interfaces.graphql", Input: `extend type Query { + shapes: [Shape] + noShape: Shape @makeNil + node: Node! + noShapeTypedNil: Shape @makeTypedNil + animal: Animal @makeTypedNil + notAnInterface: BackedByInterface +} + +interface Animal { + species: String! +} + +type BackedByInterface { + id: String! + thisShouldBind: String! + thisShouldBindWithError: String! +} + +type Dog implements Animal { + species: String! + dogBreed: String! +} + +type Cat implements Animal { + species: String! + catBreed: String! +} + +type Coordinates { + x: Float! + y: Float! +} +interface Shape { + area: Float + coordinates: Coordinates +} + +type Circle implements Shape { + radius: Float + area: Float + coordinates: Coordinates +} +type Rectangle implements Shape { + length: Float + width: Float + area: Float + coordinates: Coordinates +} +union ShapeUnion @goModel(model: "singlefile.ShapeUnion") = Circle | Rectangle + +directive @makeNil on FIELD_DEFINITION +directive @makeTypedNil on FIELD_DEFINITION + +interface Node { + id: ID! + child: Node! +} + +type ConcreteNodeA implements Node { + id: ID! + child: Node! + name: String! +} + +" Implements the Node interface with another interface " +type ConcreteNodeInterface implements Node { + id: ID! + child: Node! +} +`, BuiltIn: false}, + {Name: "../../../../../../issue896.graphql", Input: `# This example should build stable output. If the file content starts +# alternating nondeterministically between two outputs, then see +# https://github.com/99designs/gqlgen/issues/896. + +extend schema { + query: Query + subscription: Subscription +} + +type CheckIssue896 {id: Int} + +extend type Query { + issue896a: [CheckIssue896!] # Note the "!" or lack thereof. +} + +extend type Subscription { + issue896b: [CheckIssue896] # Note the "!" or lack thereof. +} +`, BuiltIn: false}, + {Name: "../../../../../../loops.graphql", Input: `type LoopA { + b: LoopB! +} + +type LoopB { + a: LoopA! +} +`, BuiltIn: false}, + {Name: "../../../../../../maps.graphql", Input: `extend type Query { + mapStringInterface(in: MapStringInterfaceInput): MapStringInterfaceType + mapNestedStringInterface(in: NestedMapInput): MapStringInterfaceType +} + +type MapStringInterfaceType @goModel(model: "map[string]interface{}") { + a: String + b: Int +} + +input MapStringInterfaceInput @goModel(model: "map[string]interface{}") { + a: String + b: Int +} + +input NestedMapInput { + map: MapStringInterfaceInput +} +`, BuiltIn: false}, + {Name: "../../../../../../mutation_with_custom_scalar.graphql", Input: `extend type Mutation { + updateSomething(input: SpecialInput!): String! +} + +scalar Email + +input SpecialInput { + nesting: NestedInput! +} + +input NestedInput { + field: Email! +} +`, BuiltIn: false}, + {Name: "../../../../../../nulls.graphql", Input: `extend type Query { + errorBubble: Error + errorBubbleList: [Error!] + errorList: [Error] + errors: Errors + valid: String! +} + +extend type Subscription { + errorRequired: Error! +} + +type Errors { + a: Error! + b: Error! + c: Error! + d: Error! + e: Error! +} + +type Error { + id: ID! + errorOnNonRequiredField: String + errorOnRequiredField: String! + nilOnRequiredField: String! +} +`, BuiltIn: false}, + {Name: "../../../../../../panics.graphql", Input: `extend type Query { + panics: Panics +} + +type Panics { + fieldScalarMarshal: [MarshalPanic!]! + fieldFuncMarshal(u: [MarshalPanic!]!): [MarshalPanic!]! + argUnmarshal(u: [MarshalPanic!]!): Boolean! + +} + +scalar MarshalPanic +`, BuiltIn: false}, + {Name: "../../../../../../primitive_objects.graphql", Input: `extend type Query { + primitiveObject: [Primitive!]! + primitiveStringObject: [PrimitiveString!]! +} + +type Primitive { + value: Int! + squared: Int! +} + +type PrimitiveString { + value: String! + doubled: String! + len: Int! +} +`, BuiltIn: false}, + {Name: "../../../../../../ptr_to_ptr_input.graphql", Input: `type PtrToPtrOuter { + name: String! + inner: PtrToPtrInner + stupidInner: PtrToPtrInner +} + +type PtrToPtrInner { + key: String! + value: String! +} + +input UpdatePtrToPtrOuter { + name: String + inner: UpdatePtrToPtrInner + stupidInner: UpdatePtrToPtrInner +} + +input UpdatePtrToPtrInner { + key: String + value: String +} + +extend type Mutation { + updatePtrToPtr(input: UpdatePtrToPtrOuter!): PtrToPtrOuter! +} +`, BuiltIn: false}, + {Name: "../../../../../../ptr_to_slice.graphql", Input: `type PtrToSliceContainer { + ptrToSlice: [String!] +} + +extend type Query { + ptrToSliceContainer: PtrToSliceContainer! +} +`, BuiltIn: false}, + {Name: "../../../../../../scalar_context.graphql", Input: `extend type Query { + infinity: Float! + stringFromContextInterface: StringFromContextInterface! + stringFromContextFunction: StringFromContextFunction! +} + +scalar StringFromContextInterface +scalar StringFromContextFunction +`, BuiltIn: false}, + {Name: "../../../../../../scalar_default.graphql", Input: `extend type Query { + defaultScalar(arg: DefaultScalarImplementation! = "default"): DefaultScalarImplementation! +} + +""" This doesnt have an implementation in the typemap, so it should act like a string """ +scalar DefaultScalarImplementation + +type EmbeddedDefaultScalar { + value: DefaultScalarImplementation +} +`, BuiltIn: false}, + {Name: "../../../../../../schema.graphql", Input: `directive @goModel( + model: String + models: [String!] +) on OBJECT | INPUT_OBJECT | SCALAR | ENUM | INTERFACE | UNION +directive @goField( + forceResolver: Boolean + name: String +) on INPUT_FIELD_DEFINITION | FIELD_DEFINITION + +type Query { + invalidIdentifier: InvalidIdentifier + collision: It + mapInput(input: Changes): Boolean + recursive(input: RecursiveInputSlice): Boolean + nestedInputs(input: [[OuterInput]] = [[{ inner: { id: 1 } }]]): Boolean + nestedOutputs: [[OuterObject]] + modelMethods: ModelMethods + user(id: Int!): User! + nullableArg(arg: Int = 123): String + inputSlice(arg: [String!]!): Boolean! + inputNullableSlice(arg: [String!]): Boolean! + shapeUnion: ShapeUnion! + autobind: Autobind + deprecatedField: String! @deprecated(reason: "test deprecated directive") +} + +type Subscription { + updated: String! + initPayload: String! +} + +type Pet { + id: Int! + friends(limit: Int): [Pet!] @goField(forceResolver: true) +} + +type User { + id: Int! + friends: [User!]! @goField(forceResolver: true) + created: Time! + updated: Time + pets(limit: Int): [Pet!] @goField(forceResolver: true) +} + +type Autobind { + int: Int! + int32: Int! + int64: Int! + + idStr: ID! + idInt: ID! +} + +type ModelMethods { + resolverField: Boolean! + noContext: Boolean! + withContext: Boolean! +} + +type InvalidIdentifier { + id: Int! +} + +type It { + id: ID! +} + +input Changes @goModel(model: "map[string]interface{}") { + a: Int + b: Int +} + +input RecursiveInputSlice { + self: [RecursiveInputSlice!] +} + +input InnerInput { + id: Int! +} + +input OuterInput { + inner: InnerInput! +} + +scalar ThirdParty @goModel(model:"singlefile.ThirdParty") + +type OuterObject { + inner: InnerObject! +} + +type InnerObject { + id: Int! +} + +type ForcedResolver { + field: Circle @goField(forceResolver: true) +} + +type EmbeddedPointer @goModel(model:"singlefile.EmbeddedPointerModel") { + ID: String + Title: String +} + +scalar UUID + +enum Status { + OK + ERROR +} + +scalar Time +`, BuiltIn: false}, + {Name: "../../../../../../slices.graphql", Input: `extend type Query { + slices: Slices + scalarSlice: Bytes! +} + +type Slices { + test1: [String] + test2: [String!] + test3: [String]! + test4: [String!]! +} + +scalar Bytes +`, BuiltIn: false}, + {Name: "../../../../../../typefallback.graphql", Input: `extend type Query { + fallback(arg: FallbackToStringEncoding!): FallbackToStringEncoding! +} + +enum FallbackToStringEncoding { + A + B + C +} +`, BuiltIn: false}, + {Name: "../../../../../../useptr.graphql", Input: `type A { + id: ID! +} + +type B { + id: ID! +} + +union TestUnion = A | B + +extend type Query { + optionalUnion: TestUnion +} +`, BuiltIn: false}, + {Name: "../../../../../../v-ok.graphql", Input: `extend type Query { + vOkCaseValue: VOkCaseValue + vOkCaseNil: VOkCaseNil +} + +type VOkCaseValue @goModel(model:"singlefile.VOkCaseValue") { + value: String +} + +type VOkCaseNil @goModel(model:"singlefile.VOkCaseNil") { + value: String +} +`, BuiltIn: false}, + {Name: "../../../../../../validtypes.graphql", Input: `extend type Query { + validType: ValidType +} + +""" These things are all valid, but without care generate invalid go code """ +type ValidType { + differentCase: String! + different_case: String! @goField(name:"DifferentCaseOld") + validInputKeywords(input: ValidInput): Boolean! + validArgs( + break: String!, + default: String!, + func: String!, + interface: String!, + select: String!, + case: String!, + defer: String!, + go: String!, + map: String!, + struct: String!, + chan: String!, + else: String!, + goto: String!, + package: String!, + switch: String!, + const: String!, + fallthrough: String!, + if: String!, + range: String!, + type: String!, + continue: String!, + for: String!, + import: String!, + return: String!, + var: String!, + _: String!, + ): Boolean! +} + +input ValidInput { + break: String! + default: String! + func: String! + interface: String! + select: String! + case: String! + defer: String! + go: String! + map: String! + struct: String! + chan: String! + else: String! + goto: String! + package: String! + switch: String! + const: String! + fallthrough: String! + if: String! + range: String! + type: String! + continue: String! + for: String! + import: String! + return: String! + var: String! + _: String! @goField(name: "Underscore") +} + +# see https://github.com/99designs/gqlgen/issues/694 +type Content_User { + foo: String +} + +type Content_Post { + foo: String +} + +union Content_Child = Content_User | Content_Post +`, BuiltIn: false}, + {Name: "../../../../../../variadic.graphql", Input: `extend type Query { + variadicModel: VariadicModel +} + +type VariadicModel { + value(rank: Int!): String +} +`, BuiltIn: false}, + {Name: "../../../../../../weird_type_cases.graphql", Input: `# regression test for https://github.com/99designs/gqlgen/issues/583 + +type asdfIt { id: ID! } +type iIt { id: ID! } +type AIt { id: ID! } +type XXIt { id: ID! } +type AbIt { id: ID! } +type XxIt { id: ID! } +`, BuiltIn: false}, + {Name: "../../../../../../wrapped_type.graphql", Input: `# regression test for https://github.com/99designs/gqlgen/issues/721 + +extend type Query { + wrappedStruct: WrappedStruct! + wrappedScalar: WrappedScalar! + wrappedMap: WrappedMap! + wrappedSlice: WrappedSlice! +} + +type WrappedStruct { name: WrappedScalar!, desc: WrappedScalar } +scalar WrappedScalar +type WrappedMap { get(key: String!): String! } +type WrappedSlice { get(idx: Int!): String! } +`, BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/integration/generated.go b/integration/generated.go index fb0a8adcd39..f8269bfa552 100644 --- a/integration/generated.go +++ b/integration/generated.go @@ -5,6 +5,7 @@ package integration import ( "bytes" "context" + "embed" "errors" "fmt" "strconv" @@ -271,8 +272,19 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } +//go:embed +var sourcesFS embed.FS + +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) +} + var sources = []*ast.Source{ - {Name: "schema.graphql", Input: `"This directive does magical things" + {Name: "../../../../schema.graphql", Input: `"This directive does magical things" directive @magic(kind: Int) on FIELD_DEFINITION scalar Map @@ -329,7 +341,7 @@ enum ErrorType { # this is a comment with a ` + "`" + `backtick` + "`" + ` `, BuiltIn: false}, - {Name: "user.graphql", Input: `type User { + {Name: "../../../../user.graphql", Input: `type User { name: String! likes: [String!]! } diff --git a/plugin/federation/testdata/entityresolver/generated/exec.go b/plugin/federation/testdata/entityresolver/generated/exec.go index 7c067979351..24a61598825 100644 --- a/plugin/federation/testdata/entityresolver/generated/exec.go +++ b/plugin/federation/testdata/entityresolver/generated/exec.go @@ -5,6 +5,7 @@ package generated import ( "bytes" "context" + "embed" "errors" "fmt" "strconv" @@ -682,8 +683,19 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } +//go:embed +var sourcesFS embed.FS + +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) +} + var sources = []*ast.Source{ - {Name: "testdata/entityresolver/schema.graphql", Input: `directive @entityResolver(multi: Boolean) on OBJECT + {Name: "../../../../../../../../testdata/entityresolver/schema.graphql", Input: `directive @entityResolver(multi: Boolean) on OBJECT type Hello @key(fields: "name") { name: String! @@ -761,7 +773,7 @@ type MultiHelloMultipleRequires @key(fields: "name") @entityResolver(multi: true key3: String! @requires(fields: "key1 key2") } `, BuiltIn: false}, - {Name: "federation/directives.graphql", Input: ` + {Name: "../../../../../../../../federation/directives.graphql", Input: ` scalar _Any scalar _FieldSet @@ -772,7 +784,7 @@ type MultiHelloMultipleRequires @key(fields: "name") @entityResolver(multi: true directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE `, BuiltIn: true}, - {Name: "federation/entity.graphql", Input: ` + {Name: "../../../../../../../../federation/entity.graphql", Input: ` # a union of all types that use the @key directive union _Entity = Hello | HelloMultiSingleKeys | HelloWithErrors | MultiHello | MultiHelloMultipleRequires | MultiHelloRequires | MultiHelloWithError | MultiPlanetRequiresNested | PlanetMultipleRequires | PlanetRequires | PlanetRequiresNested | World | WorldName | WorldWithMultipleKeys From 30eb8f9f1eb688e990d5cae6886b73184df6a0ec Mon Sep 17 00:00:00 2001 From: Viktor Stanchev Date: Mon, 25 Apr 2022 01:41:27 +0000 Subject: [PATCH 4/8] handle no embeddable sources --- _examples/chat/generated.go | 37 +++++--- _examples/config/generated.go | 47 +++++++--- _examples/dataloader/generated.go | 42 ++++++--- .../accounts/graph/generated/generated.go | 30 +----- .../products/graph/generated/generated.go | 30 +----- .../reviews/graph/generated/generated.go | 30 +----- _examples/fileupload/generated.go | 40 +++++--- _examples/scalars/generated.go | 51 +++++++--- _examples/selection/generated.go | 34 ++++--- _examples/starwars/generated/exec.go | 14 +-- _examples/todo/generated.go | 50 +++++++--- _examples/type-system-extension/generated.go | 92 +++++++++++++++---- codegen/data.go | 10 ++ codegen/generated!.gotpl | 2 + codegen/root_.gotpl | 2 + codegen/testserver/singlefile/generated.go | 12 --- integration/generated.go | 12 --- .../testdata/entityresolver/generated/exec.go | 12 --- 18 files changed, 319 insertions(+), 228 deletions(-) diff --git a/_examples/chat/generated.go b/_examples/chat/generated.go index 5c20ffe54af..19c0efd1659 100644 --- a/_examples/chat/generated.go +++ b/_examples/chat/generated.go @@ -5,7 +5,6 @@ package chat import ( "bytes" "context" - "embed" "errors" "fmt" "io" @@ -260,19 +259,35 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -//go:embed "schema.graphql" -var sourcesFS embed.FS +var sources = []*ast.Source{ + {Name: "../../../../../schema.graphql", Input: `type Chatroom { + name: String! + messages: [Message!]! +} -func sourceData(filename string) string { - data, err := sourcesFS.ReadFile(filename) - if err != nil { - panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) - } - return string(data) +type Message { + id: ID! + text: String! + createdBy: String! + createdAt: Time! } -var sources = []*ast.Source{ - {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, +type Query { + room(name:String!): Chatroom +} + +type Mutation { + post(text: String!, username: String!, roomName: String!): Message! +} + +type Subscription { + messageAdded(roomName: String!): Message! +} + +scalar Time + +directive @user(username: String!) on SUBSCRIPTION +`, BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/_examples/config/generated.go b/_examples/config/generated.go index 95ccb91b5d3..3d0e15e7cd6 100644 --- a/_examples/config/generated.go +++ b/_examples/config/generated.go @@ -5,7 +5,6 @@ package config import ( "bytes" "context" - "embed" "errors" "fmt" "strconv" @@ -251,21 +250,43 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -//go:embed "schema.graphql" "todo.graphql" "user.graphql" -var sourcesFS embed.FS +var sources = []*ast.Source{ + {Name: "../../../../../schema.graphql", Input: `directive @goModel(model: String, models: [String!]) on OBJECT | INPUT_OBJECT | SCALAR | ENUM | INTERFACE | UNION +directive @goField(forceResolver: Boolean, name: String) on INPUT_FIELD_DEFINITION | FIELD_DEFINITION -func sourceData(filename string) string { - data, err := sourcesFS.ReadFile(filename) - if err != nil { - panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) - } - return string(data) +type Query { + todos: [Todo!]! } -var sources = []*ast.Source{ - {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, - {Name: "todo.graphql", Input: sourceData("todo.graphql"), BuiltIn: false}, - {Name: "user.graphql", Input: sourceData("user.graphql"), BuiltIn: false}, +type Mutation { + createTodo(input: NewTodo!): Todo! +} +`, BuiltIn: false}, + {Name: "../../../../../todo.graphql", Input: `type Todo { + id: ID! @goField(forceResolver: true) + databaseId: Int! + text: String! + done: Boolean! + user: User! +} + +input NewTodo { + text: String! + userId: String! +} +`, BuiltIn: false}, + {Name: "../../../../../user.graphql", Input: `type User +@goModel(model:"github.com/99designs/gqlgen/_examples/config.User") { + id: ID! + name: String! @goField(name:"FullName") + role: role! +} + +type role +@goModel(model:"github.com/99designs/gqlgen/_examples/config.UserRole") { + name: String! +} +`, BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/_examples/dataloader/generated.go b/_examples/dataloader/generated.go index 92fa3f49603..52883189121 100644 --- a/_examples/dataloader/generated.go +++ b/_examples/dataloader/generated.go @@ -5,7 +5,6 @@ package dataloader import ( "bytes" "context" - "embed" "errors" "fmt" "strconv" @@ -271,19 +270,40 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -//go:embed "schema.graphql" -var sourcesFS embed.FS +var sources = []*ast.Source{ + {Name: "../../../../../schema.graphql", Input: `type Query { + customers: [Customer!] -func sourceData(filename string) string { - data, err := sourcesFS.ReadFile(filename) - if err != nil { - panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) - } - return string(data) + # these methods are here to test code generation of nested arrays + torture1d(customerIds: [Int!]): [Customer!] + torture2d(customerIds: [[Int!]]): [[Customer!]] } -var sources = []*ast.Source{ - {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, +type Customer { + id: Int! + name: String! + address: Address + orders: [Order!] +} + +type Address { + id: Int! + street: String! + country: String! +} + +type Order { + id: Int! + date: Time! + amount: Float! + items: [Item!] +} + +type Item { + name: String! +} +scalar Time +`, BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/_examples/federation/accounts/graph/generated/generated.go b/_examples/federation/accounts/graph/generated/generated.go index fdd92ef9436..c959e5b7f3f 100644 --- a/_examples/federation/accounts/graph/generated/generated.go +++ b/_examples/federation/accounts/graph/generated/generated.go @@ -5,7 +5,6 @@ package generated import ( "bytes" "context" - "embed" "errors" "fmt" "strconv" @@ -247,19 +246,8 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -//go:embed -var sourcesFS embed.FS - -func sourceData(filename string) string { - data, err := sourcesFS.ReadFile(filename) - if err != nil { - panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) - } - return string(data) -} - var sources = []*ast.Source{ - {Name: "../schema.graphqls", Input: `extend type Query { + {Name: "../../../../../../../../graph/schema.graphqls", Input: `extend type Query { me: User } @@ -275,8 +263,7 @@ type User @key(fields: "id") { username: String! } `, BuiltIn: false}, -<<<<<<< HEAD - {Name: "federation/directives.graphql", Input: ` + {Name: "../../../../../../../../federation/directives.graphql", Input: ` scalar _Any scalar _FieldSet @@ -286,19 +273,8 @@ type User @key(fields: "id") { directive @extends on OBJECT | INTERFACE directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE -======= - {Name: "../../federation/directives.graphql", Input: ` -scalar _Any -scalar _FieldSet - -directive @external on FIELD_DEFINITION -directive @requires(fields: _FieldSet!) on FIELD_DEFINITION -directive @provides(fields: _FieldSet!) on FIELD_DEFINITION -directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE -directive @extends on OBJECT | INTERFACE ->>>>>>> c657a54f (working poc) `, BuiltIn: true}, - {Name: "../../federation/entity.graphql", Input: ` + {Name: "../../../../../../../../federation/entity.graphql", Input: ` # a union of all types that use the @key directive union _Entity = EmailHost | User diff --git a/_examples/federation/products/graph/generated/generated.go b/_examples/federation/products/graph/generated/generated.go index 9122d31685f..23d6c10f368 100644 --- a/_examples/federation/products/graph/generated/generated.go +++ b/_examples/federation/products/graph/generated/generated.go @@ -5,7 +5,6 @@ package generated import ( "bytes" "context" - "embed" "errors" "fmt" "strconv" @@ -274,19 +273,8 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -//go:embed -var sourcesFS embed.FS - -func sourceData(filename string) string { - data, err := sourcesFS.ReadFile(filename) - if err != nil { - panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) - } - return string(data) -} - var sources = []*ast.Source{ - {Name: "../schema.graphqls", Input: `extend type Query { + {Name: "../../../../../../../../graph/schema.graphqls", Input: `extend type Query { topProducts(first: Int = 5): [Product] } @@ -303,8 +291,7 @@ type Product @key(fields: "manufacturer { id } id") @key(fields: "upc") { price: Int! } `, BuiltIn: false}, -<<<<<<< HEAD - {Name: "federation/directives.graphql", Input: ` + {Name: "../../../../../../../../federation/directives.graphql", Input: ` scalar _Any scalar _FieldSet @@ -314,19 +301,8 @@ type Product @key(fields: "manufacturer { id } id") @key(fields: "upc") { directive @extends on OBJECT | INTERFACE directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE -======= - {Name: "../../federation/directives.graphql", Input: ` -scalar _Any -scalar _FieldSet - -directive @external on FIELD_DEFINITION -directive @requires(fields: _FieldSet!) on FIELD_DEFINITION -directive @provides(fields: _FieldSet!) on FIELD_DEFINITION -directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE -directive @extends on OBJECT | INTERFACE ->>>>>>> c657a54f (working poc) `, BuiltIn: true}, - {Name: "../../federation/entity.graphql", Input: ` + {Name: "../../../../../../../../federation/entity.graphql", Input: ` # a union of all types that use the @key directive union _Entity = Manufacturer | Product diff --git a/_examples/federation/reviews/graph/generated/generated.go b/_examples/federation/reviews/graph/generated/generated.go index 12cc95f7d01..ad8c6221aa3 100644 --- a/_examples/federation/reviews/graph/generated/generated.go +++ b/_examples/federation/reviews/graph/generated/generated.go @@ -5,7 +5,6 @@ package generated import ( "bytes" "context" - "embed" "errors" "fmt" "strconv" @@ -296,19 +295,8 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -//go:embed -var sourcesFS embed.FS - -func sourceData(filename string) string { - data, err := sourcesFS.ReadFile(filename) - if err != nil { - panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) - } - return string(data) -} - var sources = []*ast.Source{ - {Name: "../schema.graphqls", Input: `type Review { + {Name: "../../../../../../../../graph/schema.graphqls", Input: `type Review { body: String! author: User! @provides(fields: "username") product: Product! @@ -335,8 +323,7 @@ extend type Product @key(fields: " manufacturer{ id} id") { reviews: [Review] } `, BuiltIn: false}, -<<<<<<< HEAD - {Name: "federation/directives.graphql", Input: ` + {Name: "../../../../../../../../federation/directives.graphql", Input: ` scalar _Any scalar _FieldSet @@ -346,19 +333,8 @@ extend type Product @key(fields: " manufacturer{ id} id") { directive @extends on OBJECT | INTERFACE directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE -======= - {Name: "../../federation/directives.graphql", Input: ` -scalar _Any -scalar _FieldSet - -directive @external on FIELD_DEFINITION -directive @requires(fields: _FieldSet!) on FIELD_DEFINITION -directive @provides(fields: _FieldSet!) on FIELD_DEFINITION -directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE -directive @extends on OBJECT | INTERFACE ->>>>>>> c657a54f (working poc) `, BuiltIn: true}, - {Name: "../../federation/entity.graphql", Input: ` + {Name: "../../../../../../../../federation/entity.graphql", Input: ` # a union of all types that use the @key directive union _Entity = EmailHost | Manufacturer | Product | User diff --git a/_examples/fileupload/generated.go b/_examples/fileupload/generated.go index 986aef9ea84..eaaf9d962b8 100644 --- a/_examples/fileupload/generated.go +++ b/_examples/fileupload/generated.go @@ -5,7 +5,6 @@ package fileupload import ( "bytes" "context" - "embed" "errors" "fmt" "strconv" @@ -240,19 +239,38 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -//go:embed "schema.graphql" -var sourcesFS embed.FS +var sources = []*ast.Source{ + {Name: "../../../../../schema.graphql", Input: `"The ` + "`" + `Upload` + "`" + ` scalar type represents a multipart file upload." +scalar Upload -func sourceData(filename string) string { - data, err := sourcesFS.ReadFile(filename) - if err != nil { - panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) - } - return string(data) +"The ` + "`" + `File` + "`" + ` type, represents the response of uploading a file." +type File { + id: Int! + name: String! + content: String! + contentType: String! } -var sources = []*ast.Source{ - {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, +"The ` + "`" + `UploadFile` + "`" + ` type, represents the request for uploading a file with certain payload." +input UploadFile { + id: Int! + file: Upload! +} + +"The ` + "`" + `Query` + "`" + ` type, represents all of the entry points into our object graph." +type Query { + empty: String! +} + +"The ` + "`" + `Mutation` + "`" + ` type, represents all updates we can make to our data." +type Mutation { + singleUpload(file: Upload!): File! + singleUploadWithPayload(req: UploadFile!): File! + multipleUpload(files: [Upload!]!): [File!]! + multipleUploadWithPayload(req: [UploadFile!]!): [File!]! +} + +`, BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/_examples/scalars/generated.go b/_examples/scalars/generated.go index e2b69dd4747..bd238719eca 100644 --- a/_examples/scalars/generated.go +++ b/_examples/scalars/generated.go @@ -5,7 +5,6 @@ package scalars import ( "bytes" "context" - "embed" "errors" "fmt" "strconv" @@ -278,19 +277,49 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -//go:embed "schema.graphql" -var sourcesFS embed.FS +var sources = []*ast.Source{ + {Name: "../../../../../schema.graphql", Input: `type Query { + user(id: ID!): User + search(input: SearchArgs = {location: "37,144", isBanned: false}): [User!]! + userByTier(tier: Tier!, darkMode: DarkMode!): [User!]! +} -func sourceData(filename string) string { - data, err := sourcesFS.ReadFile(filename) - if err != nil { - panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) - } - return string(data) +type User { + id: ID! + name: String! + created: Timestamp + modified: Timestamp + valPrefs: DarkMode + ptrPrefs: DarkMode + isBanned: Banned! + primitiveResolver: String! + customResolver: Point! + address: Address + tier: Tier } -var sources = []*ast.Source{ - {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, +type Address { + id: ID! + location: Point +} + +input SearchArgs { + location: Point + createdAfter: Timestamp + isBanned: Banned # TODO: This can be a Boolean again once multiple backing types are allowed +} + +enum Tier { + A + B + C +} + +scalar Timestamp +scalar Point +scalar Banned +scalar DarkMode +`, BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/_examples/selection/generated.go b/_examples/selection/generated.go index ee3a0f2f824..da3c03801dc 100644 --- a/_examples/selection/generated.go +++ b/_examples/selection/generated.go @@ -5,7 +5,6 @@ package selection import ( "bytes" "context" - "embed" "errors" "fmt" "strconv" @@ -195,19 +194,32 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -//go:embed "schema.graphql" -var sourcesFS embed.FS +var sources = []*ast.Source{ + {Name: "../../../../../schema.graphql", Input: `interface Event { + selection: [String!] + collected: [String!] +} -func sourceData(filename string) string { - data, err := sourcesFS.ReadFile(filename) - if err != nil { - panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) - } - return string(data) +type Post implements Event { + message: String! + sent: Time! + selection: [String!] + collected: [String!] } -var sources = []*ast.Source{ - {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, +type Like implements Event { + reaction: String! + sent: Time! + selection: [String!] + collected: [String!] +} + +type Query { + events: [Event!] +} + +scalar Time +`, BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/_examples/starwars/generated/exec.go b/_examples/starwars/generated/exec.go index 7feccd993e9..c0f262023d9 100644 --- a/_examples/starwars/generated/exec.go +++ b/_examples/starwars/generated/exec.go @@ -5,7 +5,6 @@ package generated import ( "bytes" "context" - "embed" "errors" "fmt" "strconv" @@ -555,19 +554,8 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -//go:embed -var sourcesFS embed.FS - -func sourceData(filename string) string { - data, err := sourcesFS.ReadFile(filename) - if err != nil { - panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) - } - return string(data) -} - var sources = []*ast.Source{ - {Name: "../schema.graphql", Input: `# The query type, represents all of the entry points into our object graph + {Name: "../../../../../../schema.graphql", Input: `# The query type, represents all of the entry points into our object graph type Query { hero(episode: Episode = NEWHOPE): Character reviews(episode: Episode!, since: Time): [Review!]! diff --git a/_examples/todo/generated.go b/_examples/todo/generated.go index 2fd43e5cc10..05e7a987f1c 100644 --- a/_examples/todo/generated.go +++ b/_examples/todo/generated.go @@ -5,7 +5,6 @@ package todo import ( "bytes" "context" - "embed" "errors" "fmt" "strconv" @@ -232,19 +231,48 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -//go:embed "schema.graphql" -var sourcesFS embed.FS +var sources = []*ast.Source{ + {Name: "../../../../../schema.graphql", Input: `schema { + query: MyQuery + mutation: MyMutation +} -func sourceData(filename string) string { - data, err := sourcesFS.ReadFile(filename) - if err != nil { - panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) - } - return string(data) +type MyQuery { + todo(id: ID!): Todo + lastTodo: Todo + todos: [Todo!]! } -var sources = []*ast.Source{ - {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, +type MyMutation { + createTodo(todo: TodoInput!): Todo! + updateTodo(id: ID!, changes: Map!): Todo +} + +type Todo { + id: ID! + text: String! + done: Boolean! @hasRole(role: OWNER) # only the owner can see if a todo is done +} + +"Passed to createTodo to create a new todo" +input TodoInput { + "The body text" + text: String! + "Is it done already?" + done: Boolean +} + +scalar Map + +"Prevents access to a field if the user doesnt have the matching role" +directive @hasRole(role: Role!) on FIELD_DEFINITION +directive @user(id: ID!) on MUTATION | QUERY | FIELD + +enum Role { + ADMIN + OWNER +} +`, BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/_examples/type-system-extension/generated.go b/_examples/type-system-extension/generated.go index a4d50d2e185..9b4edbc446e 100644 --- a/_examples/type-system-extension/generated.go +++ b/_examples/type-system-extension/generated.go @@ -5,7 +5,6 @@ package type_system_extension import ( "bytes" "context" - "embed" "errors" "fmt" "strconv" @@ -218,27 +217,82 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -//go:embed "schemas/enum-extension.graphql" "schemas/input-object-extension.graphql" "schemas/interface-extension.graphql" "schemas/object-extension.graphql" "schemas/scalar-extension.graphql" "schemas/schema-extension.graphql" "schemas/schema.graphql" "schemas/type-extension.graphql" "schemas/union-extension.graphql" -var sourcesFS embed.FS +var sources = []*ast.Source{ + {Name: "../../../../../schemas/enum-extension.graphql", Input: `directive @enumLogging on ENUM -func sourceData(filename string) string { - data, err := sourcesFS.ReadFile(filename) - if err != nil { - panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) - } - return string(data) +extend enum State @enumLogging +`, BuiltIn: false}, + {Name: "../../../../../schemas/input-object-extension.graphql", Input: `directive @inputLogging on INPUT_OBJECT + +extend input TodoInput @inputLogging +`, BuiltIn: false}, + {Name: "../../../../../schemas/interface-extension.graphql", Input: `directive @interfaceLogging on INTERFACE + +extend interface Node @interfaceLogging +`, BuiltIn: false}, + {Name: "../../../../../schemas/object-extension.graphql", Input: `directive @objectLogging on OBJECT + +extend type Todo @objectLogging +`, BuiltIn: false}, + {Name: "../../../../../schemas/scalar-extension.graphql", Input: `directive @scalarLogging on SCALAR + +extend scalar ID @scalarLogging +`, BuiltIn: false}, + {Name: "../../../../../schemas/schema-extension.graphql", Input: `extend schema { + mutation: MyMutation } -var sources = []*ast.Source{ - {Name: "schemas/enum-extension.graphql", Input: sourceData("schemas/enum-extension.graphql"), BuiltIn: false}, - {Name: "schemas/input-object-extension.graphql", Input: sourceData("schemas/input-object-extension.graphql"), BuiltIn: false}, - {Name: "schemas/interface-extension.graphql", Input: sourceData("schemas/interface-extension.graphql"), BuiltIn: false}, - {Name: "schemas/object-extension.graphql", Input: sourceData("schemas/object-extension.graphql"), BuiltIn: false}, - {Name: "schemas/scalar-extension.graphql", Input: sourceData("schemas/scalar-extension.graphql"), BuiltIn: false}, - {Name: "schemas/schema-extension.graphql", Input: sourceData("schemas/schema-extension.graphql"), BuiltIn: false}, - {Name: "schemas/schema.graphql", Input: sourceData("schemas/schema.graphql"), BuiltIn: false}, - {Name: "schemas/type-extension.graphql", Input: sourceData("schemas/type-extension.graphql"), BuiltIn: false}, - {Name: "schemas/union-extension.graphql", Input: sourceData("schemas/union-extension.graphql"), BuiltIn: false}, +extend type MyQuery { + todo(id: ID!): Todo +} + +type MyMutation { + createTodo(todo: TodoInput!): Todo! +} + +input TodoInput { + text: String! +} +`, BuiltIn: false}, + {Name: "../../../../../schemas/schema.graphql", Input: `# GraphQL schema example +# +# https://gqlgen.com/getting-started/ + +schema { + query: MyQuery +} + +interface Node { + id: ID! +} + +type Todo implements Node { + id: ID! + text: String! + state: State! +} + +type MyQuery { + todos: [Todo!]! +} + +union Data = Todo + +enum State { + NOT_YET + DONE +} +`, BuiltIn: false}, + {Name: "../../../../../schemas/type-extension.graphql", Input: `directive @fieldLogging on FIELD_DEFINITION + +extend type Todo { + verified: Boolean! @fieldLogging +} +`, BuiltIn: false}, + {Name: "../../../../../schemas/union-extension.graphql", Input: `directive @unionLogging on UNION + +extend union Data @unionLogging +`, BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/codegen/data.go b/codegen/data.go index b757d21fcec..29918fb2a61 100644 --- a/codegen/data.go +++ b/codegen/data.go @@ -35,6 +35,16 @@ type Data struct { SubscriptionRoot *Object } +func (d *Data) HasEmbeddableSources() bool { + hasEmbeddableSources := false + for _, s := range d.AugmentedSources() { + if s.Embeddable { + hasEmbeddableSources = true + } + } + return hasEmbeddableSources +} + func (d *Data) AugmentedSources() []AugmentedSource { sources := []AugmentedSource{} for _, s := range d.Config.Sources { diff --git a/codegen/generated!.gotpl b/codegen/generated!.gotpl index bed873e842d..8ebf36968cb 100644 --- a/codegen/generated!.gotpl +++ b/codegen/generated!.gotpl @@ -236,6 +236,7 @@ return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } + {{if .HasEmbeddableSources }} //go:embed{{- range $source := .AugmentedSources }}{{if $source.Embeddable}} {{$source.RelativePath|quote}}{{end}}{{- end }} var sourcesFS embed.FS @@ -246,6 +247,7 @@ } return string(data) } + {{- end }} var sources = []*ast.Source{ {{- range $source := .AugmentedSources }} diff --git a/codegen/root_.gotpl b/codegen/root_.gotpl index 26603957692..fb4c6fe25cc 100644 --- a/codegen/root_.gotpl +++ b/codegen/root_.gotpl @@ -204,6 +204,7 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er } +{{if .HasEmbeddableSources }} //go:embed{{- range $source := .AugmentedSources }}{{if $source.Embeddable}} {{$source.RelativePath|quote}}{{end}}{{- end }} var sourcesFS embed.FS @@ -214,6 +215,7 @@ func sourceData(filename string) string { } return string(data) } +{{- end}} var sources = []*ast.Source{ {{- range $source := .AugmentedSources }} diff --git a/codegen/testserver/singlefile/generated.go b/codegen/testserver/singlefile/generated.go index 0b6cac1c076..311b72e29c8 100644 --- a/codegen/testserver/singlefile/generated.go +++ b/codegen/testserver/singlefile/generated.go @@ -5,7 +5,6 @@ package singlefile import ( "bytes" "context" - "embed" "errors" "fmt" "io" @@ -2150,17 +2149,6 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -//go:embed -var sourcesFS embed.FS - -func sourceData(filename string) string { - data, err := sourcesFS.ReadFile(filename) - if err != nil { - panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) - } - return string(data) -} - var sources = []*ast.Source{ {Name: "../../../../../../builtinscalar.graphql", Input: ` """ diff --git a/integration/generated.go b/integration/generated.go index f8269bfa552..bdaf8e82de5 100644 --- a/integration/generated.go +++ b/integration/generated.go @@ -5,7 +5,6 @@ package integration import ( "bytes" "context" - "embed" "errors" "fmt" "strconv" @@ -272,17 +271,6 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -//go:embed -var sourcesFS embed.FS - -func sourceData(filename string) string { - data, err := sourcesFS.ReadFile(filename) - if err != nil { - panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) - } - return string(data) -} - var sources = []*ast.Source{ {Name: "../../../../schema.graphql", Input: `"This directive does magical things" directive @magic(kind: Int) on FIELD_DEFINITION diff --git a/plugin/federation/testdata/entityresolver/generated/exec.go b/plugin/federation/testdata/entityresolver/generated/exec.go index 24a61598825..8fc2c88e1d1 100644 --- a/plugin/federation/testdata/entityresolver/generated/exec.go +++ b/plugin/federation/testdata/entityresolver/generated/exec.go @@ -5,7 +5,6 @@ package generated import ( "bytes" "context" - "embed" "errors" "fmt" "strconv" @@ -683,17 +682,6 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -//go:embed -var sourcesFS embed.FS - -func sourceData(filename string) string { - data, err := sourcesFS.ReadFile(filename) - if err != nil { - panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) - } - return string(data) -} - var sources = []*ast.Source{ {Name: "../../../../../../../../testdata/entityresolver/schema.graphql", Input: `directive @entityResolver(multi: Boolean) on OBJECT From 75c9e52650517ceeb4cee07a2ffe4c31675c8b56 Mon Sep 17 00:00:00 2001 From: Viktor Stanchev Date: Mon, 25 Apr 2022 01:52:37 +0000 Subject: [PATCH 5/8] fix dir --- _examples/chat/generated.go | 37 +- _examples/config/generated.go | 47 +- _examples/dataloader/generated.go | 42 +- .../accounts/graph/generated/generated.go | 6 +- .../products/graph/generated/generated.go | 6 +- .../reviews/graph/generated/generated.go | 6 +- _examples/fileupload/generated.go | 40 +- _examples/scalars/generated.go | 51 +- _examples/selection/generated.go | 34 +- _examples/starwars/generated/exec.go | 2 +- _examples/todo/generated.go | 50 +- _examples/type-system-extension/generated.go | 92 +-- codegen/data.go | 3 +- codegen/testserver/singlefile/generated.go | 677 +----------------- integration/generated.go | 72 +- .../testdata/entityresolver/generated/exec.go | 6 +- 16 files changed, 161 insertions(+), 1010 deletions(-) diff --git a/_examples/chat/generated.go b/_examples/chat/generated.go index 19c0efd1659..5c20ffe54af 100644 --- a/_examples/chat/generated.go +++ b/_examples/chat/generated.go @@ -5,6 +5,7 @@ package chat import ( "bytes" "context" + "embed" "errors" "fmt" "io" @@ -259,35 +260,19 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var sources = []*ast.Source{ - {Name: "../../../../../schema.graphql", Input: `type Chatroom { - name: String! - messages: [Message!]! -} - -type Message { - id: ID! - text: String! - createdBy: String! - createdAt: Time! -} - -type Query { - room(name:String!): Chatroom -} +//go:embed "schema.graphql" +var sourcesFS embed.FS -type Mutation { - post(text: String!, username: String!, roomName: String!): Message! -} - -type Subscription { - messageAdded(roomName: String!): Message! +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) } -scalar Time - -directive @user(username: String!) on SUBSCRIPTION -`, BuiltIn: false}, +var sources = []*ast.Source{ + {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/_examples/config/generated.go b/_examples/config/generated.go index 3d0e15e7cd6..95ccb91b5d3 100644 --- a/_examples/config/generated.go +++ b/_examples/config/generated.go @@ -5,6 +5,7 @@ package config import ( "bytes" "context" + "embed" "errors" "fmt" "strconv" @@ -250,43 +251,21 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var sources = []*ast.Source{ - {Name: "../../../../../schema.graphql", Input: `directive @goModel(model: String, models: [String!]) on OBJECT | INPUT_OBJECT | SCALAR | ENUM | INTERFACE | UNION -directive @goField(forceResolver: Boolean, name: String) on INPUT_FIELD_DEFINITION | FIELD_DEFINITION - -type Query { - todos: [Todo!]! -} - -type Mutation { - createTodo(input: NewTodo!): Todo! -} -`, BuiltIn: false}, - {Name: "../../../../../todo.graphql", Input: `type Todo { - id: ID! @goField(forceResolver: true) - databaseId: Int! - text: String! - done: Boolean! - user: User! -} +//go:embed "schema.graphql" "todo.graphql" "user.graphql" +var sourcesFS embed.FS -input NewTodo { - text: String! - userId: String! -} -`, BuiltIn: false}, - {Name: "../../../../../user.graphql", Input: `type User -@goModel(model:"github.com/99designs/gqlgen/_examples/config.User") { - id: ID! - name: String! @goField(name:"FullName") - role: role! +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) } -type role -@goModel(model:"github.com/99designs/gqlgen/_examples/config.UserRole") { - name: String! -} -`, BuiltIn: false}, +var sources = []*ast.Source{ + {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, + {Name: "todo.graphql", Input: sourceData("todo.graphql"), BuiltIn: false}, + {Name: "user.graphql", Input: sourceData("user.graphql"), BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/_examples/dataloader/generated.go b/_examples/dataloader/generated.go index 52883189121..92fa3f49603 100644 --- a/_examples/dataloader/generated.go +++ b/_examples/dataloader/generated.go @@ -5,6 +5,7 @@ package dataloader import ( "bytes" "context" + "embed" "errors" "fmt" "strconv" @@ -270,40 +271,19 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var sources = []*ast.Source{ - {Name: "../../../../../schema.graphql", Input: `type Query { - customers: [Customer!] - - # these methods are here to test code generation of nested arrays - torture1d(customerIds: [Int!]): [Customer!] - torture2d(customerIds: [[Int!]]): [[Customer!]] -} +//go:embed "schema.graphql" +var sourcesFS embed.FS -type Customer { - id: Int! - name: String! - address: Address - orders: [Order!] -} - -type Address { - id: Int! - street: String! - country: String! -} - -type Order { - id: Int! - date: Time! - amount: Float! - items: [Item!] +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) } -type Item { - name: String! -} -scalar Time -`, BuiltIn: false}, +var sources = []*ast.Source{ + {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/_examples/federation/accounts/graph/generated/generated.go b/_examples/federation/accounts/graph/generated/generated.go index c959e5b7f3f..ef06e1c44af 100644 --- a/_examples/federation/accounts/graph/generated/generated.go +++ b/_examples/federation/accounts/graph/generated/generated.go @@ -247,7 +247,7 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er } var sources = []*ast.Source{ - {Name: "../../../../../../../../graph/schema.graphqls", Input: `extend type Query { + {Name: "../schema.graphqls", Input: `extend type Query { me: User } @@ -263,7 +263,7 @@ type User @key(fields: "id") { username: String! } `, BuiltIn: false}, - {Name: "../../../../../../../../federation/directives.graphql", Input: ` + {Name: "../../federation/directives.graphql", Input: ` scalar _Any scalar _FieldSet @@ -274,7 +274,7 @@ type User @key(fields: "id") { directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE `, BuiltIn: true}, - {Name: "../../../../../../../../federation/entity.graphql", Input: ` + {Name: "../../federation/entity.graphql", Input: ` # a union of all types that use the @key directive union _Entity = EmailHost | User diff --git a/_examples/federation/products/graph/generated/generated.go b/_examples/federation/products/graph/generated/generated.go index 23d6c10f368..5f2577f2f66 100644 --- a/_examples/federation/products/graph/generated/generated.go +++ b/_examples/federation/products/graph/generated/generated.go @@ -274,7 +274,7 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er } var sources = []*ast.Source{ - {Name: "../../../../../../../../graph/schema.graphqls", Input: `extend type Query { + {Name: "../schema.graphqls", Input: `extend type Query { topProducts(first: Int = 5): [Product] } @@ -291,7 +291,7 @@ type Product @key(fields: "manufacturer { id } id") @key(fields: "upc") { price: Int! } `, BuiltIn: false}, - {Name: "../../../../../../../../federation/directives.graphql", Input: ` + {Name: "../../federation/directives.graphql", Input: ` scalar _Any scalar _FieldSet @@ -302,7 +302,7 @@ type Product @key(fields: "manufacturer { id } id") @key(fields: "upc") { directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE `, BuiltIn: true}, - {Name: "../../../../../../../../federation/entity.graphql", Input: ` + {Name: "../../federation/entity.graphql", Input: ` # a union of all types that use the @key directive union _Entity = Manufacturer | Product diff --git a/_examples/federation/reviews/graph/generated/generated.go b/_examples/federation/reviews/graph/generated/generated.go index ad8c6221aa3..271e4cd74b9 100644 --- a/_examples/federation/reviews/graph/generated/generated.go +++ b/_examples/federation/reviews/graph/generated/generated.go @@ -296,7 +296,7 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er } var sources = []*ast.Source{ - {Name: "../../../../../../../../graph/schema.graphqls", Input: `type Review { + {Name: "../schema.graphqls", Input: `type Review { body: String! author: User! @provides(fields: "username") product: Product! @@ -323,7 +323,7 @@ extend type Product @key(fields: " manufacturer{ id} id") { reviews: [Review] } `, BuiltIn: false}, - {Name: "../../../../../../../../federation/directives.graphql", Input: ` + {Name: "../../federation/directives.graphql", Input: ` scalar _Any scalar _FieldSet @@ -334,7 +334,7 @@ extend type Product @key(fields: " manufacturer{ id} id") { directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE `, BuiltIn: true}, - {Name: "../../../../../../../../federation/entity.graphql", Input: ` + {Name: "../../federation/entity.graphql", Input: ` # a union of all types that use the @key directive union _Entity = EmailHost | Manufacturer | Product | User diff --git a/_examples/fileupload/generated.go b/_examples/fileupload/generated.go index eaaf9d962b8..986aef9ea84 100644 --- a/_examples/fileupload/generated.go +++ b/_examples/fileupload/generated.go @@ -5,6 +5,7 @@ package fileupload import ( "bytes" "context" + "embed" "errors" "fmt" "strconv" @@ -239,38 +240,19 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var sources = []*ast.Source{ - {Name: "../../../../../schema.graphql", Input: `"The ` + "`" + `Upload` + "`" + ` scalar type represents a multipart file upload." -scalar Upload - -"The ` + "`" + `File` + "`" + ` type, represents the response of uploading a file." -type File { - id: Int! - name: String! - content: String! - contentType: String! -} - -"The ` + "`" + `UploadFile` + "`" + ` type, represents the request for uploading a file with certain payload." -input UploadFile { - id: Int! - file: Upload! -} +//go:embed "schema.graphql" +var sourcesFS embed.FS -"The ` + "`" + `Query` + "`" + ` type, represents all of the entry points into our object graph." -type Query { - empty: String! -} - -"The ` + "`" + `Mutation` + "`" + ` type, represents all updates we can make to our data." -type Mutation { - singleUpload(file: Upload!): File! - singleUploadWithPayload(req: UploadFile!): File! - multipleUpload(files: [Upload!]!): [File!]! - multipleUploadWithPayload(req: [UploadFile!]!): [File!]! +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) } -`, BuiltIn: false}, +var sources = []*ast.Source{ + {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/_examples/scalars/generated.go b/_examples/scalars/generated.go index bd238719eca..e2b69dd4747 100644 --- a/_examples/scalars/generated.go +++ b/_examples/scalars/generated.go @@ -5,6 +5,7 @@ package scalars import ( "bytes" "context" + "embed" "errors" "fmt" "strconv" @@ -277,49 +278,19 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var sources = []*ast.Source{ - {Name: "../../../../../schema.graphql", Input: `type Query { - user(id: ID!): User - search(input: SearchArgs = {location: "37,144", isBanned: false}): [User!]! - userByTier(tier: Tier!, darkMode: DarkMode!): [User!]! -} - -type User { - id: ID! - name: String! - created: Timestamp - modified: Timestamp - valPrefs: DarkMode - ptrPrefs: DarkMode - isBanned: Banned! - primitiveResolver: String! - customResolver: Point! - address: Address - tier: Tier -} - -type Address { - id: ID! - location: Point -} +//go:embed "schema.graphql" +var sourcesFS embed.FS -input SearchArgs { - location: Point - createdAfter: Timestamp - isBanned: Banned # TODO: This can be a Boolean again once multiple backing types are allowed -} - -enum Tier { - A - B - C +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) } -scalar Timestamp -scalar Point -scalar Banned -scalar DarkMode -`, BuiltIn: false}, +var sources = []*ast.Source{ + {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/_examples/selection/generated.go b/_examples/selection/generated.go index da3c03801dc..ee3a0f2f824 100644 --- a/_examples/selection/generated.go +++ b/_examples/selection/generated.go @@ -5,6 +5,7 @@ package selection import ( "bytes" "context" + "embed" "errors" "fmt" "strconv" @@ -194,32 +195,19 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var sources = []*ast.Source{ - {Name: "../../../../../schema.graphql", Input: `interface Event { - selection: [String!] - collected: [String!] -} +//go:embed "schema.graphql" +var sourcesFS embed.FS -type Post implements Event { - message: String! - sent: Time! - selection: [String!] - collected: [String!] -} - -type Like implements Event { - reaction: String! - sent: Time! - selection: [String!] - collected: [String!] -} - -type Query { - events: [Event!] +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) } -scalar Time -`, BuiltIn: false}, +var sources = []*ast.Source{ + {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/_examples/starwars/generated/exec.go b/_examples/starwars/generated/exec.go index c0f262023d9..b25c26077fb 100644 --- a/_examples/starwars/generated/exec.go +++ b/_examples/starwars/generated/exec.go @@ -555,7 +555,7 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er } var sources = []*ast.Source{ - {Name: "../../../../../../schema.graphql", Input: `# The query type, represents all of the entry points into our object graph + {Name: "../schema.graphql", Input: `# The query type, represents all of the entry points into our object graph type Query { hero(episode: Episode = NEWHOPE): Character reviews(episode: Episode!, since: Time): [Review!]! diff --git a/_examples/todo/generated.go b/_examples/todo/generated.go index 05e7a987f1c..2fd43e5cc10 100644 --- a/_examples/todo/generated.go +++ b/_examples/todo/generated.go @@ -5,6 +5,7 @@ package todo import ( "bytes" "context" + "embed" "errors" "fmt" "strconv" @@ -231,48 +232,19 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var sources = []*ast.Source{ - {Name: "../../../../../schema.graphql", Input: `schema { - query: MyQuery - mutation: MyMutation -} - -type MyQuery { - todo(id: ID!): Todo - lastTodo: Todo - todos: [Todo!]! -} - -type MyMutation { - createTodo(todo: TodoInput!): Todo! - updateTodo(id: ID!, changes: Map!): Todo -} - -type Todo { - id: ID! - text: String! - done: Boolean! @hasRole(role: OWNER) # only the owner can see if a todo is done -} +//go:embed "schema.graphql" +var sourcesFS embed.FS -"Passed to createTodo to create a new todo" -input TodoInput { - "The body text" - text: String! - "Is it done already?" - done: Boolean +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) } -scalar Map - -"Prevents access to a field if the user doesnt have the matching role" -directive @hasRole(role: Role!) on FIELD_DEFINITION -directive @user(id: ID!) on MUTATION | QUERY | FIELD - -enum Role { - ADMIN - OWNER -} -`, BuiltIn: false}, +var sources = []*ast.Source{ + {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/_examples/type-system-extension/generated.go b/_examples/type-system-extension/generated.go index 9b4edbc446e..a4d50d2e185 100644 --- a/_examples/type-system-extension/generated.go +++ b/_examples/type-system-extension/generated.go @@ -5,6 +5,7 @@ package type_system_extension import ( "bytes" "context" + "embed" "errors" "fmt" "strconv" @@ -217,82 +218,27 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var sources = []*ast.Source{ - {Name: "../../../../../schemas/enum-extension.graphql", Input: `directive @enumLogging on ENUM - -extend enum State @enumLogging -`, BuiltIn: false}, - {Name: "../../../../../schemas/input-object-extension.graphql", Input: `directive @inputLogging on INPUT_OBJECT - -extend input TodoInput @inputLogging -`, BuiltIn: false}, - {Name: "../../../../../schemas/interface-extension.graphql", Input: `directive @interfaceLogging on INTERFACE - -extend interface Node @interfaceLogging -`, BuiltIn: false}, - {Name: "../../../../../schemas/object-extension.graphql", Input: `directive @objectLogging on OBJECT - -extend type Todo @objectLogging -`, BuiltIn: false}, - {Name: "../../../../../schemas/scalar-extension.graphql", Input: `directive @scalarLogging on SCALAR - -extend scalar ID @scalarLogging -`, BuiltIn: false}, - {Name: "../../../../../schemas/schema-extension.graphql", Input: `extend schema { - mutation: MyMutation -} +//go:embed "schemas/enum-extension.graphql" "schemas/input-object-extension.graphql" "schemas/interface-extension.graphql" "schemas/object-extension.graphql" "schemas/scalar-extension.graphql" "schemas/schema-extension.graphql" "schemas/schema.graphql" "schemas/type-extension.graphql" "schemas/union-extension.graphql" +var sourcesFS embed.FS -extend type MyQuery { - todo(id: ID!): Todo -} - -type MyMutation { - createTodo(todo: TodoInput!): Todo! -} - -input TodoInput { - text: String! -} -`, BuiltIn: false}, - {Name: "../../../../../schemas/schema.graphql", Input: `# GraphQL schema example -# -# https://gqlgen.com/getting-started/ - -schema { - query: MyQuery -} - -interface Node { - id: ID! -} - -type Todo implements Node { - id: ID! - text: String! - state: State! -} - -type MyQuery { - todos: [Todo!]! -} - -union Data = Todo - -enum State { - NOT_YET - DONE -} -`, BuiltIn: false}, - {Name: "../../../../../schemas/type-extension.graphql", Input: `directive @fieldLogging on FIELD_DEFINITION - -extend type Todo { - verified: Boolean! @fieldLogging +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) } -`, BuiltIn: false}, - {Name: "../../../../../schemas/union-extension.graphql", Input: `directive @unionLogging on UNION -extend union Data @unionLogging -`, BuiltIn: false}, +var sources = []*ast.Source{ + {Name: "schemas/enum-extension.graphql", Input: sourceData("schemas/enum-extension.graphql"), BuiltIn: false}, + {Name: "schemas/input-object-extension.graphql", Input: sourceData("schemas/input-object-extension.graphql"), BuiltIn: false}, + {Name: "schemas/interface-extension.graphql", Input: sourceData("schemas/interface-extension.graphql"), BuiltIn: false}, + {Name: "schemas/object-extension.graphql", Input: sourceData("schemas/object-extension.graphql"), BuiltIn: false}, + {Name: "schemas/scalar-extension.graphql", Input: sourceData("schemas/scalar-extension.graphql"), BuiltIn: false}, + {Name: "schemas/schema-extension.graphql", Input: sourceData("schemas/schema-extension.graphql"), BuiltIn: false}, + {Name: "schemas/schema.graphql", Input: sourceData("schemas/schema.graphql"), BuiltIn: false}, + {Name: "schemas/type-extension.graphql", Input: sourceData("schemas/type-extension.graphql"), BuiltIn: false}, + {Name: "schemas/union-extension.graphql", Input: sourceData("schemas/union-extension.graphql"), BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/codegen/data.go b/codegen/data.go index 29918fb2a61..71ddb7186c5 100644 --- a/codegen/data.go +++ b/codegen/data.go @@ -53,8 +53,7 @@ func (d *Data) AugmentedSources() []AugmentedSource { if err != nil { panic(err) } - outputDir := filepath.Dir(d.Config.Exec.Filename) - outputDir = filepath.Join(wd, outputDir) + outputDir := d.Config.Exec.Dir() relative, err := filepath.Rel(outputDir, filepath.Join(wd, s.Name)) if err != nil { panic("TODO: handle" + err.Error() + " inputs:" + d.Config.Exec.Filename + " and " + filepath.Join(wd, s.Name)) diff --git a/codegen/testserver/singlefile/generated.go b/codegen/testserver/singlefile/generated.go index 311b72e29c8..469384111b9 100644 --- a/codegen/testserver/singlefile/generated.go +++ b/codegen/testserver/singlefile/generated.go @@ -5,6 +5,7 @@ package singlefile import ( "bytes" "context" + "embed" "errors" "fmt" "io" @@ -2149,649 +2150,45 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var sources = []*ast.Source{ - {Name: "../../../../../../builtinscalar.graphql", Input: ` -""" -Since gqlgen defines default implementation for a Map scalar, this tests that the builtin is _not_ -added to the TypeMap -""" -type Map { - id: ID! -} -`, BuiltIn: false}, - {Name: "../../../../../../complexity.graphql", Input: `extend type Query { - overlapping: OverlappingFields -} - -type OverlappingFields { - oneFoo: Int! @goField(name: "foo") - twoFoo: Int! @goField(name: "foo") - oldFoo: Int! @goField(name: "foo", forceResolver: true) - newFoo: Int! - new_foo: Int! -} -`, BuiltIn: false}, - {Name: "../../../../../../defaults.graphql", Input: `extend type Query { - defaultParameters( - falsyBoolean: Boolean = false - truthyBoolean: Boolean = true - ): DefaultParametersMirror! -} - -extend type Mutation { - defaultInput(input: DefaultInput!): DefaultParametersMirror! -} - -input DefaultInput { - falsyBoolean: Boolean = false - truthyBoolean: Boolean = true -} - -type DefaultParametersMirror { - falsyBoolean: Boolean - truthyBoolean: Boolean -} -`, BuiltIn: false}, - {Name: "../../../../../../directive.graphql", Input: `directive @length(min: Int!, max: Int, message: String) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | FIELD_DEFINITION -directive @range(min: Int = 0, max: Int) on ARGUMENT_DEFINITION -directive @custom on ARGUMENT_DEFINITION -directive @logged(id: UUID!) on FIELD -directive @toNull on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | FIELD_DEFINITION -directive @directive1 on FIELD_DEFINITION -directive @directive2 on FIELD_DEFINITION -directive @directive3 on INPUT_OBJECT -directive @unimplemented on FIELD_DEFINITION -directive @order1(location: String!) repeatable on FIELD_DEFINITION | OBJECT -directive @order2(location: String!) on OBJECT - -extend type Query { - directiveArg(arg: String! @length(min:1, max: 255, message: "invalid length")): String - directiveNullableArg(arg: Int @range(min:0), arg2: Int @range, arg3: String @toNull): String - directiveInputNullable(arg: InputDirectives): String - directiveInput(arg: InputDirectives!): String - directiveInputType(arg: InnerInput! @custom): String - directiveObject: ObjectDirectives @order1(location: "Query_field") - directiveObjectWithCustomGoModel: ObjectDirectivesWithCustomGoModel - directiveFieldDef(ret: String!): String! @length(min: 1, message: "not valid") - directiveField: String - directiveDouble: String @directive1 @directive2 - directiveUnimplemented: String @unimplemented -} - -extend type Subscription { - directiveArg(arg: String! @length(min:1, max: 255, message: "invalid length")): String - directiveNullableArg(arg: Int @range(min:0), arg2: Int @range, arg3: String @toNull): String - directiveDouble: String @directive1 @directive2 - directiveUnimplemented: String @unimplemented -} - -input InputDirectives @directive3 { - text: String! @length(min: 0, max: 7, message: "not valid") - nullableText: String @toNull - inner: InnerDirectives! - innerNullable: InnerDirectives - thirdParty: ThirdParty @length(min: 0, max: 7) -} - -input InnerDirectives { - message: String! @length(min: 1, message: "not valid") -} - -type ObjectDirectives @order1(location: "order1_1") @order1(location: "order1_2") @order2(location: "order2_1") { - text: String! @length(min: 0, max: 7, message: "not valid") - nullableText: String @toNull - order: [String!]! -} - -type ObjectDirectivesWithCustomGoModel { - nullableText: String @toNull -} -`, BuiltIn: false}, - {Name: "../../../../../../embedded.graphql", Input: `extend type Query { - embeddedCase1: EmbeddedCase1 - embeddedCase2: EmbeddedCase2 - embeddedCase3: EmbeddedCase3 -} - -type EmbeddedCase1 @goModel(model:"singlefile.EmbeddedCase1") { - exportedEmbeddedPointerExportedMethod: String! -} - -type EmbeddedCase2 @goModel(model:"singlefile.EmbeddedCase2") { - unexportedEmbeddedPointerExportedMethod: String! -} - -type EmbeddedCase3 @goModel(model:"singlefile.EmbeddedCase3") { - unexportedEmbeddedInterfaceExportedMethod: String! -} -`, BuiltIn: false}, - {Name: "../../../../../../enum.graphql", Input: `enum EnumTest { - OK - NG -} - -input InputWithEnumValue { - enum: EnumTest! -} - -extend type Query { - enumInInput(input: InputWithEnumValue): EnumTest! -} -`, BuiltIn: false}, - {Name: "../../../../../../interfaces.graphql", Input: `extend type Query { - shapes: [Shape] - noShape: Shape @makeNil - node: Node! - noShapeTypedNil: Shape @makeTypedNil - animal: Animal @makeTypedNil - notAnInterface: BackedByInterface -} - -interface Animal { - species: String! -} - -type BackedByInterface { - id: String! - thisShouldBind: String! - thisShouldBindWithError: String! -} - -type Dog implements Animal { - species: String! - dogBreed: String! -} - -type Cat implements Animal { - species: String! - catBreed: String! -} - -type Coordinates { - x: Float! - y: Float! -} -interface Shape { - area: Float - coordinates: Coordinates -} - -type Circle implements Shape { - radius: Float - area: Float - coordinates: Coordinates -} -type Rectangle implements Shape { - length: Float - width: Float - area: Float - coordinates: Coordinates -} -union ShapeUnion @goModel(model: "singlefile.ShapeUnion") = Circle | Rectangle - -directive @makeNil on FIELD_DEFINITION -directive @makeTypedNil on FIELD_DEFINITION - -interface Node { - id: ID! - child: Node! -} - -type ConcreteNodeA implements Node { - id: ID! - child: Node! - name: String! -} - -" Implements the Node interface with another interface " -type ConcreteNodeInterface implements Node { - id: ID! - child: Node! -} -`, BuiltIn: false}, - {Name: "../../../../../../issue896.graphql", Input: `# This example should build stable output. If the file content starts -# alternating nondeterministically between two outputs, then see -# https://github.com/99designs/gqlgen/issues/896. - -extend schema { - query: Query - subscription: Subscription -} - -type CheckIssue896 {id: Int} - -extend type Query { - issue896a: [CheckIssue896!] # Note the "!" or lack thereof. -} - -extend type Subscription { - issue896b: [CheckIssue896] # Note the "!" or lack thereof. -} -`, BuiltIn: false}, - {Name: "../../../../../../loops.graphql", Input: `type LoopA { - b: LoopB! -} - -type LoopB { - a: LoopA! -} -`, BuiltIn: false}, - {Name: "../../../../../../maps.graphql", Input: `extend type Query { - mapStringInterface(in: MapStringInterfaceInput): MapStringInterfaceType - mapNestedStringInterface(in: NestedMapInput): MapStringInterfaceType -} - -type MapStringInterfaceType @goModel(model: "map[string]interface{}") { - a: String - b: Int -} - -input MapStringInterfaceInput @goModel(model: "map[string]interface{}") { - a: String - b: Int -} - -input NestedMapInput { - map: MapStringInterfaceInput -} -`, BuiltIn: false}, - {Name: "../../../../../../mutation_with_custom_scalar.graphql", Input: `extend type Mutation { - updateSomething(input: SpecialInput!): String! -} - -scalar Email - -input SpecialInput { - nesting: NestedInput! -} - -input NestedInput { - field: Email! -} -`, BuiltIn: false}, - {Name: "../../../../../../nulls.graphql", Input: `extend type Query { - errorBubble: Error - errorBubbleList: [Error!] - errorList: [Error] - errors: Errors - valid: String! -} - -extend type Subscription { - errorRequired: Error! -} - -type Errors { - a: Error! - b: Error! - c: Error! - d: Error! - e: Error! -} - -type Error { - id: ID! - errorOnNonRequiredField: String - errorOnRequiredField: String! - nilOnRequiredField: String! -} -`, BuiltIn: false}, - {Name: "../../../../../../panics.graphql", Input: `extend type Query { - panics: Panics -} - -type Panics { - fieldScalarMarshal: [MarshalPanic!]! - fieldFuncMarshal(u: [MarshalPanic!]!): [MarshalPanic!]! - argUnmarshal(u: [MarshalPanic!]!): Boolean! - -} - -scalar MarshalPanic -`, BuiltIn: false}, - {Name: "../../../../../../primitive_objects.graphql", Input: `extend type Query { - primitiveObject: [Primitive!]! - primitiveStringObject: [PrimitiveString!]! -} - -type Primitive { - value: Int! - squared: Int! -} - -type PrimitiveString { - value: String! - doubled: String! - len: Int! -} -`, BuiltIn: false}, - {Name: "../../../../../../ptr_to_ptr_input.graphql", Input: `type PtrToPtrOuter { - name: String! - inner: PtrToPtrInner - stupidInner: PtrToPtrInner -} - -type PtrToPtrInner { - key: String! - value: String! -} - -input UpdatePtrToPtrOuter { - name: String - inner: UpdatePtrToPtrInner - stupidInner: UpdatePtrToPtrInner -} - -input UpdatePtrToPtrInner { - key: String - value: String -} - -extend type Mutation { - updatePtrToPtr(input: UpdatePtrToPtrOuter!): PtrToPtrOuter! -} -`, BuiltIn: false}, - {Name: "../../../../../../ptr_to_slice.graphql", Input: `type PtrToSliceContainer { - ptrToSlice: [String!] -} - -extend type Query { - ptrToSliceContainer: PtrToSliceContainer! -} -`, BuiltIn: false}, - {Name: "../../../../../../scalar_context.graphql", Input: `extend type Query { - infinity: Float! - stringFromContextInterface: StringFromContextInterface! - stringFromContextFunction: StringFromContextFunction! -} - -scalar StringFromContextInterface -scalar StringFromContextFunction -`, BuiltIn: false}, - {Name: "../../../../../../scalar_default.graphql", Input: `extend type Query { - defaultScalar(arg: DefaultScalarImplementation! = "default"): DefaultScalarImplementation! -} - -""" This doesnt have an implementation in the typemap, so it should act like a string """ -scalar DefaultScalarImplementation - -type EmbeddedDefaultScalar { - value: DefaultScalarImplementation -} -`, BuiltIn: false}, - {Name: "../../../../../../schema.graphql", Input: `directive @goModel( - model: String - models: [String!] -) on OBJECT | INPUT_OBJECT | SCALAR | ENUM | INTERFACE | UNION -directive @goField( - forceResolver: Boolean - name: String -) on INPUT_FIELD_DEFINITION | FIELD_DEFINITION - -type Query { - invalidIdentifier: InvalidIdentifier - collision: It - mapInput(input: Changes): Boolean - recursive(input: RecursiveInputSlice): Boolean - nestedInputs(input: [[OuterInput]] = [[{ inner: { id: 1 } }]]): Boolean - nestedOutputs: [[OuterObject]] - modelMethods: ModelMethods - user(id: Int!): User! - nullableArg(arg: Int = 123): String - inputSlice(arg: [String!]!): Boolean! - inputNullableSlice(arg: [String!]): Boolean! - shapeUnion: ShapeUnion! - autobind: Autobind - deprecatedField: String! @deprecated(reason: "test deprecated directive") -} - -type Subscription { - updated: String! - initPayload: String! -} - -type Pet { - id: Int! - friends(limit: Int): [Pet!] @goField(forceResolver: true) -} - -type User { - id: Int! - friends: [User!]! @goField(forceResolver: true) - created: Time! - updated: Time - pets(limit: Int): [Pet!] @goField(forceResolver: true) -} - -type Autobind { - int: Int! - int32: Int! - int64: Int! - - idStr: ID! - idInt: ID! -} - -type ModelMethods { - resolverField: Boolean! - noContext: Boolean! - withContext: Boolean! -} - -type InvalidIdentifier { - id: Int! -} +//go:embed "builtinscalar.graphql" "complexity.graphql" "defaults.graphql" "directive.graphql" "embedded.graphql" "enum.graphql" "interfaces.graphql" "issue896.graphql" "loops.graphql" "maps.graphql" "mutation_with_custom_scalar.graphql" "nulls.graphql" "panics.graphql" "primitive_objects.graphql" "ptr_to_ptr_input.graphql" "ptr_to_slice.graphql" "scalar_context.graphql" "scalar_default.graphql" "schema.graphql" "slices.graphql" "typefallback.graphql" "useptr.graphql" "v-ok.graphql" "validtypes.graphql" "variadic.graphql" "weird_type_cases.graphql" "wrapped_type.graphql" +var sourcesFS embed.FS -type It { - id: ID! -} - -input Changes @goModel(model: "map[string]interface{}") { - a: Int - b: Int -} - -input RecursiveInputSlice { - self: [RecursiveInputSlice!] -} - -input InnerInput { - id: Int! -} - -input OuterInput { - inner: InnerInput! -} - -scalar ThirdParty @goModel(model:"singlefile.ThirdParty") - -type OuterObject { - inner: InnerObject! -} - -type InnerObject { - id: Int! -} - -type ForcedResolver { - field: Circle @goField(forceResolver: true) -} - -type EmbeddedPointer @goModel(model:"singlefile.EmbeddedPointerModel") { - ID: String - Title: String -} - -scalar UUID - -enum Status { - OK - ERROR -} - -scalar Time -`, BuiltIn: false}, - {Name: "../../../../../../slices.graphql", Input: `extend type Query { - slices: Slices - scalarSlice: Bytes! -} - -type Slices { - test1: [String] - test2: [String!] - test3: [String]! - test4: [String!]! -} - -scalar Bytes -`, BuiltIn: false}, - {Name: "../../../../../../typefallback.graphql", Input: `extend type Query { - fallback(arg: FallbackToStringEncoding!): FallbackToStringEncoding! -} - -enum FallbackToStringEncoding { - A - B - C -} -`, BuiltIn: false}, - {Name: "../../../../../../useptr.graphql", Input: `type A { - id: ID! -} - -type B { - id: ID! -} - -union TestUnion = A | B - -extend type Query { - optionalUnion: TestUnion -} -`, BuiltIn: false}, - {Name: "../../../../../../v-ok.graphql", Input: `extend type Query { - vOkCaseValue: VOkCaseValue - vOkCaseNil: VOkCaseNil -} - -type VOkCaseValue @goModel(model:"singlefile.VOkCaseValue") { - value: String -} - -type VOkCaseNil @goModel(model:"singlefile.VOkCaseNil") { - value: String -} -`, BuiltIn: false}, - {Name: "../../../../../../validtypes.graphql", Input: `extend type Query { - validType: ValidType +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) } -""" These things are all valid, but without care generate invalid go code """ -type ValidType { - differentCase: String! - different_case: String! @goField(name:"DifferentCaseOld") - validInputKeywords(input: ValidInput): Boolean! - validArgs( - break: String!, - default: String!, - func: String!, - interface: String!, - select: String!, - case: String!, - defer: String!, - go: String!, - map: String!, - struct: String!, - chan: String!, - else: String!, - goto: String!, - package: String!, - switch: String!, - const: String!, - fallthrough: String!, - if: String!, - range: String!, - type: String!, - continue: String!, - for: String!, - import: String!, - return: String!, - var: String!, - _: String!, - ): Boolean! -} - -input ValidInput { - break: String! - default: String! - func: String! - interface: String! - select: String! - case: String! - defer: String! - go: String! - map: String! - struct: String! - chan: String! - else: String! - goto: String! - package: String! - switch: String! - const: String! - fallthrough: String! - if: String! - range: String! - type: String! - continue: String! - for: String! - import: String! - return: String! - var: String! - _: String! @goField(name: "Underscore") -} - -# see https://github.com/99designs/gqlgen/issues/694 -type Content_User { - foo: String -} - -type Content_Post { - foo: String -} - -union Content_Child = Content_User | Content_Post -`, BuiltIn: false}, - {Name: "../../../../../../variadic.graphql", Input: `extend type Query { - variadicModel: VariadicModel -} - -type VariadicModel { - value(rank: Int!): String -} -`, BuiltIn: false}, - {Name: "../../../../../../weird_type_cases.graphql", Input: `# regression test for https://github.com/99designs/gqlgen/issues/583 - -type asdfIt { id: ID! } -type iIt { id: ID! } -type AIt { id: ID! } -type XXIt { id: ID! } -type AbIt { id: ID! } -type XxIt { id: ID! } -`, BuiltIn: false}, - {Name: "../../../../../../wrapped_type.graphql", Input: `# regression test for https://github.com/99designs/gqlgen/issues/721 - -extend type Query { - wrappedStruct: WrappedStruct! - wrappedScalar: WrappedScalar! - wrappedMap: WrappedMap! - wrappedSlice: WrappedSlice! -} - -type WrappedStruct { name: WrappedScalar!, desc: WrappedScalar } -scalar WrappedScalar -type WrappedMap { get(key: String!): String! } -type WrappedSlice { get(idx: Int!): String! } -`, BuiltIn: false}, +var sources = []*ast.Source{ + {Name: "builtinscalar.graphql", Input: sourceData("builtinscalar.graphql"), BuiltIn: false}, + {Name: "complexity.graphql", Input: sourceData("complexity.graphql"), BuiltIn: false}, + {Name: "defaults.graphql", Input: sourceData("defaults.graphql"), BuiltIn: false}, + {Name: "directive.graphql", Input: sourceData("directive.graphql"), BuiltIn: false}, + {Name: "embedded.graphql", Input: sourceData("embedded.graphql"), BuiltIn: false}, + {Name: "enum.graphql", Input: sourceData("enum.graphql"), BuiltIn: false}, + {Name: "interfaces.graphql", Input: sourceData("interfaces.graphql"), BuiltIn: false}, + {Name: "issue896.graphql", Input: sourceData("issue896.graphql"), BuiltIn: false}, + {Name: "loops.graphql", Input: sourceData("loops.graphql"), BuiltIn: false}, + {Name: "maps.graphql", Input: sourceData("maps.graphql"), BuiltIn: false}, + {Name: "mutation_with_custom_scalar.graphql", Input: sourceData("mutation_with_custom_scalar.graphql"), BuiltIn: false}, + {Name: "nulls.graphql", Input: sourceData("nulls.graphql"), BuiltIn: false}, + {Name: "panics.graphql", Input: sourceData("panics.graphql"), BuiltIn: false}, + {Name: "primitive_objects.graphql", Input: sourceData("primitive_objects.graphql"), BuiltIn: false}, + {Name: "ptr_to_ptr_input.graphql", Input: sourceData("ptr_to_ptr_input.graphql"), BuiltIn: false}, + {Name: "ptr_to_slice.graphql", Input: sourceData("ptr_to_slice.graphql"), BuiltIn: false}, + {Name: "scalar_context.graphql", Input: sourceData("scalar_context.graphql"), BuiltIn: false}, + {Name: "scalar_default.graphql", Input: sourceData("scalar_default.graphql"), BuiltIn: false}, + {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, + {Name: "slices.graphql", Input: sourceData("slices.graphql"), BuiltIn: false}, + {Name: "typefallback.graphql", Input: sourceData("typefallback.graphql"), BuiltIn: false}, + {Name: "useptr.graphql", Input: sourceData("useptr.graphql"), BuiltIn: false}, + {Name: "v-ok.graphql", Input: sourceData("v-ok.graphql"), BuiltIn: false}, + {Name: "validtypes.graphql", Input: sourceData("validtypes.graphql"), BuiltIn: false}, + {Name: "variadic.graphql", Input: sourceData("variadic.graphql"), BuiltIn: false}, + {Name: "weird_type_cases.graphql", Input: sourceData("weird_type_cases.graphql"), BuiltIn: false}, + {Name: "wrapped_type.graphql", Input: sourceData("wrapped_type.graphql"), BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/integration/generated.go b/integration/generated.go index bdaf8e82de5..78bdab91424 100644 --- a/integration/generated.go +++ b/integration/generated.go @@ -5,6 +5,7 @@ package integration import ( "bytes" "context" + "embed" "errors" "fmt" "strconv" @@ -271,69 +272,20 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var sources = []*ast.Source{ - {Name: "../../../../schema.graphql", Input: `"This directive does magical things" -directive @magic(kind: Int) on FIELD_DEFINITION - -scalar Map - -type Element { - child: Element! - error: Boolean! - mismatched: [Boolean!] -} - -enum DATE_FILTER_OP { - # multi - # line - # comment - EQ - NEQ - GT - GTE - LT - LTE -} - -input DateFilter { - value: String! - timezone: String = "UTC" - op: DATE_FILTER_OP = EQ -} - -type Viewer { - user: User -} - -input ListCoercion { - enumVal: [ErrorType] - strVal: [String] - intVal: [Int] - scalarVal: [Map] -} - -type Query { - path: [Element] - date(filter: DateFilter!): Boolean! - viewer: Viewer - jsonEncoding: String! - error(type: ErrorType = NORMAL): Boolean! - complexity(value: Int!): Boolean! - coercion(value: [ListCoercion!]): Boolean! -} +//go:embed "schema.graphql" "user.graphql" +var sourcesFS embed.FS -enum ErrorType { - CUSTOM - NORMAL +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) } -# this is a comment with a ` + "`" + `backtick` + "`" + ` -`, BuiltIn: false}, - {Name: "../../../../user.graphql", Input: `type User { - name: String! - likes: [String!]! -} -`, BuiltIn: false}, +var sources = []*ast.Source{ + {Name: "schema.graphql", Input: sourceData("schema.graphql"), BuiltIn: false}, + {Name: "user.graphql", Input: sourceData("user.graphql"), BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/plugin/federation/testdata/entityresolver/generated/exec.go b/plugin/federation/testdata/entityresolver/generated/exec.go index 8fc2c88e1d1..5741f6a2f70 100644 --- a/plugin/federation/testdata/entityresolver/generated/exec.go +++ b/plugin/federation/testdata/entityresolver/generated/exec.go @@ -683,7 +683,7 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er } var sources = []*ast.Source{ - {Name: "../../../../../../../../testdata/entityresolver/schema.graphql", Input: `directive @entityResolver(multi: Boolean) on OBJECT + {Name: "../schema.graphql", Input: `directive @entityResolver(multi: Boolean) on OBJECT type Hello @key(fields: "name") { name: String! @@ -761,7 +761,7 @@ type MultiHelloMultipleRequires @key(fields: "name") @entityResolver(multi: true key3: String! @requires(fields: "key1 key2") } `, BuiltIn: false}, - {Name: "../../../../../../../../federation/directives.graphql", Input: ` + {Name: "../../../federation/directives.graphql", Input: ` scalar _Any scalar _FieldSet @@ -772,7 +772,7 @@ type MultiHelloMultipleRequires @key(fields: "name") @entityResolver(multi: true directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE `, BuiltIn: true}, - {Name: "../../../../../../../../federation/entity.graphql", Input: ` + {Name: "../../../federation/entity.graphql", Input: ` # a union of all types that use the @key directive union _Entity = Hello | HelloMultiSingleKeys | HelloWithErrors | MultiHello | MultiHelloMultipleRequires | MultiHelloRequires | MultiHelloWithError | MultiPlanetRequiresNested | PlanetMultipleRequires | PlanetRequires | PlanetRequiresNested | World | WorldName | WorldWithMultipleKeys From 1a1f5ed9a08222e89a9fd8f95d05730b5bdca1d3 Mon Sep 17 00:00:00 2001 From: Viktor Stanchev Date: Mon, 25 Apr 2022 01:56:55 +0000 Subject: [PATCH 6/8] comment --- codegen/data.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen/data.go b/codegen/data.go index 71ddb7186c5..afcd1320262 100644 --- a/codegen/data.go +++ b/codegen/data.go @@ -66,7 +66,7 @@ func (d *Data) AugmentedSources() []AugmentedSource { RelativePath: relative, Embeddable: embeddable, BuiltIn: s.BuiltIn, - Source: s.Input, // TODO: remove this + Source: s.Input, }) } return sources From ec5c46336cb3e04baae599f22f5fadce2438d491 Mon Sep 17 00:00:00 2001 From: Viktor Stanchev Date: Sun, 1 May 2022 18:30:33 +0000 Subject: [PATCH 7/8] add test for embedding --- _examples/embedding/parent.graphqls | 3 + .../subdir/cfgdir/generate_in_gendir.yml | 12 + .../subdir/cfgdir/generate_in_subdir.yml | 12 + _examples/embedding/subdir/embedding_test.go | 48 + .../embedding/subdir/gendir/generated.go | 3216 +++++++++++++++++ .../embedding/subdir/prelude.generated.go | 2687 ++++++++++++++ _examples/embedding/subdir/resolvers.go | 31 + _examples/embedding/subdir/root.generated.go | 440 +++ _examples/embedding/subdir/root_.generated.go | 154 + .../embedding/subdir/schemadir/root.graphqls | 3 + _examples/embedding/subdir/subdir.graphqls | 3 + 11 files changed, 6609 insertions(+) create mode 100644 _examples/embedding/parent.graphqls create mode 100644 _examples/embedding/subdir/cfgdir/generate_in_gendir.yml create mode 100644 _examples/embedding/subdir/cfgdir/generate_in_subdir.yml create mode 100644 _examples/embedding/subdir/embedding_test.go create mode 100644 _examples/embedding/subdir/gendir/generated.go create mode 100644 _examples/embedding/subdir/prelude.generated.go create mode 100644 _examples/embedding/subdir/resolvers.go create mode 100644 _examples/embedding/subdir/root.generated.go create mode 100644 _examples/embedding/subdir/root_.generated.go create mode 100644 _examples/embedding/subdir/schemadir/root.graphqls create mode 100644 _examples/embedding/subdir/subdir.graphqls diff --git a/_examples/embedding/parent.graphqls b/_examples/embedding/parent.graphqls new file mode 100644 index 00000000000..70ee33e4a13 --- /dev/null +++ b/_examples/embedding/parent.graphqls @@ -0,0 +1,3 @@ +extend type Query { + parentdir: String! +} diff --git a/_examples/embedding/subdir/cfgdir/generate_in_gendir.yml b/_examples/embedding/subdir/cfgdir/generate_in_gendir.yml new file mode 100644 index 00000000000..f7c77131060 --- /dev/null +++ b/_examples/embedding/subdir/cfgdir/generate_in_gendir.yml @@ -0,0 +1,12 @@ +schema: + - schemadir/*.graphqls + - ../*.graphqls + - '*.graphqls' +exec: + dir: gendir + filename: gendir/generated.go + package: gendir + +model: + filename: gendir/model.go + package: gendir \ No newline at end of file diff --git a/_examples/embedding/subdir/cfgdir/generate_in_subdir.yml b/_examples/embedding/subdir/cfgdir/generate_in_subdir.yml new file mode 100644 index 00000000000..cca0072e0a0 --- /dev/null +++ b/_examples/embedding/subdir/cfgdir/generate_in_subdir.yml @@ -0,0 +1,12 @@ +schema: + - schemadir/*.graphqls + - ../*.graphqls + - '*.graphqls' +exec: + layout: follow-schema + dir: . + package: subdir + +model: + filename: model.go + package: subdir \ No newline at end of file diff --git a/_examples/embedding/subdir/embedding_test.go b/_examples/embedding/subdir/embedding_test.go new file mode 100644 index 00000000000..d7794552366 --- /dev/null +++ b/_examples/embedding/subdir/embedding_test.go @@ -0,0 +1,48 @@ +package subdir + +import ( + "testing" + + "github.com/99designs/gqlgen/_examples/embedding/subdir/gendir" + "github.com/99designs/gqlgen/client" + "github.com/99designs/gqlgen/graphql/handler" + "github.com/stretchr/testify/require" +) + +func TestEmbeddingWorks(t *testing.T) { + c := client.New(handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: &Resolver{}}))) + var resp struct { + InSchemadir string + Parentdir string + Subdir string + } + c.MustPost(`{ + inSchemadir + parentdir + subdir + } + `, &resp) + + require.Equal(t, "example", resp.InSchemadir) + require.Equal(t, "example", resp.Parentdir) + require.Equal(t, "example", resp.Subdir) +} + +func TestEmbeddingWorksInGendir(t *testing.T) { + c := client.New(handler.NewDefaultServer(gendir.NewExecutableSchema(gendir.Config{Resolvers: &GendirResolver{}}))) + var resp struct { + InSchemadir string + Parentdir string + Subdir string + } + c.MustPost(`{ + inSchemadir + parentdir + subdir + } + `, &resp) + + require.Equal(t, "example", resp.InSchemadir) + require.Equal(t, "example", resp.Parentdir) + require.Equal(t, "example", resp.Subdir) +} diff --git a/_examples/embedding/subdir/gendir/generated.go b/_examples/embedding/subdir/gendir/generated.go new file mode 100644 index 00000000000..e90caa59466 --- /dev/null +++ b/_examples/embedding/subdir/gendir/generated.go @@ -0,0 +1,3216 @@ +// Code generated by github.com/99designs/gqlgen, DO NOT EDIT. + +package gendir + +import ( + "bytes" + "context" + "errors" + "fmt" + "strconv" + "sync" + "sync/atomic" + + "github.com/99designs/gqlgen/graphql" + "github.com/99designs/gqlgen/graphql/introspection" + gqlparser "github.com/vektah/gqlparser/v2" + "github.com/vektah/gqlparser/v2/ast" +) + +// region ************************** generated!.gotpl ************************** + +// NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface. +func NewExecutableSchema(cfg Config) graphql.ExecutableSchema { + return &executableSchema{ + resolvers: cfg.Resolvers, + directives: cfg.Directives, + complexity: cfg.Complexity, + } +} + +type Config struct { + Resolvers ResolverRoot + Directives DirectiveRoot + Complexity ComplexityRoot +} + +type ResolverRoot interface { + Query() QueryResolver +} + +type DirectiveRoot struct { +} + +type ComplexityRoot struct { + Query struct { + InSchemadir func(childComplexity int) int + Parentdir func(childComplexity int) int + Subdir func(childComplexity int) int + } +} + +type QueryResolver interface { + InSchemadir(ctx context.Context) (string, error) + Parentdir(ctx context.Context) (string, error) + Subdir(ctx context.Context) (string, error) +} + +type executableSchema struct { + resolvers ResolverRoot + directives DirectiveRoot + complexity ComplexityRoot +} + +func (e *executableSchema) Schema() *ast.Schema { + return parsedSchema +} + +func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) { + ec := executionContext{nil, e} + _ = ec + switch typeName + "." + field { + + case "Query.inSchemadir": + if e.complexity.Query.InSchemadir == nil { + break + } + + return e.complexity.Query.InSchemadir(childComplexity), true + + case "Query.parentdir": + if e.complexity.Query.Parentdir == nil { + break + } + + return e.complexity.Query.Parentdir(childComplexity), true + + case "Query.subdir": + if e.complexity.Query.Subdir == nil { + break + } + + return e.complexity.Query.Subdir(childComplexity), true + + } + return 0, false +} + +func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { + rc := graphql.GetOperationContext(ctx) + ec := executionContext{rc, e} + inputUnmarshalMap := graphql.BuildUnmarshalerMap() + first := true + + switch rc.Operation.Operation { + case ast.Query: + return func(ctx context.Context) *graphql.Response { + if !first { + return nil + } + first = false + ctx = graphql.WithUnmarshalerMap(ctx, inputUnmarshalMap) + data := ec._Query(ctx, rc.Operation.SelectionSet) + var buf bytes.Buffer + data.MarshalGQL(&buf) + + return &graphql.Response{ + Data: buf.Bytes(), + } + } + + default: + return graphql.OneShot(graphql.ErrorResponse(ctx, "unsupported GraphQL operation")) + } +} + +type executionContext struct { + *graphql.OperationContext + *executableSchema +} + +func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") + } + return introspection.WrapSchema(parsedSchema), nil +} + +func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") + } + return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil +} + +var sources = []*ast.Source{ + {Name: "../schemadir/root.graphqls", Input: `type Query { + inSchemadir: String! +} +`, BuiltIn: false}, + {Name: "../../parent.graphqls", Input: `extend type Query { + parentdir: String! +} +`, BuiltIn: false}, + {Name: "../subdir.graphqls", Input: `extend type Query { + subdir: String! +} +`, BuiltIn: false}, +} +var parsedSchema = gqlparser.MustLoadSchema(sources...) + +// endregion ************************** generated!.gotpl ************************** + +// region ***************************** args.gotpl ***************************** + +func (ec *executionContext) field_Query___type_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["name"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["name"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil +} + +// endregion ***************************** args.gotpl ***************************** + +// region ************************** directives.gotpl ************************** + +// endregion ************************** directives.gotpl ************************** + +// region **************************** field.gotpl ***************************** + +func (ec *executionContext) _Query_inSchemadir(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_inSchemadir(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().InSchemadir(rctx) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_inSchemadir(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Query_parentdir(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_parentdir(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Parentdir(rctx) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_parentdir(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Query_subdir(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_subdir(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Subdir(rctx) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_subdir(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query___type(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.introspectType(fc.Args["name"].(string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query___type(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query___type_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query___schema(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.introspectSchema() + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Schema) + fc.Result = res + return ec.marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query___schema(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "description": + return ec.fieldContext___Schema_description(ctx, field) + case "types": + return ec.fieldContext___Schema_types(ctx, field) + case "queryType": + return ec.fieldContext___Schema_queryType(ctx, field) + case "mutationType": + return ec.fieldContext___Schema_mutationType(ctx, field) + case "subscriptionType": + return ec.fieldContext___Schema_subscriptionType(ctx, field) + case "directives": + return ec.fieldContext___Schema_directives(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Schema", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Directive_name(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Directive_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Directive", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Directive_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Directive_description(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Directive", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Directive_locations(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Locations, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]string) + fc.Result = res + return ec.marshalN__DirectiveLocation2ᚕstringᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Directive_locations(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Directive", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type __DirectiveLocation does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Directive_args(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Args, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]introspection.InputValue) + fc.Result = res + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Directive_args(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Directive", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___InputValue_name(ctx, field) + case "description": + return ec.fieldContext___InputValue_description(ctx, field) + case "type": + return ec.fieldContext___InputValue_type(ctx, field) + case "defaultValue": + return ec.fieldContext___InputValue_defaultValue(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __InputValue", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Directive_isRepeatable(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Directive_isRepeatable(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsRepeatable, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Directive_isRepeatable(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Directive", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___EnumValue_name(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___EnumValue_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__EnumValue", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___EnumValue_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___EnumValue_description(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__EnumValue", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___EnumValue_isDeprecated(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsDeprecated(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__EnumValue", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___EnumValue_deprecationReason(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.DeprecationReason(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__EnumValue", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_name(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_description(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_args(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Args, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]introspection.InputValue) + fc.Result = res + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_args(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___InputValue_name(ctx, field) + case "description": + return ec.fieldContext___InputValue_description(ctx, field) + case "type": + return ec.fieldContext___InputValue_type(ctx, field) + case "defaultValue": + return ec.fieldContext___InputValue_defaultValue(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __InputValue", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_type(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Type, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_type(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_isDeprecated(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsDeprecated(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_isDeprecated(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_deprecationReason(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.DeprecationReason(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_deprecationReason(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___InputValue_name(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___InputValue_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__InputValue", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___InputValue_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___InputValue_description(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__InputValue", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___InputValue_type(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Type, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___InputValue_type(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__InputValue", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___InputValue_defaultValue(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.DefaultValue, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__InputValue", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Schema_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_description(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_types(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Types(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]introspection.Type) + fc.Result = res + return ec.marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_types(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_queryType(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.QueryType(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_queryType(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_mutationType(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.MutationType(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_mutationType(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_subscriptionType(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.SubscriptionType(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_directives(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Directives(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]introspection.Directive) + fc.Result = res + return ec.marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirectiveᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_directives(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___Directive_name(ctx, field) + case "description": + return ec.fieldContext___Directive_description(ctx, field) + case "locations": + return ec.fieldContext___Directive_locations(ctx, field) + case "args": + return ec.fieldContext___Directive_args(ctx, field) + case "isRepeatable": + return ec.fieldContext___Directive_isRepeatable(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Directive", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_kind(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Kind(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalN__TypeKind2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_kind(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type __TypeKind does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_name(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_description(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_fields(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Fields(fc.Args["includeDeprecated"].(bool)), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.Field) + fc.Result = res + return ec.marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐFieldᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_fields(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___Field_name(ctx, field) + case "description": + return ec.fieldContext___Field_description(ctx, field) + case "args": + return ec.fieldContext___Field_args(ctx, field) + case "type": + return ec.fieldContext___Field_type(ctx, field) + case "isDeprecated": + return ec.fieldContext___Field_isDeprecated(ctx, field) + case "deprecationReason": + return ec.fieldContext___Field_deprecationReason(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Field", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field___Type_fields_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_interfaces(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Interfaces(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_interfaces(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_possibleTypes(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.PossibleTypes(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_possibleTypes(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_enumValues(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.EnumValues(fc.Args["includeDeprecated"].(bool)), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.EnumValue) + fc.Result = res + return ec.marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValueᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_enumValues(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___EnumValue_name(ctx, field) + case "description": + return ec.fieldContext___EnumValue_description(ctx, field) + case "isDeprecated": + return ec.fieldContext___EnumValue_isDeprecated(ctx, field) + case "deprecationReason": + return ec.fieldContext___EnumValue_deprecationReason(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __EnumValue", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field___Type_enumValues_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_inputFields(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.InputFields(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.InputValue) + fc.Result = res + return ec.marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_inputFields(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___InputValue_name(ctx, field) + case "description": + return ec.fieldContext___InputValue_description(ctx, field) + case "type": + return ec.fieldContext___InputValue_type(ctx, field) + case "defaultValue": + return ec.fieldContext___InputValue_defaultValue(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __InputValue", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_ofType(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.OfType(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_ofType(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_specifiedByURL(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_specifiedByURL(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.SpecifiedByURL(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_specifiedByURL(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +// endregion **************************** field.gotpl ***************************** + +// region **************************** input.gotpl ***************************** + +// endregion **************************** input.gotpl ***************************** + +// region ************************** interface.gotpl *************************** + +// endregion ************************** interface.gotpl *************************** + +// region **************************** object.gotpl **************************** + +var queryImplementors = []string{"Query"} + +func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, queryImplementors) + ctx = graphql.WithFieldContext(ctx, &graphql.FieldContext{ + Object: "Query", + }) + + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + innerCtx := graphql.WithRootFieldContext(ctx, &graphql.RootFieldContext{ + Object: field.Name, + Field: field, + }) + + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Query") + case "inSchemadir": + field := field + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_inSchemadir(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) + }) + case "parentdir": + field := field + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_parentdir(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) + }) + case "subdir": + field := field + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_subdir(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) + }) + case "__type": + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Query___type(ctx, field) + }) + + case "__schema": + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Query___schema(ctx, field) + }) + + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var __DirectiveImplementors = []string{"__Directive"} + +func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __DirectiveImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Directive") + case "name": + + out.Values[i] = ec.___Directive_name(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "description": + + out.Values[i] = ec.___Directive_description(ctx, field, obj) + + case "locations": + + out.Values[i] = ec.___Directive_locations(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "args": + + out.Values[i] = ec.___Directive_args(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "isRepeatable": + + out.Values[i] = ec.___Directive_isRepeatable(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var __EnumValueImplementors = []string{"__EnumValue"} + +func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __EnumValueImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__EnumValue") + case "name": + + out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "description": + + out.Values[i] = ec.___EnumValue_description(ctx, field, obj) + + case "isDeprecated": + + out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "deprecationReason": + + out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) + + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var __FieldImplementors = []string{"__Field"} + +func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __FieldImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Field") + case "name": + + out.Values[i] = ec.___Field_name(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "description": + + out.Values[i] = ec.___Field_description(ctx, field, obj) + + case "args": + + out.Values[i] = ec.___Field_args(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "type": + + out.Values[i] = ec.___Field_type(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "isDeprecated": + + out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "deprecationReason": + + out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) + + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var __InputValueImplementors = []string{"__InputValue"} + +func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __InputValueImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__InputValue") + case "name": + + out.Values[i] = ec.___InputValue_name(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "description": + + out.Values[i] = ec.___InputValue_description(ctx, field, obj) + + case "type": + + out.Values[i] = ec.___InputValue_type(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "defaultValue": + + out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) + + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var __SchemaImplementors = []string{"__Schema"} + +func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __SchemaImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Schema") + case "description": + + out.Values[i] = ec.___Schema_description(ctx, field, obj) + + case "types": + + out.Values[i] = ec.___Schema_types(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "queryType": + + out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "mutationType": + + out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) + + case "subscriptionType": + + out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) + + case "directives": + + out.Values[i] = ec.___Schema_directives(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var __TypeImplementors = []string{"__Type"} + +func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __TypeImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Type") + case "kind": + + out.Values[i] = ec.___Type_kind(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "name": + + out.Values[i] = ec.___Type_name(ctx, field, obj) + + case "description": + + out.Values[i] = ec.___Type_description(ctx, field, obj) + + case "fields": + + out.Values[i] = ec.___Type_fields(ctx, field, obj) + + case "interfaces": + + out.Values[i] = ec.___Type_interfaces(ctx, field, obj) + + case "possibleTypes": + + out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) + + case "enumValues": + + out.Values[i] = ec.___Type_enumValues(ctx, field, obj) + + case "inputFields": + + out.Values[i] = ec.___Type_inputFields(ctx, field, obj) + + case "ofType": + + out.Values[i] = ec.___Type_ofType(ctx, field, obj) + + case "specifiedByURL": + + out.Values[i] = ec.___Type_specifiedByURL(ctx, field, obj) + + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +// endregion **************************** object.gotpl **************************** + +// region ***************************** type.gotpl ***************************** + +func (ec *executionContext) unmarshalNBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + res, err := graphql.UnmarshalBoolean(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + res := graphql.MarshalBoolean(v) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return res +} + +func (ec *executionContext) unmarshalNString2string(ctx context.Context, v interface{}) (string, error) { + res, err := graphql.UnmarshalString(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + res := graphql.MarshalString(v) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return res +} + +func (ec *executionContext) marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v introspection.Directive) graphql.Marshaler { + return ec.___Directive(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirectiveᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.Directive) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2string(ctx context.Context, v interface{}) (string, error) { + res, err := graphql.UnmarshalString(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalN__DirectiveLocation2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + res := graphql.MarshalString(v) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return res +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2ᚕstringᚄ(ctx context.Context, v interface{}) ([]string, error) { + var vSlice []interface{} + if v != nil { + vSlice = graphql.CoerceList(v) + } + var err error + res := make([]string, len(vSlice)) + for i := range vSlice { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) + res[i], err = ec.unmarshalN__DirectiveLocation2string(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalN__DirectiveLocation2ᚕstringᚄ(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__DirectiveLocation2string(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v introspection.EnumValue) graphql.Marshaler { + return ec.___EnumValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v introspection.Field) graphql.Marshaler { + return ec.___Field(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v introspection.InputValue) graphql.Marshaler { + return ec.___InputValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec.___Type(ctx, sel, v) +} + +func (ec *executionContext) unmarshalN__TypeKind2string(ctx context.Context, v interface{}) (string, error) { + res, err := graphql.UnmarshalString(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalN__TypeKind2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + res := graphql.MarshalString(v) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return res +} + +func (ec *executionContext) unmarshalOBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + res, err := graphql.UnmarshalBoolean(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + res := graphql.MarshalBoolean(v) + return res +} + +func (ec *executionContext) unmarshalOBoolean2ᚖbool(ctx context.Context, v interface{}) (*bool, error) { + if v == nil { + return nil, nil + } + res, err := graphql.UnmarshalBoolean(v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOBoolean2ᚖbool(ctx context.Context, sel ast.SelectionSet, v *bool) graphql.Marshaler { + if v == nil { + return graphql.Null + } + res := graphql.MarshalBoolean(*v) + return res +} + +func (ec *executionContext) unmarshalOString2ᚖstring(ctx context.Context, v interface{}) (*string, error) { + if v == nil { + return nil, nil + } + res, err := graphql.UnmarshalString(v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOString2ᚖstring(ctx context.Context, sel ast.SelectionSet, v *string) graphql.Marshaler { + if v == nil { + return graphql.Null + } + res := graphql.MarshalString(*v) + return res +} + +func (ec *executionContext) marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValueᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.EnumValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐFieldᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.Field) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v *introspection.Schema) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Schema(ctx, sel, v) +} + +func (ec *executionContext) marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Type(ctx, sel, v) +} + +// endregion ***************************** type.gotpl ***************************** diff --git a/_examples/embedding/subdir/prelude.generated.go b/_examples/embedding/subdir/prelude.generated.go new file mode 100644 index 00000000000..9c17808f350 --- /dev/null +++ b/_examples/embedding/subdir/prelude.generated.go @@ -0,0 +1,2687 @@ +// Code generated by github.com/99designs/gqlgen, DO NOT EDIT. + +package subdir + +import ( + "context" + "errors" + "fmt" + "strconv" + "sync" + + "github.com/99designs/gqlgen/graphql" + "github.com/99designs/gqlgen/graphql/introspection" + "github.com/vektah/gqlparser/v2/ast" +) + +// region ************************** generated!.gotpl ************************** + +// endregion ************************** generated!.gotpl ************************** + +// region ***************************** args.gotpl ***************************** + +func (ec *executionContext) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil +} + +// endregion ***************************** args.gotpl ***************************** + +// region ************************** directives.gotpl ************************** + +// endregion ************************** directives.gotpl ************************** + +// region **************************** field.gotpl ***************************** + +func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Directive_name(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Directive_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Directive", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Directive_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Directive_description(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Directive", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Directive_locations(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Locations, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]string) + fc.Result = res + return ec.marshalN__DirectiveLocation2ᚕstringᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Directive_locations(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Directive", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type __DirectiveLocation does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Directive_args(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Args, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]introspection.InputValue) + fc.Result = res + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Directive_args(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Directive", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___InputValue_name(ctx, field) + case "description": + return ec.fieldContext___InputValue_description(ctx, field) + case "type": + return ec.fieldContext___InputValue_type(ctx, field) + case "defaultValue": + return ec.fieldContext___InputValue_defaultValue(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __InputValue", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Directive_isRepeatable(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Directive_isRepeatable(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsRepeatable, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Directive_isRepeatable(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Directive", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___EnumValue_name(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___EnumValue_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__EnumValue", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___EnumValue_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___EnumValue_description(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__EnumValue", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___EnumValue_isDeprecated(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsDeprecated(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__EnumValue", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___EnumValue_deprecationReason(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.DeprecationReason(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__EnumValue", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_name(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_description(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_args(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Args, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]introspection.InputValue) + fc.Result = res + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_args(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___InputValue_name(ctx, field) + case "description": + return ec.fieldContext___InputValue_description(ctx, field) + case "type": + return ec.fieldContext___InputValue_type(ctx, field) + case "defaultValue": + return ec.fieldContext___InputValue_defaultValue(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __InputValue", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_type(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Type, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_type(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_isDeprecated(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsDeprecated(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_isDeprecated(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_deprecationReason(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.DeprecationReason(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_deprecationReason(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___InputValue_name(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___InputValue_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__InputValue", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___InputValue_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___InputValue_description(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__InputValue", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___InputValue_type(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Type, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___InputValue_type(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__InputValue", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___InputValue_defaultValue(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.DefaultValue, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__InputValue", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Schema_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_description(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_types(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Types(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]introspection.Type) + fc.Result = res + return ec.marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_types(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_queryType(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.QueryType(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_queryType(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_mutationType(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.MutationType(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_mutationType(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_subscriptionType(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.SubscriptionType(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_directives(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Directives(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]introspection.Directive) + fc.Result = res + return ec.marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirectiveᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_directives(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___Directive_name(ctx, field) + case "description": + return ec.fieldContext___Directive_description(ctx, field) + case "locations": + return ec.fieldContext___Directive_locations(ctx, field) + case "args": + return ec.fieldContext___Directive_args(ctx, field) + case "isRepeatable": + return ec.fieldContext___Directive_isRepeatable(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Directive", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_kind(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Kind(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalN__TypeKind2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_kind(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type __TypeKind does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_name(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_description(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_fields(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Fields(fc.Args["includeDeprecated"].(bool)), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.Field) + fc.Result = res + return ec.marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐFieldᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_fields(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___Field_name(ctx, field) + case "description": + return ec.fieldContext___Field_description(ctx, field) + case "args": + return ec.fieldContext___Field_args(ctx, field) + case "type": + return ec.fieldContext___Field_type(ctx, field) + case "isDeprecated": + return ec.fieldContext___Field_isDeprecated(ctx, field) + case "deprecationReason": + return ec.fieldContext___Field_deprecationReason(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Field", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field___Type_fields_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_interfaces(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Interfaces(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_interfaces(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_possibleTypes(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.PossibleTypes(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_possibleTypes(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_enumValues(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.EnumValues(fc.Args["includeDeprecated"].(bool)), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.EnumValue) + fc.Result = res + return ec.marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValueᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_enumValues(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___EnumValue_name(ctx, field) + case "description": + return ec.fieldContext___EnumValue_description(ctx, field) + case "isDeprecated": + return ec.fieldContext___EnumValue_isDeprecated(ctx, field) + case "deprecationReason": + return ec.fieldContext___EnumValue_deprecationReason(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __EnumValue", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field___Type_enumValues_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_inputFields(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.InputFields(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.InputValue) + fc.Result = res + return ec.marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_inputFields(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___InputValue_name(ctx, field) + case "description": + return ec.fieldContext___InputValue_description(ctx, field) + case "type": + return ec.fieldContext___InputValue_type(ctx, field) + case "defaultValue": + return ec.fieldContext___InputValue_defaultValue(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __InputValue", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_ofType(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.OfType(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_ofType(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_specifiedByURL(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_specifiedByURL(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.SpecifiedByURL(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_specifiedByURL(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +// endregion **************************** field.gotpl ***************************** + +// region **************************** input.gotpl ***************************** + +// endregion **************************** input.gotpl ***************************** + +// region ************************** interface.gotpl *************************** + +// endregion ************************** interface.gotpl *************************** + +// region **************************** object.gotpl **************************** + +var __DirectiveImplementors = []string{"__Directive"} + +func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __DirectiveImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Directive") + case "name": + + out.Values[i] = ec.___Directive_name(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "description": + + out.Values[i] = ec.___Directive_description(ctx, field, obj) + + case "locations": + + out.Values[i] = ec.___Directive_locations(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "args": + + out.Values[i] = ec.___Directive_args(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "isRepeatable": + + out.Values[i] = ec.___Directive_isRepeatable(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var __EnumValueImplementors = []string{"__EnumValue"} + +func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __EnumValueImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__EnumValue") + case "name": + + out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "description": + + out.Values[i] = ec.___EnumValue_description(ctx, field, obj) + + case "isDeprecated": + + out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "deprecationReason": + + out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) + + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var __FieldImplementors = []string{"__Field"} + +func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __FieldImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Field") + case "name": + + out.Values[i] = ec.___Field_name(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "description": + + out.Values[i] = ec.___Field_description(ctx, field, obj) + + case "args": + + out.Values[i] = ec.___Field_args(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "type": + + out.Values[i] = ec.___Field_type(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "isDeprecated": + + out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "deprecationReason": + + out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) + + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var __InputValueImplementors = []string{"__InputValue"} + +func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __InputValueImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__InputValue") + case "name": + + out.Values[i] = ec.___InputValue_name(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "description": + + out.Values[i] = ec.___InputValue_description(ctx, field, obj) + + case "type": + + out.Values[i] = ec.___InputValue_type(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "defaultValue": + + out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) + + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var __SchemaImplementors = []string{"__Schema"} + +func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __SchemaImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Schema") + case "description": + + out.Values[i] = ec.___Schema_description(ctx, field, obj) + + case "types": + + out.Values[i] = ec.___Schema_types(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "queryType": + + out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "mutationType": + + out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) + + case "subscriptionType": + + out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) + + case "directives": + + out.Values[i] = ec.___Schema_directives(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var __TypeImplementors = []string{"__Type"} + +func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __TypeImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Type") + case "kind": + + out.Values[i] = ec.___Type_kind(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "name": + + out.Values[i] = ec.___Type_name(ctx, field, obj) + + case "description": + + out.Values[i] = ec.___Type_description(ctx, field, obj) + + case "fields": + + out.Values[i] = ec.___Type_fields(ctx, field, obj) + + case "interfaces": + + out.Values[i] = ec.___Type_interfaces(ctx, field, obj) + + case "possibleTypes": + + out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) + + case "enumValues": + + out.Values[i] = ec.___Type_enumValues(ctx, field, obj) + + case "inputFields": + + out.Values[i] = ec.___Type_inputFields(ctx, field, obj) + + case "ofType": + + out.Values[i] = ec.___Type_ofType(ctx, field, obj) + + case "specifiedByURL": + + out.Values[i] = ec.___Type_specifiedByURL(ctx, field, obj) + + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +// endregion **************************** object.gotpl **************************** + +// region ***************************** type.gotpl ***************************** + +func (ec *executionContext) unmarshalNBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + res, err := graphql.UnmarshalBoolean(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + res := graphql.MarshalBoolean(v) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return res +} + +func (ec *executionContext) unmarshalNString2string(ctx context.Context, v interface{}) (string, error) { + res, err := graphql.UnmarshalString(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + res := graphql.MarshalString(v) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return res +} + +func (ec *executionContext) marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v introspection.Directive) graphql.Marshaler { + return ec.___Directive(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirectiveᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.Directive) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2string(ctx context.Context, v interface{}) (string, error) { + res, err := graphql.UnmarshalString(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalN__DirectiveLocation2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + res := graphql.MarshalString(v) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return res +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2ᚕstringᚄ(ctx context.Context, v interface{}) ([]string, error) { + var vSlice []interface{} + if v != nil { + vSlice = graphql.CoerceList(v) + } + var err error + res := make([]string, len(vSlice)) + for i := range vSlice { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) + res[i], err = ec.unmarshalN__DirectiveLocation2string(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalN__DirectiveLocation2ᚕstringᚄ(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__DirectiveLocation2string(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v introspection.EnumValue) graphql.Marshaler { + return ec.___EnumValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v introspection.Field) graphql.Marshaler { + return ec.___Field(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v introspection.InputValue) graphql.Marshaler { + return ec.___InputValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec.___Type(ctx, sel, v) +} + +func (ec *executionContext) unmarshalN__TypeKind2string(ctx context.Context, v interface{}) (string, error) { + res, err := graphql.UnmarshalString(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalN__TypeKind2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + res := graphql.MarshalString(v) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return res +} + +func (ec *executionContext) unmarshalOBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + res, err := graphql.UnmarshalBoolean(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + res := graphql.MarshalBoolean(v) + return res +} + +func (ec *executionContext) unmarshalOBoolean2ᚖbool(ctx context.Context, v interface{}) (*bool, error) { + if v == nil { + return nil, nil + } + res, err := graphql.UnmarshalBoolean(v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOBoolean2ᚖbool(ctx context.Context, sel ast.SelectionSet, v *bool) graphql.Marshaler { + if v == nil { + return graphql.Null + } + res := graphql.MarshalBoolean(*v) + return res +} + +func (ec *executionContext) unmarshalOString2ᚖstring(ctx context.Context, v interface{}) (*string, error) { + if v == nil { + return nil, nil + } + res, err := graphql.UnmarshalString(v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOString2ᚖstring(ctx context.Context, sel ast.SelectionSet, v *string) graphql.Marshaler { + if v == nil { + return graphql.Null + } + res := graphql.MarshalString(*v) + return res +} + +func (ec *executionContext) marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValueᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.EnumValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐFieldᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.Field) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v *introspection.Schema) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Schema(ctx, sel, v) +} + +func (ec *executionContext) marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Type(ctx, sel, v) +} + +// endregion ***************************** type.gotpl ***************************** diff --git a/_examples/embedding/subdir/resolvers.go b/_examples/embedding/subdir/resolvers.go new file mode 100644 index 00000000000..4bb0607f51a --- /dev/null +++ b/_examples/embedding/subdir/resolvers.go @@ -0,0 +1,31 @@ +//go:generate go run ../../../testdata/gqlgen.go -config cfgdir/generate_in_subdir.yml +//go:generate go run ../../../testdata/gqlgen.go -config cfgdir/generate_in_gendir.yml + +package subdir + +import ( + context "context" + + "github.com/99designs/gqlgen/_examples/embedding/subdir/gendir" +) + +type Resolver struct{ *Resolver } + +func (q *Resolver) Query() QueryResolver { + return q +} +func (q *Resolver) InSchemadir(ctx context.Context) (string, error) { + return "example", nil +} +func (q *Resolver) Parentdir(ctx context.Context) (string, error) { + return "example", nil +} +func (q *Resolver) Subdir(ctx context.Context) (string, error) { + return "example", nil +} + +type GendirResolver struct{ *Resolver } + +func (q *GendirResolver) Query() gendir.QueryResolver { + return &Resolver{} +} diff --git a/_examples/embedding/subdir/root.generated.go b/_examples/embedding/subdir/root.generated.go new file mode 100644 index 00000000000..f7cd12048ca --- /dev/null +++ b/_examples/embedding/subdir/root.generated.go @@ -0,0 +1,440 @@ +// Code generated by github.com/99designs/gqlgen, DO NOT EDIT. + +package subdir + +import ( + "context" + "errors" + "fmt" + "strconv" + "sync/atomic" + + "github.com/99designs/gqlgen/graphql" + "github.com/99designs/gqlgen/graphql/introspection" + "github.com/vektah/gqlparser/v2/ast" +) + +// region ************************** generated!.gotpl ************************** + +type QueryResolver interface { + InSchemadir(ctx context.Context) (string, error) + Parentdir(ctx context.Context) (string, error) + Subdir(ctx context.Context) (string, error) +} + +// endregion ************************** generated!.gotpl ************************** + +// region ***************************** args.gotpl ***************************** + +func (ec *executionContext) field_Query___type_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["name"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["name"] = arg0 + return args, nil +} + +// endregion ***************************** args.gotpl ***************************** + +// region ************************** directives.gotpl ************************** + +// endregion ************************** directives.gotpl ************************** + +// region **************************** field.gotpl ***************************** + +func (ec *executionContext) _Query_inSchemadir(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_inSchemadir(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().InSchemadir(rctx) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_inSchemadir(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Query_parentdir(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_parentdir(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Parentdir(rctx) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_parentdir(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Query_subdir(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_subdir(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Subdir(rctx) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_subdir(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query___type(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.introspectType(fc.Args["name"].(string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query___type(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query___type_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query___schema(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.introspectSchema() + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Schema) + fc.Result = res + return ec.marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query___schema(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "description": + return ec.fieldContext___Schema_description(ctx, field) + case "types": + return ec.fieldContext___Schema_types(ctx, field) + case "queryType": + return ec.fieldContext___Schema_queryType(ctx, field) + case "mutationType": + return ec.fieldContext___Schema_mutationType(ctx, field) + case "subscriptionType": + return ec.fieldContext___Schema_subscriptionType(ctx, field) + case "directives": + return ec.fieldContext___Schema_directives(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Schema", field.Name) + }, + } + return fc, nil +} + +// endregion **************************** field.gotpl ***************************** + +// region **************************** input.gotpl ***************************** + +// endregion **************************** input.gotpl ***************************** + +// region ************************** interface.gotpl *************************** + +// endregion ************************** interface.gotpl *************************** + +// region **************************** object.gotpl **************************** + +var queryImplementors = []string{"Query"} + +func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, queryImplementors) + ctx = graphql.WithFieldContext(ctx, &graphql.FieldContext{ + Object: "Query", + }) + + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + innerCtx := graphql.WithRootFieldContext(ctx, &graphql.RootFieldContext{ + Object: field.Name, + Field: field, + }) + + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Query") + case "inSchemadir": + field := field + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_inSchemadir(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) + }) + case "parentdir": + field := field + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_parentdir(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) + }) + case "subdir": + field := field + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_subdir(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) + }) + case "__type": + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Query___type(ctx, field) + }) + + case "__schema": + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Query___schema(ctx, field) + }) + + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +// endregion **************************** object.gotpl **************************** + +// region ***************************** type.gotpl ***************************** + +// endregion ***************************** type.gotpl ***************************** diff --git a/_examples/embedding/subdir/root_.generated.go b/_examples/embedding/subdir/root_.generated.go new file mode 100644 index 00000000000..79417650656 --- /dev/null +++ b/_examples/embedding/subdir/root_.generated.go @@ -0,0 +1,154 @@ +// Code generated by github.com/99designs/gqlgen, DO NOT EDIT. + +package subdir + +import ( + "bytes" + "context" + "embed" + "errors" + "fmt" + + "github.com/99designs/gqlgen/graphql" + "github.com/99designs/gqlgen/graphql/introspection" + gqlparser "github.com/vektah/gqlparser/v2" + "github.com/vektah/gqlparser/v2/ast" +) + +// NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface. +func NewExecutableSchema(cfg Config) graphql.ExecutableSchema { + return &executableSchema{ + resolvers: cfg.Resolvers, + directives: cfg.Directives, + complexity: cfg.Complexity, + } +} + +type Config struct { + Resolvers ResolverRoot + Directives DirectiveRoot + Complexity ComplexityRoot +} + +type ResolverRoot interface { + Query() QueryResolver +} + +type DirectiveRoot struct { +} + +type ComplexityRoot struct { + Query struct { + InSchemadir func(childComplexity int) int + Parentdir func(childComplexity int) int + Subdir func(childComplexity int) int + } +} + +type executableSchema struct { + resolvers ResolverRoot + directives DirectiveRoot + complexity ComplexityRoot +} + +func (e *executableSchema) Schema() *ast.Schema { + return parsedSchema +} + +func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) { + ec := executionContext{nil, e} + _ = ec + switch typeName + "." + field { + + case "Query.inSchemadir": + if e.complexity.Query.InSchemadir == nil { + break + } + + return e.complexity.Query.InSchemadir(childComplexity), true + + case "Query.parentdir": + if e.complexity.Query.Parentdir == nil { + break + } + + return e.complexity.Query.Parentdir(childComplexity), true + + case "Query.subdir": + if e.complexity.Query.Subdir == nil { + break + } + + return e.complexity.Query.Subdir(childComplexity), true + + } + return 0, false +} + +func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { + rc := graphql.GetOperationContext(ctx) + ec := executionContext{rc, e} + inputUnmarshalMap := graphql.BuildUnmarshalerMap() + first := true + + switch rc.Operation.Operation { + case ast.Query: + return func(ctx context.Context) *graphql.Response { + if !first { + return nil + } + first = false + ctx = graphql.WithUnmarshalerMap(ctx, inputUnmarshalMap) + data := ec._Query(ctx, rc.Operation.SelectionSet) + var buf bytes.Buffer + data.MarshalGQL(&buf) + + return &graphql.Response{ + Data: buf.Bytes(), + } + } + + default: + return graphql.OneShot(graphql.ErrorResponse(ctx, "unsupported GraphQL operation")) + } +} + +type executionContext struct { + *graphql.OperationContext + *executableSchema +} + +func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") + } + return introspection.WrapSchema(parsedSchema), nil +} + +func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") + } + return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil +} + +//go:embed "schemadir/root.graphqls" "subdir.graphqls" +var sourcesFS embed.FS + +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not availalbe", filename)) + } + return string(data) +} + +var sources = []*ast.Source{ + {Name: "schemadir/root.graphqls", Input: sourceData("schemadir/root.graphqls"), BuiltIn: false}, + {Name: "../parent.graphqls", Input: `extend type Query { + parentdir: String! +} +`, BuiltIn: false}, + {Name: "subdir.graphqls", Input: sourceData("subdir.graphqls"), BuiltIn: false}, +} +var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/_examples/embedding/subdir/schemadir/root.graphqls b/_examples/embedding/subdir/schemadir/root.graphqls new file mode 100644 index 00000000000..e3323159fe2 --- /dev/null +++ b/_examples/embedding/subdir/schemadir/root.graphqls @@ -0,0 +1,3 @@ +type Query { + inSchemadir: String! +} diff --git a/_examples/embedding/subdir/subdir.graphqls b/_examples/embedding/subdir/subdir.graphqls new file mode 100644 index 00000000000..2f50d38cac3 --- /dev/null +++ b/_examples/embedding/subdir/subdir.graphqls @@ -0,0 +1,3 @@ +extend type Query { + subdir: String! +} From 524ec52a7cc205464e735636e0da75c271848870 Mon Sep 17 00:00:00 2001 From: Viktor Stanchev Date: Sun, 1 May 2022 18:39:48 +0000 Subject: [PATCH 8/8] improve error handling --- codegen/data.go | 54 ++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/codegen/data.go b/codegen/data.go index afcd1320262..3a636e3bdb6 100644 --- a/codegen/data.go +++ b/codegen/data.go @@ -33,11 +33,12 @@ type Data struct { QueryRoot *Object MutationRoot *Object SubscriptionRoot *Object + AugmentedSources []AugmentedSource } func (d *Data) HasEmbeddableSources() bool { hasEmbeddableSources := false - for _, s := range d.AugmentedSources() { + for _, s := range d.AugmentedSources { if s.Embeddable { hasEmbeddableSources = true } @@ -45,33 +46,6 @@ func (d *Data) HasEmbeddableSources() bool { return hasEmbeddableSources } -func (d *Data) AugmentedSources() []AugmentedSource { - sources := []AugmentedSource{} - for _, s := range d.Config.Sources { - - wd, err := os.Getwd() - if err != nil { - panic(err) - } - outputDir := d.Config.Exec.Dir() - relative, err := filepath.Rel(outputDir, filepath.Join(wd, s.Name)) - if err != nil { - panic("TODO: handle" + err.Error() + " inputs:" + d.Config.Exec.Filename + " and " + filepath.Join(wd, s.Name)) - } - embeddable := true - if strings.HasPrefix(relative, "..") { - embeddable = false - } - sources = append(sources, AugmentedSource{ - RelativePath: relative, - Embeddable: embeddable, - BuiltIn: s.BuiltIn, - Source: s.Input, - }) - } - return sources -} - // AugmentedSource contains extra information about graphql schema files which is not known directly from the Config.Sources data type AugmentedSource struct { // path relative to Config.Exec.Filename @@ -196,6 +170,30 @@ func BuildData(cfg *config.Config) (*Data, error) { // otherwise show a generic error message return nil, fmt.Errorf("invalid types were encountered while traversing the go source code, this probably means the invalid code generated isnt correct. add try adding -v to debug") } + aSources := []AugmentedSource{} + for _, s := range cfg.Sources { + wd, err := os.Getwd() + if err != nil { + return nil, fmt.Errorf("failed to get working directory: %w", err) + } + outputDir := cfg.Exec.Dir() + sourcePath := filepath.Join(wd, s.Name) + relative, err := filepath.Rel(outputDir, sourcePath) + if err != nil { + return nil, fmt.Errorf("failed to compute path of %s relative to %s: %w"+sourcePath, outputDir, err) + } + embeddable := true + if strings.HasPrefix(relative, "..") { + embeddable = false + } + aSources = append(aSources, AugmentedSource{ + RelativePath: relative, + Embeddable: embeddable, + BuiltIn: s.BuiltIn, + Source: s.Input, + }) + } + s.AugmentedSources = aSources return &s, nil }