From 962470dec347d728e236395c59844ae0acf22333 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 12 May 2019 12:15:30 +1000 Subject: [PATCH] Fix a data race when handling concurrent resolver errors --- codegen/generated!.gotpl | 1 + codegen/object.gotpl | 16 +- codegen/testdata/gqlgen.yml | 21 - codegen/testdata/schema.graphql | 168 ----- codegen/testserver/generated.go | 816 +++++++++++++++------ codegen/testserver/gqlgen.yml | 2 + codegen/testserver/models.go | 2 + codegen/testserver/nulls.graphql | 20 + codegen/testserver/nulls_test.go | 23 + codegen/testserver/resolver.go | 36 +- codegen/testserver/schema.graphql | 9 - codegen/testserver/stub.go | 48 +- example/chat/generated.go | 84 +-- example/config/generated.go | 89 +-- example/dataloader/generated.go | 93 +-- example/fileupload/generated.go | 83 +-- example/scalars/generated.go | 81 +- example/selection/generated.go | 74 +- example/starwars/generated/exec.go | 135 ++-- example/todo/generated.go | 77 +- example/type-system-extension/generated.go | 79 +- integration/generated.go | 87 +-- 22 files changed, 1163 insertions(+), 881 deletions(-) delete mode 100644 codegen/testdata/gqlgen.yml delete mode 100644 codegen/testdata/schema.graphql create mode 100644 codegen/testserver/nulls.graphql diff --git a/codegen/generated!.gotpl b/codegen/generated!.gotpl index dc8095de20e..5753f1d1360 100644 --- a/codegen/generated!.gotpl +++ b/codegen/generated!.gotpl @@ -4,6 +4,7 @@ {{ reserveImport "strconv" }} {{ reserveImport "time" }} {{ reserveImport "sync" }} +{{ reserveImport "sync/atomic" }} {{ reserveImport "errors" }} {{ reserveImport "bytes" }} diff --git a/codegen/object.gotpl b/codegen/object.gotpl index 5cc738311cb..98a75740e66 100644 --- a/codegen/object.gotpl +++ b/codegen/object.gotpl @@ -32,7 +32,7 @@ func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.Selec {{end}} out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -50,7 +50,11 @@ func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.Selec res = ec._{{$object.Name}}_{{$field.Name}}(ctx, field{{if not $object.Root}}, obj{{end}}) {{- if $field.TypeReference.GQL.NonNull }} if res == graphql.Null { - invalid = true + {{- if $object.IsConcurrent }} + atomic.AddUint32(&invalids, 1) + {{- else }} + invalids++ + {{- end }} } {{- end }} return res @@ -59,7 +63,11 @@ func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.Selec out.Values[i] = ec._{{$object.Name}}_{{$field.Name}}(ctx, field{{if not $object.Root}}, obj{{end}}) {{- if $field.TypeReference.GQL.NonNull }} if out.Values[i] == graphql.Null { - invalid = true + {{- if $object.IsConcurrent }} + atomic.AddUint32(&invalids, 1) + {{- else }} + invalids++ + {{- end }} } {{- end }} {{- end }} @@ -69,7 +77,7 @@ func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.Selec } } out.Dispatch() - if invalid { return graphql.Null } + if invalids > 0 { return graphql.Null } return out } {{- end }} diff --git a/codegen/testdata/gqlgen.yml b/codegen/testdata/gqlgen.yml deleted file mode 100644 index b32289be0d3..00000000000 --- a/codegen/testdata/gqlgen.yml +++ /dev/null @@ -1,21 +0,0 @@ -schema: - - "testdata/schema.graphql" - -exec: - filename: out/generated.go -model: - filename: out/generated.go - -models: - ExistingModel: - model: github.com/99designs/gqlgen/plugin/modelgen/out.ExistingModel - ExistingInput: - model: github.com/99designs/gqlgen/plugin/modelgen/out.ExistingInput - ExistingEnum: - model: github.com/99designs/gqlgen/plugin/modelgen/out.ExistingEnum - ExistingInterface: - model: github.com/99designs/gqlgen/plugin/modelgen/out.ExistingInterface - ExistingUnion: - model: github.com/99designs/gqlgen/plugin/modelgen/out.ExistingUnion - - diff --git a/codegen/testdata/schema.graphql b/codegen/testdata/schema.graphql deleted file mode 100644 index 5d49426216f..00000000000 --- a/codegen/testdata/schema.graphql +++ /dev/null @@ -1,168 +0,0 @@ -type Query { - invalidIdentifier: InvalidIdentifier - collision: It - recursive(input: RecursiveInputSlice): Boolean - nestedInputs(input: [[OuterInput]] = [[{inner: {id: 1}}]]): Boolean - nestedOutputs: [[OuterObject]] - keywords(input: Keywords): Boolean! - shapes: [Shape] - errorBubble: Error - modelMethods: ModelMethods - valid: String! - user(id: Int!): User! - nullableArg(arg: Int = 123): String - directiveArg(arg: String! @length(min:1, max: 255, message: "invalid length")): String - directiveNullableArg(arg: Int @range(min:0), arg2: Int @range): String - directiveInputNullable(arg: InputDirectives): String - directiveInput(arg: InputDirectives!): String -} - -type Subscription { - updated: String! - initPayload: String! -} - -type User { - id: Int! - friends: [User!]! -} - -type Error { - id: ID! - errorOnNonRequiredField: String - errorOnRequiredField: String! - nilOnRequiredField: String! -} - -type ModelMethods { - resolverField: Boolean! - noContext: Boolean! - withContext: Boolean! -} - -type InvalidIdentifier { - id: Int! -} - -type It { - id: ID! -} - -input RecursiveInputSlice { - self: [RecursiveInputSlice!] -} - -input InnerInput { - id:Int! -} - -input OuterInput { - inner: InnerInput! -} - -input InputDirectives { - text: String! @length(min: 0, max: 7, message: "not valid") - inner: InnerDirectives! - innerNullable: InnerDirectives -} - -input InnerDirectives { - message: String! @length(min: 1, message: "not valid") -} - -type OuterObject { - inner: InnerObject! -} - -type InnerObject { - id: Int! -} - -input Keywords { - 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! -} - -extend type Query { - keywordArgs( - 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!, - ): Boolean! -} - -interface Shape { - area: Float -} -type Circle implements Shape { - radius: Float - area: Float -} -type Rectangle implements Shape { - length: Float - width: Float - area: Float -} -union ShapeUnion = Circle | Rectangle - -type ForcedResolver { - field: Circle -} - -type EmbeddedPointer { - ID: String - Title: String -} - -directive @length(min: Int!, max: Int, message: String!) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION -directive @range(min: Int = 0, max: Int, message: String) on ARGUMENT_DEFINITION - -enum Status { - OK - ERROR -} diff --git a/codegen/testserver/generated.go b/codegen/testserver/generated.go index 85025fdf429..3025a337b26 100644 --- a/codegen/testserver/generated.go +++ b/codegen/testserver/generated.go @@ -10,6 +10,7 @@ import ( "io" "strconv" "sync" + "sync/atomic" "time" introspection1 "github.com/99designs/gqlgen/codegen/testserver/introspection" @@ -38,6 +39,7 @@ type Config struct { } type ResolverRoot interface { + Errors() ErrorsResolver ForcedResolver() ForcedResolverResolver ModelMethods() ModelMethodsResolver OverlappingFields() OverlappingFieldsResolver @@ -109,6 +111,14 @@ type ComplexityRoot struct { NilOnRequiredField func(childComplexity int) int } + Errors struct { + A func(childComplexity int) int + B func(childComplexity int) int + C func(childComplexity int) int + D func(childComplexity int) int + E func(childComplexity int) int + } + ForcedResolver struct { Field func(childComplexity int) int } @@ -175,6 +185,7 @@ type ComplexityRoot struct { DirectiveInputType func(childComplexity int, arg InnerInput) int DirectiveNullableArg func(childComplexity int, arg *int, arg2 *int) int ErrorBubble func(childComplexity int) int + Errors func(childComplexity int) int Fallback func(childComplexity int, arg FallbackToStringEncoding) int InputSlice func(childComplexity int, arg []string) int InvalidIdentifier func(childComplexity int) int @@ -246,6 +257,13 @@ type ComplexityRoot struct { } } +type ErrorsResolver interface { + A(ctx context.Context, obj *Errors) (*Error, error) + B(ctx context.Context, obj *Errors) (*Error, error) + C(ctx context.Context, obj *Errors) (*Error, error) + D(ctx context.Context, obj *Errors) (*Error, error) + E(ctx context.Context, obj *Errors) (*Error, error) +} type ForcedResolverResolver interface { Field(ctx context.Context, obj *ForcedResolver) (*Circle, error) } @@ -268,9 +286,7 @@ type QueryResolver interface { NestedInputs(ctx context.Context, input [][]*OuterInput) (*bool, error) NestedOutputs(ctx context.Context) ([][]*OuterObject, error) Shapes(ctx context.Context) ([]Shape, error) - ErrorBubble(ctx context.Context) (*Error, error) ModelMethods(ctx context.Context) (*ModelMethods, error) - Valid(ctx context.Context) (string, error) User(ctx context.Context, id int) (*User, error) NullableArg(ctx context.Context, arg *int) (*string, error) DirectiveArg(ctx context.Context, arg string) (*string, error) @@ -284,6 +300,9 @@ type QueryResolver interface { DeprecatedField(ctx context.Context) (string, error) Overlapping(ctx context.Context) (*OverlappingFields, error) MapStringInterface(ctx context.Context, in map[string]interface{}) (map[string]interface{}, error) + ErrorBubble(ctx context.Context) (*Error, error) + Errors(ctx context.Context) (*Errors, error) + Valid(ctx context.Context) (string, error) Panics(ctx context.Context) (*Panics, error) DefaultScalar(ctx context.Context, arg string) (string, error) Slices(ctx context.Context) (*Slices, error) @@ -455,6 +474,41 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Error.NilOnRequiredField(childComplexity), true + case "Errors.a": + if e.complexity.Errors.A == nil { + break + } + + return e.complexity.Errors.A(childComplexity), true + + case "Errors.b": + if e.complexity.Errors.B == nil { + break + } + + return e.complexity.Errors.B(childComplexity), true + + case "Errors.c": + if e.complexity.Errors.C == nil { + break + } + + return e.complexity.Errors.C(childComplexity), true + + case "Errors.d": + if e.complexity.Errors.D == nil { + break + } + + return e.complexity.Errors.D(childComplexity), true + + case "Errors.e": + if e.complexity.Errors.E == nil { + break + } + + return e.complexity.Errors.E(childComplexity), true + case "ForcedResolver.field": if e.complexity.ForcedResolver.Field == nil { break @@ -698,6 +752,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.ErrorBubble(childComplexity), true + case "Query.errors": + if e.complexity.Query.Errors == nil { + break + } + + return e.complexity.Query.Errors(childComplexity), true + case "Query.fallback": if e.complexity.Query.Fallback == nil { break @@ -1208,6 +1269,27 @@ input MapStringInterfaceInput { a: String b: Int } +`}, + &ast.Source{Name: "nulls.graphql", Input: `extend type Query { + errorBubble: Error + errors: Errors + valid: String! +} + +type Errors { + a: Error! + b: Error! + c: Error! + d: Error! + e: Error! +} + +type Error { + id: ID! + errorOnNonRequiredField: String + errorOnRequiredField: String! + nilOnRequiredField: String! +} `}, &ast.Source{Name: "panics.graphql", Input: `extend type Query { panics: Panics @@ -1241,9 +1323,7 @@ type EmbeddedDefaultScalar { nestedInputs(input: [[OuterInput]] = [[{inner: {id: 1}}]]): Boolean nestedOutputs: [[OuterObject]] shapes: [Shape] - errorBubble: Error modelMethods: ModelMethods - valid: String! user(id: Int!): User! nullableArg(arg: Int = 123): String directiveArg(arg: String! @length(min:1, max: 255, message: "invalid length")): String @@ -1278,13 +1358,6 @@ type Autobind { idInt: ID! } -type Error { - id: ID! - errorOnNonRequiredField: String - errorOnRequiredField: String! - nilOnRequiredField: String! -} - type ModelMethods { resolverField: Boolean! noContext: Boolean! @@ -2618,6 +2691,141 @@ func (ec *executionContext) _Error_nilOnRequiredField(ctx context.Context, field return ec.marshalNString2ᚖstring(ctx, field.Selections, res) } +func (ec *executionContext) _Errors_a(ctx context.Context, field graphql.CollectedField, obj *Errors) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Errors", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Errors().A(rctx, obj) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*Error) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNError2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐError(ctx, field.Selections, res) +} + +func (ec *executionContext) _Errors_b(ctx context.Context, field graphql.CollectedField, obj *Errors) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Errors", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Errors().B(rctx, obj) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*Error) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNError2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐError(ctx, field.Selections, res) +} + +func (ec *executionContext) _Errors_c(ctx context.Context, field graphql.CollectedField, obj *Errors) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Errors", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Errors().C(rctx, obj) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*Error) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNError2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐError(ctx, field.Selections, res) +} + +func (ec *executionContext) _Errors_d(ctx context.Context, field graphql.CollectedField, obj *Errors) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Errors", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Errors().D(rctx, obj) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*Error) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNError2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐError(ctx, field.Selections, res) +} + +func (ec *executionContext) _Errors_e(ctx context.Context, field graphql.CollectedField, obj *Errors) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Errors", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Errors().E(rctx, obj) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*Error) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNError2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐError(ctx, field.Selections, res) +} + func (ec *executionContext) _ForcedResolver_field(ctx context.Context, field graphql.CollectedField, obj *ForcedResolver) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() @@ -3397,30 +3605,6 @@ func (ec *executionContext) _Query_shapes(ctx context.Context, field graphql.Col return ec.marshalOShape2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐShape(ctx, field.Selections, res) } -func (ec *executionContext) _Query_errorBubble(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Query", - Field: field, - Args: nil, - IsMethod: true, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().ErrorBubble(rctx) - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(*Error) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalOError2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐError(ctx, field.Selections, res) -} - func (ec *executionContext) _Query_modelMethods(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() @@ -3445,33 +3629,6 @@ func (ec *executionContext) _Query_modelMethods(ctx context.Context, field graph return ec.marshalOModelMethods2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐModelMethods(ctx, field.Selections, res) } -func (ec *executionContext) _Query_valid(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Query", - Field: field, - Args: nil, - IsMethod: true, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Valid(rctx) - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalNString2string(ctx, field.Selections, res) -} - func (ec *executionContext) _Query_user(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() @@ -3859,6 +4016,81 @@ func (ec *executionContext) _Query_mapStringInterface(ctx context.Context, field return ec.marshalOMapStringInterfaceType2map(ctx, field.Selections, res) } +func (ec *executionContext) _Query_errorBubble(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().ErrorBubble(rctx) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*Error) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOError2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐError(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_errors(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Errors(rctx) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*Errors) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOErrors2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐErrors(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_valid(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Valid(rctx) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNString2string(ctx, field.Selections, res) +} + func (ec *executionContext) _Query_panics(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() @@ -5888,7 +6120,7 @@ func (ec *executionContext) _A(ctx context.Context, sel ast.SelectionSet, obj *A fields := graphql.CollectFields(ec.RequestContext, sel, aImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -5896,14 +6128,14 @@ func (ec *executionContext) _A(ctx context.Context, sel ast.SelectionSet, obj *A case "id": out.Values[i] = ec._A_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -5915,7 +6147,7 @@ func (ec *executionContext) _AIt(ctx context.Context, sel ast.SelectionSet, obj fields := graphql.CollectFields(ec.RequestContext, sel, aItImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -5923,14 +6155,14 @@ func (ec *executionContext) _AIt(ctx context.Context, sel ast.SelectionSet, obj case "id": out.Values[i] = ec._AIt_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -5942,7 +6174,7 @@ func (ec *executionContext) _AbIt(ctx context.Context, sel ast.SelectionSet, obj fields := graphql.CollectFields(ec.RequestContext, sel, abItImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -5950,14 +6182,14 @@ func (ec *executionContext) _AbIt(ctx context.Context, sel ast.SelectionSet, obj case "id": out.Values[i] = ec._AbIt_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -5969,7 +6201,7 @@ func (ec *executionContext) _Autobind(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, autobindImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -5977,34 +6209,34 @@ func (ec *executionContext) _Autobind(ctx context.Context, sel ast.SelectionSet, case "int": out.Values[i] = ec._Autobind_int(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "int32": out.Values[i] = ec._Autobind_int32(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "int64": out.Values[i] = ec._Autobind_int64(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "idStr": out.Values[i] = ec._Autobind_idStr(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "idInt": out.Values[i] = ec._Autobind_idInt(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -6016,7 +6248,7 @@ func (ec *executionContext) _B(ctx context.Context, sel ast.SelectionSet, obj *B fields := graphql.CollectFields(ec.RequestContext, sel, bImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -6024,14 +6256,14 @@ func (ec *executionContext) _B(ctx context.Context, sel ast.SelectionSet, obj *B case "id": out.Values[i] = ec._B_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -6043,7 +6275,7 @@ func (ec *executionContext) _Circle(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ec.RequestContext, sel, circleImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -6057,7 +6289,7 @@ func (ec *executionContext) _Circle(ctx context.Context, sel ast.SelectionSet, o } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -6069,7 +6301,7 @@ func (ec *executionContext) _Content_Post(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ec.RequestContext, sel, content_PostImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -6081,7 +6313,7 @@ func (ec *executionContext) _Content_Post(ctx context.Context, sel ast.Selection } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -6093,7 +6325,7 @@ func (ec *executionContext) _Content_User(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ec.RequestContext, sel, content_UserImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -6105,7 +6337,7 @@ func (ec *executionContext) _Content_User(ctx context.Context, sel ast.Selection } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -6117,7 +6349,7 @@ func (ec *executionContext) _EmbeddedDefaultScalar(ctx context.Context, sel ast. fields := graphql.CollectFields(ec.RequestContext, sel, embeddedDefaultScalarImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -6129,7 +6361,7 @@ func (ec *executionContext) _EmbeddedDefaultScalar(ctx context.Context, sel ast. } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -6141,7 +6373,7 @@ func (ec *executionContext) _EmbeddedPointer(ctx context.Context, sel ast.Select fields := graphql.CollectFields(ec.RequestContext, sel, embeddedPointerImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -6155,7 +6387,7 @@ func (ec *executionContext) _EmbeddedPointer(ctx context.Context, sel ast.Select } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -6167,7 +6399,7 @@ func (ec *executionContext) _Error(ctx context.Context, sel ast.SelectionSet, ob fields := graphql.CollectFields(ec.RequestContext, sel, errorImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -6175,26 +6407,118 @@ func (ec *executionContext) _Error(ctx context.Context, sel ast.SelectionSet, ob case "id": out.Values[i] = ec._Error_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "errorOnNonRequiredField": out.Values[i] = ec._Error_errorOnNonRequiredField(ctx, field, obj) case "errorOnRequiredField": out.Values[i] = ec._Error_errorOnRequiredField(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "nilOnRequiredField": out.Values[i] = ec._Error_nilOnRequiredField(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { + return graphql.Null + } + return out +} + +var errorsImplementors = []string{"Errors"} + +func (ec *executionContext) _Errors(ctx context.Context, sel ast.SelectionSet, obj *Errors) graphql.Marshaler { + fields := graphql.CollectFields(ec.RequestContext, sel, errorsImplementors) + + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Errors") + case "a": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Errors_a(ctx, field, obj) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + }) + case "b": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Errors_b(ctx, field, obj) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + }) + case "c": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Errors_c(ctx, field, obj) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + }) + case "d": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Errors_d(ctx, field, obj) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + }) + case "e": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Errors_e(ctx, field, obj) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + }) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { return graphql.Null } return out @@ -6206,7 +6530,7 @@ func (ec *executionContext) _ForcedResolver(ctx context.Context, sel ast.Selecti fields := graphql.CollectFields(ec.RequestContext, sel, forcedResolverImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -6227,7 +6551,7 @@ func (ec *executionContext) _ForcedResolver(ctx context.Context, sel ast.Selecti } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -6239,7 +6563,7 @@ func (ec *executionContext) _InnerObject(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, innerObjectImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -6247,14 +6571,14 @@ func (ec *executionContext) _InnerObject(ctx context.Context, sel ast.SelectionS case "id": out.Values[i] = ec._InnerObject_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -6266,7 +6590,7 @@ func (ec *executionContext) _InvalidIdentifier(ctx context.Context, sel ast.Sele fields := graphql.CollectFields(ec.RequestContext, sel, invalidIdentifierImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -6274,14 +6598,14 @@ func (ec *executionContext) _InvalidIdentifier(ctx context.Context, sel ast.Sele case "id": out.Values[i] = ec._InvalidIdentifier_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -6293,7 +6617,7 @@ func (ec *executionContext) _It(ctx context.Context, sel ast.SelectionSet, obj * fields := graphql.CollectFields(ec.RequestContext, sel, itImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -6301,14 +6625,14 @@ func (ec *executionContext) _It(ctx context.Context, sel ast.SelectionSet, obj * case "id": out.Values[i] = ec._It_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -6320,7 +6644,7 @@ func (ec *executionContext) _LoopA(ctx context.Context, sel ast.SelectionSet, ob fields := graphql.CollectFields(ec.RequestContext, sel, loopAImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -6328,14 +6652,14 @@ func (ec *executionContext) _LoopA(ctx context.Context, sel ast.SelectionSet, ob case "b": out.Values[i] = ec._LoopA_b(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -6347,7 +6671,7 @@ func (ec *executionContext) _LoopB(ctx context.Context, sel ast.SelectionSet, ob fields := graphql.CollectFields(ec.RequestContext, sel, loopBImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -6355,14 +6679,14 @@ func (ec *executionContext) _LoopB(ctx context.Context, sel ast.SelectionSet, ob case "a": out.Values[i] = ec._LoopB_a(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -6374,7 +6698,7 @@ func (ec *executionContext) _Map(ctx context.Context, sel ast.SelectionSet, obj fields := graphql.CollectFields(ec.RequestContext, sel, mapImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -6382,14 +6706,14 @@ func (ec *executionContext) _Map(ctx context.Context, sel ast.SelectionSet, obj case "id": out.Values[i] = ec._Map_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -6401,7 +6725,7 @@ func (ec *executionContext) _MapStringInterfaceType(ctx context.Context, sel ast fields := graphql.CollectFields(ec.RequestContext, sel, mapStringInterfaceTypeImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -6415,7 +6739,7 @@ func (ec *executionContext) _MapStringInterfaceType(ctx context.Context, sel ast } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -6427,7 +6751,7 @@ func (ec *executionContext) _ModelMethods(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ec.RequestContext, sel, modelMethodsImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -6442,14 +6766,14 @@ func (ec *executionContext) _ModelMethods(ctx context.Context, sel ast.Selection }() res = ec._ModelMethods_resolverField(ctx, field, obj) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) case "noContext": out.Values[i] = ec._ModelMethods_noContext(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "withContext": field := field @@ -6461,7 +6785,7 @@ func (ec *executionContext) _ModelMethods(ctx context.Context, sel ast.Selection }() res = ec._ModelMethods_withContext(ctx, field, obj) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -6470,7 +6794,7 @@ func (ec *executionContext) _ModelMethods(ctx context.Context, sel ast.Selection } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -6482,7 +6806,7 @@ func (ec *executionContext) _OuterObject(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, outerObjectImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -6490,14 +6814,14 @@ func (ec *executionContext) _OuterObject(ctx context.Context, sel ast.SelectionS case "inner": out.Values[i] = ec._OuterObject_inner(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -6509,7 +6833,7 @@ func (ec *executionContext) _OverlappingFields(ctx context.Context, sel ast.Sele fields := graphql.CollectFields(ec.RequestContext, sel, overlappingFieldsImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -6517,12 +6841,12 @@ func (ec *executionContext) _OverlappingFields(ctx context.Context, sel ast.Sele case "oneFoo": out.Values[i] = ec._OverlappingFields_oneFoo(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "twoFoo": out.Values[i] = ec._OverlappingFields_twoFoo(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "oldFoo": field := field @@ -6534,26 +6858,26 @@ func (ec *executionContext) _OverlappingFields(ctx context.Context, sel ast.Sele }() res = ec._OverlappingFields_oldFoo(ctx, field, obj) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) case "newFoo": out.Values[i] = ec._OverlappingFields_newFoo(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "new_foo": out.Values[i] = ec._OverlappingFields_new_foo(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -6565,7 +6889,7 @@ func (ec *executionContext) _Panics(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ec.RequestContext, sel, panicsImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -6580,7 +6904,7 @@ func (ec *executionContext) _Panics(ctx context.Context, sel ast.SelectionSet, o }() res = ec._Panics_fieldScalarMarshal(ctx, field, obj) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -6594,7 +6918,7 @@ func (ec *executionContext) _Panics(ctx context.Context, sel ast.SelectionSet, o }() res = ec._Panics_fieldFuncMarshal(ctx, field, obj) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -6608,7 +6932,7 @@ func (ec *executionContext) _Panics(ctx context.Context, sel ast.SelectionSet, o }() res = ec._Panics_argUnmarshal(ctx, field, obj) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -6617,7 +6941,7 @@ func (ec *executionContext) _Panics(ctx context.Context, sel ast.SelectionSet, o } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -6633,7 +6957,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -6715,17 +7039,6 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr res = ec._Query_shapes(ctx, field) return res }) - case "errorBubble": - field := field - out.Concurrently(i, func() (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._Query_errorBubble(ctx, field) - return res - }) case "modelMethods": field := field out.Concurrently(i, func() (res graphql.Marshaler) { @@ -6737,20 +7050,6 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr res = ec._Query_modelMethods(ctx, field) return res }) - case "valid": - field := field - out.Concurrently(i, func() (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._Query_valid(ctx, field) - if res == graphql.Null { - invalid = true - } - return res - }) case "user": field := field out.Concurrently(i, func() (res graphql.Marshaler) { @@ -6761,7 +7060,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }() res = ec._Query_user(ctx, field) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -6841,7 +7140,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }() res = ec._Query_inputSlice(ctx, field) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -6855,7 +7154,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }() res = ec._Query_shapeUnion(ctx, field) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -6880,7 +7179,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }() res = ec._Query_deprecatedField(ctx, field) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -6906,6 +7205,42 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr res = ec._Query_mapStringInterface(ctx, field) return res }) + case "errorBubble": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_errorBubble(ctx, field) + return res + }) + case "errors": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_errors(ctx, field) + return res + }) + case "valid": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_valid(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + }) case "panics": field := field out.Concurrently(i, func() (res graphql.Marshaler) { @@ -6927,7 +7262,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }() res = ec._Query_defaultScalar(ctx, field) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -6952,7 +7287,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }() res = ec._Query_scalarSlice(ctx, field) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -6966,7 +7301,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }() res = ec._Query_fallback(ctx, field) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -7001,7 +7336,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -7013,7 +7348,7 @@ func (ec *executionContext) _Rectangle(ctx context.Context, sel ast.SelectionSet fields := graphql.CollectFields(ec.RequestContext, sel, rectangleImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -7029,7 +7364,7 @@ func (ec *executionContext) _Rectangle(ctx context.Context, sel ast.SelectionSet } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -7041,7 +7376,7 @@ func (ec *executionContext) _Slices(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ec.RequestContext, sel, slicesImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -7053,19 +7388,19 @@ func (ec *executionContext) _Slices(ctx context.Context, sel ast.SelectionSet, o case "test3": out.Values[i] = ec._Slices_test3(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "test4": out.Values[i] = ec._Slices_test4(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -7099,7 +7434,7 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj fields := graphql.CollectFields(ec.RequestContext, sel, userImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -7107,7 +7442,7 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj case "id": out.Values[i] = ec._User_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "friends": field := field @@ -7119,14 +7454,14 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj }() res = ec._User_friends(ctx, field, obj) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) case "created": out.Values[i] = ec._User_created(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "updated": out.Values[i] = ec._User_updated(ctx, field, obj) @@ -7135,7 +7470,7 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -7147,7 +7482,7 @@ func (ec *executionContext) _ValidType(ctx context.Context, sel ast.SelectionSet fields := graphql.CollectFields(ec.RequestContext, sel, validTypeImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -7155,29 +7490,29 @@ func (ec *executionContext) _ValidType(ctx context.Context, sel ast.SelectionSet case "differentCase": out.Values[i] = ec._ValidType_differentCase(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "different_case": out.Values[i] = ec._ValidType_different_case(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "validInputKeywords": out.Values[i] = ec._ValidType_validInputKeywords(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "validArgs": out.Values[i] = ec._ValidType_validArgs(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -7189,7 +7524,7 @@ func (ec *executionContext) _XXIt(ctx context.Context, sel ast.SelectionSet, obj fields := graphql.CollectFields(ec.RequestContext, sel, xXItImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -7197,14 +7532,14 @@ func (ec *executionContext) _XXIt(ctx context.Context, sel ast.SelectionSet, obj case "id": out.Values[i] = ec._XXIt_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -7216,7 +7551,7 @@ func (ec *executionContext) _XxIt(ctx context.Context, sel ast.SelectionSet, obj fields := graphql.CollectFields(ec.RequestContext, sel, xxItImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -7224,14 +7559,14 @@ func (ec *executionContext) _XxIt(ctx context.Context, sel ast.SelectionSet, obj case "id": out.Values[i] = ec._XxIt_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -7243,7 +7578,7 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, __DirectiveImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -7251,26 +7586,26 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec.___Directive_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "args": out.Values[i] = ec.___Directive_args(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -7282,7 +7617,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, __EnumValueImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -7290,14 +7625,14 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec.___EnumValue_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "deprecationReason": out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) @@ -7306,7 +7641,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -7318,7 +7653,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, __FieldImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -7326,24 +7661,24 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, case "name": out.Values[i] = ec.___Field_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "type": out.Values[i] = ec.___Field_type(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "isDeprecated": out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "deprecationReason": out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) @@ -7352,7 +7687,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -7364,7 +7699,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ec.RequestContext, sel, __InputValueImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -7372,14 +7707,14 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection case "name": out.Values[i] = ec.___InputValue_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "defaultValue": out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) @@ -7388,7 +7723,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -7400,7 +7735,7 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, __SchemaImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -7408,12 +7743,12 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, case "types": out.Values[i] = ec.___Schema_types(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "queryType": out.Values[i] = ec.___Schema_queryType(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "mutationType": out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) @@ -7422,14 +7757,14 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, case "directives": out.Values[i] = ec.___Schema_directives(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -7441,7 +7776,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ec.RequestContext, sel, __TypeImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -7449,7 +7784,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o case "kind": out.Values[i] = ec.___Type_kind(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "name": out.Values[i] = ec.___Type_name(ctx, field, obj) @@ -7472,7 +7807,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -7484,7 +7819,7 @@ func (ec *executionContext) _asdfIt(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ec.RequestContext, sel, asdfItImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -7492,14 +7827,14 @@ func (ec *executionContext) _asdfIt(ctx context.Context, sel ast.SelectionSet, o case "id": out.Values[i] = ec._asdfIt_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -7511,7 +7846,7 @@ func (ec *executionContext) _iIt(ctx context.Context, sel ast.SelectionSet, obj fields := graphql.CollectFields(ec.RequestContext, sel, iItImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -7519,14 +7854,14 @@ func (ec *executionContext) _iIt(ctx context.Context, sel ast.SelectionSet, obj case "id": out.Values[i] = ec._iIt_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -7578,6 +7913,20 @@ func (ec *executionContext) marshalNDefaultScalarImplementation2string(ctx conte return res } +func (ec *executionContext) marshalNError2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐError(ctx context.Context, sel ast.SelectionSet, v Error) graphql.Marshaler { + return ec._Error(ctx, sel, &v) +} + +func (ec *executionContext) marshalNError2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐError(ctx context.Context, sel ast.SelectionSet, v *Error) graphql.Marshaler { + if v == nil { + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return ec._Error(ctx, sel, v) +} + func (ec *executionContext) unmarshalNFallbackToStringEncoding2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐFallbackToStringEncoding(ctx context.Context, v interface{}) (FallbackToStringEncoding, error) { tmp, err := graphql.UnmarshalString(v) return FallbackToStringEncoding(tmp), err @@ -8246,6 +8595,17 @@ func (ec *executionContext) marshalOError2ᚖgithubᚗcomᚋ99designsᚋgqlgen return ec._Error(ctx, sel, v) } +func (ec *executionContext) marshalOErrors2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐErrors(ctx context.Context, sel ast.SelectionSet, v Errors) graphql.Marshaler { + return ec._Errors(ctx, sel, &v) +} + +func (ec *executionContext) marshalOErrors2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐErrors(ctx context.Context, sel ast.SelectionSet, v *Errors) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._Errors(ctx, sel, v) +} + func (ec *executionContext) unmarshalOFloat2float64(ctx context.Context, v interface{}) (float64, error) { return graphql.UnmarshalFloat(v) } diff --git a/codegen/testserver/gqlgen.yml b/codegen/testserver/gqlgen.yml index 83555211939..3693e1a8b12 100644 --- a/codegen/testserver/gqlgen.yml +++ b/codegen/testserver/gqlgen.yml @@ -37,6 +37,8 @@ models: friends: { resolver: true } Error: model: "github.com/99designs/gqlgen/codegen/testserver.Error" + Errors: + model: "github.com/99designs/gqlgen/codegen/testserver.Errors" EmbeddedPointer: model: "github.com/99designs/gqlgen/codegen/testserver.EmbeddedPointerModel" ThirdParty: diff --git a/codegen/testserver/models.go b/codegen/testserver/models.go index 3ee710a50fc..4cab630f187 100644 --- a/codegen/testserver/models.go +++ b/codegen/testserver/models.go @@ -21,6 +21,8 @@ func (m ModelMethods) WithContext(_ context.Context) bool { return true } +type Errors struct{} + type Error struct { ID string } diff --git a/codegen/testserver/nulls.graphql b/codegen/testserver/nulls.graphql new file mode 100644 index 00000000000..d93f6b0cf62 --- /dev/null +++ b/codegen/testserver/nulls.graphql @@ -0,0 +1,20 @@ +extend type Query { + errorBubble: Error + errors: Errors + valid: String! +} + +type Errors { + a: Error! + b: Error! + c: Error! + d: Error! + e: Error! +} + +type Error { + id: ID! + errorOnNonRequiredField: String + errorOnRequiredField: String! + nilOnRequiredField: String! +} diff --git a/codegen/testserver/nulls_test.go b/codegen/testserver/nulls_test.go index b70935db11d..a9d502a6787 100644 --- a/codegen/testserver/nulls_test.go +++ b/codegen/testserver/nulls_test.go @@ -16,6 +16,9 @@ func TestNullBubbling(t *testing.T) { return "Ok", nil } + resolvers.QueryResolver.Errors = func(ctx context.Context) (errors *Errors, e error) { + return &Errors{}, nil + } resolvers.QueryResolver.ErrorBubble = func(ctx context.Context) (i *Error, e error) { return &Error{ID: "E1234"}, nil } @@ -80,4 +83,24 @@ func TestNullBubbling(t *testing.T) { require.Nil(t, err) require.Equal(t, "Ok", *resp.NullableArg) }) + + t.Run("concurrent null detection", func(t *testing.T) { + var resp interface{} + resolvers.ErrorsResolver.A = func(ctx context.Context, obj *Errors) (i *Error, e error) { return nil, nil } + resolvers.ErrorsResolver.B = func(ctx context.Context, obj *Errors) (i *Error, e error) { return nil, nil } + resolvers.ErrorsResolver.C = func(ctx context.Context, obj *Errors) (i *Error, e error) { return nil, nil } + resolvers.ErrorsResolver.D = func(ctx context.Context, obj *Errors) (i *Error, e error) { return nil, nil } + resolvers.ErrorsResolver.E = func(ctx context.Context, obj *Errors) (i *Error, e error) { return nil, nil } + + err := c.Post(`{ errors { + a { id }, + b { id }, + c { id }, + d { id }, + e { id }, + } }`, &resp) + + require.Error(t, err) + require.Contains(t, err.Error(), "must not be null") + }) } diff --git a/codegen/testserver/resolver.go b/codegen/testserver/resolver.go index e752629b677..e9d85ba9b24 100644 --- a/codegen/testserver/resolver.go +++ b/codegen/testserver/resolver.go @@ -11,6 +11,9 @@ import ( type Resolver struct{} +func (r *Resolver) Errors() ErrorsResolver { + return &errorsResolver{r} +} func (r *Resolver) ForcedResolver() ForcedResolverResolver { return &forcedResolverResolver{r} } @@ -33,6 +36,24 @@ func (r *Resolver) User() UserResolver { return &userResolver{r} } +type errorsResolver struct{ *Resolver } + +func (r *errorsResolver) A(ctx context.Context, obj *Errors) (*Error, error) { + panic("not implemented") +} +func (r *errorsResolver) B(ctx context.Context, obj *Errors) (*Error, error) { + panic("not implemented") +} +func (r *errorsResolver) C(ctx context.Context, obj *Errors) (*Error, error) { + panic("not implemented") +} +func (r *errorsResolver) D(ctx context.Context, obj *Errors) (*Error, error) { + panic("not implemented") +} +func (r *errorsResolver) E(ctx context.Context, obj *Errors) (*Error, error) { + panic("not implemented") +} + type forcedResolverResolver struct{ *Resolver } func (r *forcedResolverResolver) Field(ctx context.Context, obj *ForcedResolver) (*Circle, error) { @@ -83,15 +104,9 @@ func (r *queryResolver) NestedOutputs(ctx context.Context) ([][]*OuterObject, er func (r *queryResolver) Shapes(ctx context.Context) ([]Shape, error) { panic("not implemented") } -func (r *queryResolver) ErrorBubble(ctx context.Context) (*Error, error) { - panic("not implemented") -} func (r *queryResolver) ModelMethods(ctx context.Context) (*ModelMethods, error) { panic("not implemented") } -func (r *queryResolver) Valid(ctx context.Context) (string, error) { - panic("not implemented") -} func (r *queryResolver) User(ctx context.Context, id int) (*User, error) { panic("not implemented") } @@ -131,6 +146,15 @@ func (r *queryResolver) Overlapping(ctx context.Context) (*OverlappingFields, er func (r *queryResolver) MapStringInterface(ctx context.Context, in map[string]interface{}) (map[string]interface{}, error) { panic("not implemented") } +func (r *queryResolver) ErrorBubble(ctx context.Context) (*Error, error) { + panic("not implemented") +} +func (r *queryResolver) Errors(ctx context.Context) (*Errors, error) { + panic("not implemented") +} +func (r *queryResolver) Valid(ctx context.Context) (string, error) { + panic("not implemented") +} func (r *queryResolver) Panics(ctx context.Context) (*Panics, error) { panic("not implemented") } diff --git a/codegen/testserver/schema.graphql b/codegen/testserver/schema.graphql index 0b135308f2a..0fd5b598651 100644 --- a/codegen/testserver/schema.graphql +++ b/codegen/testserver/schema.graphql @@ -6,9 +6,7 @@ type Query { nestedInputs(input: [[OuterInput]] = [[{inner: {id: 1}}]]): Boolean nestedOutputs: [[OuterObject]] shapes: [Shape] - errorBubble: Error modelMethods: ModelMethods - valid: String! user(id: Int!): User! nullableArg(arg: Int = 123): String directiveArg(arg: String! @length(min:1, max: 255, message: "invalid length")): String @@ -43,13 +41,6 @@ type Autobind { idInt: ID! } -type Error { - id: ID! - errorOnNonRequiredField: String - errorOnRequiredField: String! - nilOnRequiredField: String! -} - type ModelMethods { resolverField: Boolean! noContext: Boolean! diff --git a/codegen/testserver/stub.go b/codegen/testserver/stub.go index eaebd12d323..0cd5466592d 100644 --- a/codegen/testserver/stub.go +++ b/codegen/testserver/stub.go @@ -10,6 +10,13 @@ import ( ) type Stub struct { + ErrorsResolver struct { + A func(ctx context.Context, obj *Errors) (*Error, error) + B func(ctx context.Context, obj *Errors) (*Error, error) + C func(ctx context.Context, obj *Errors) (*Error, error) + D func(ctx context.Context, obj *Errors) (*Error, error) + E func(ctx context.Context, obj *Errors) (*Error, error) + } ForcedResolverResolver struct { Field func(ctx context.Context, obj *ForcedResolver) (*Circle, error) } @@ -31,9 +38,7 @@ type Stub struct { NestedInputs func(ctx context.Context, input [][]*OuterInput) (*bool, error) NestedOutputs func(ctx context.Context) ([][]*OuterObject, error) Shapes func(ctx context.Context) ([]Shape, error) - ErrorBubble func(ctx context.Context) (*Error, error) ModelMethods func(ctx context.Context) (*ModelMethods, error) - Valid func(ctx context.Context) (string, error) User func(ctx context.Context, id int) (*User, error) NullableArg func(ctx context.Context, arg *int) (*string, error) DirectiveArg func(ctx context.Context, arg string) (*string, error) @@ -47,6 +52,9 @@ type Stub struct { DeprecatedField func(ctx context.Context) (string, error) Overlapping func(ctx context.Context) (*OverlappingFields, error) MapStringInterface func(ctx context.Context, in map[string]interface{}) (map[string]interface{}, error) + ErrorBubble func(ctx context.Context) (*Error, error) + Errors func(ctx context.Context) (*Errors, error) + Valid func(ctx context.Context) (string, error) Panics func(ctx context.Context) (*Panics, error) DefaultScalar func(ctx context.Context, arg string) (string, error) Slices func(ctx context.Context) (*Slices, error) @@ -64,6 +72,9 @@ type Stub struct { } } +func (r *Stub) Errors() ErrorsResolver { + return &stubErrors{r} +} func (r *Stub) ForcedResolver() ForcedResolverResolver { return &stubForcedResolver{r} } @@ -86,6 +97,24 @@ func (r *Stub) User() UserResolver { return &stubUser{r} } +type stubErrors struct{ *Stub } + +func (r *stubErrors) A(ctx context.Context, obj *Errors) (*Error, error) { + return r.ErrorsResolver.A(ctx, obj) +} +func (r *stubErrors) B(ctx context.Context, obj *Errors) (*Error, error) { + return r.ErrorsResolver.B(ctx, obj) +} +func (r *stubErrors) C(ctx context.Context, obj *Errors) (*Error, error) { + return r.ErrorsResolver.C(ctx, obj) +} +func (r *stubErrors) D(ctx context.Context, obj *Errors) (*Error, error) { + return r.ErrorsResolver.D(ctx, obj) +} +func (r *stubErrors) E(ctx context.Context, obj *Errors) (*Error, error) { + return r.ErrorsResolver.E(ctx, obj) +} + type stubForcedResolver struct{ *Stub } func (r *stubForcedResolver) Field(ctx context.Context, obj *ForcedResolver) (*Circle, error) { @@ -136,15 +165,9 @@ func (r *stubQuery) NestedOutputs(ctx context.Context) ([][]*OuterObject, error) func (r *stubQuery) Shapes(ctx context.Context) ([]Shape, error) { return r.QueryResolver.Shapes(ctx) } -func (r *stubQuery) ErrorBubble(ctx context.Context) (*Error, error) { - return r.QueryResolver.ErrorBubble(ctx) -} func (r *stubQuery) ModelMethods(ctx context.Context) (*ModelMethods, error) { return r.QueryResolver.ModelMethods(ctx) } -func (r *stubQuery) Valid(ctx context.Context) (string, error) { - return r.QueryResolver.Valid(ctx) -} func (r *stubQuery) User(ctx context.Context, id int) (*User, error) { return r.QueryResolver.User(ctx, id) } @@ -184,6 +207,15 @@ func (r *stubQuery) Overlapping(ctx context.Context) (*OverlappingFields, error) func (r *stubQuery) MapStringInterface(ctx context.Context, in map[string]interface{}) (map[string]interface{}, error) { return r.QueryResolver.MapStringInterface(ctx, in) } +func (r *stubQuery) ErrorBubble(ctx context.Context) (*Error, error) { + return r.QueryResolver.ErrorBubble(ctx) +} +func (r *stubQuery) Errors(ctx context.Context) (*Errors, error) { + return r.QueryResolver.Errors(ctx) +} +func (r *stubQuery) Valid(ctx context.Context) (string, error) { + return r.QueryResolver.Valid(ctx) +} func (r *stubQuery) Panics(ctx context.Context) (*Panics, error) { return r.QueryResolver.Panics(ctx) } diff --git a/example/chat/generated.go b/example/chat/generated.go index 0e547eb4dde..f13879d03cc 100644 --- a/example/chat/generated.go +++ b/example/chat/generated.go @@ -1575,7 +1575,7 @@ func (ec *executionContext) _Chatroom(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, chatroomImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1583,19 +1583,19 @@ func (ec *executionContext) _Chatroom(ctx context.Context, sel ast.SelectionSet, case "name": out.Values[i] = ec._Chatroom_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "messages": out.Values[i] = ec._Chatroom_messages(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1607,7 +1607,7 @@ func (ec *executionContext) _Message(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, messageImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1615,29 +1615,29 @@ func (ec *executionContext) _Message(ctx context.Context, sel ast.SelectionSet, case "id": out.Values[i] = ec._Message_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "text": out.Values[i] = ec._Message_text(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "createdBy": out.Values[i] = ec._Message_createdBy(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "createdAt": out.Values[i] = ec._Message_createdAt(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1653,7 +1653,7 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) }) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1661,14 +1661,14 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) case "post": out.Values[i] = ec._Mutation_post(ctx, field) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1684,7 +1684,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1709,7 +1709,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1741,7 +1741,7 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, __DirectiveImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1749,26 +1749,26 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec.___Directive_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "args": out.Values[i] = ec.___Directive_args(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1780,7 +1780,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, __EnumValueImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1788,14 +1788,14 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec.___EnumValue_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "deprecationReason": out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) @@ -1804,7 +1804,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1816,7 +1816,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, __FieldImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1824,24 +1824,24 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, case "name": out.Values[i] = ec.___Field_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "type": out.Values[i] = ec.___Field_type(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "isDeprecated": out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "deprecationReason": out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) @@ -1850,7 +1850,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1862,7 +1862,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ec.RequestContext, sel, __InputValueImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1870,14 +1870,14 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection case "name": out.Values[i] = ec.___InputValue_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "defaultValue": out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) @@ -1886,7 +1886,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1898,7 +1898,7 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, __SchemaImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1906,12 +1906,12 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, case "types": out.Values[i] = ec.___Schema_types(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "queryType": out.Values[i] = ec.___Schema_queryType(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "mutationType": out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) @@ -1920,14 +1920,14 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, case "directives": out.Values[i] = ec.___Schema_directives(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1939,7 +1939,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ec.RequestContext, sel, __TypeImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1947,7 +1947,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o case "kind": out.Values[i] = ec.___Type_kind(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "name": out.Values[i] = ec.___Type_name(ctx, field, obj) @@ -1970,7 +1970,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out diff --git a/example/config/generated.go b/example/config/generated.go index 7c72de998ed..160da9ec0f3 100644 --- a/example/config/generated.go +++ b/example/config/generated.go @@ -8,6 +8,7 @@ import ( "errors" "strconv" "sync" + "sync/atomic" "github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql/introspection" @@ -1505,7 +1506,7 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) }) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1513,14 +1514,14 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) case "createTodo": out.Values[i] = ec._Mutation_createTodo(ctx, field) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1536,7 +1537,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1551,7 +1552,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }() res = ec._Query_todos(ctx, field) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -1564,7 +1565,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1576,7 +1577,7 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj fields := graphql.CollectFields(ec.RequestContext, sel, todoImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1591,36 +1592,36 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj }() res = ec._Todo_id(ctx, field, obj) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) case "databaseId": out.Values[i] = ec._Todo_databaseId(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "text": out.Values[i] = ec._Todo_text(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "done": out.Values[i] = ec._Todo_done(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "user": out.Values[i] = ec._Todo_user(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1632,7 +1633,7 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj fields := graphql.CollectFields(ec.RequestContext, sel, userImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1640,19 +1641,19 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj case "id": out.Values[i] = ec._User_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "name": out.Values[i] = ec._User_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1664,7 +1665,7 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, __DirectiveImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1672,26 +1673,26 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec.___Directive_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "args": out.Values[i] = ec.___Directive_args(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1703,7 +1704,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, __EnumValueImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1711,14 +1712,14 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec.___EnumValue_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "deprecationReason": out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) @@ -1727,7 +1728,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1739,7 +1740,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, __FieldImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1747,24 +1748,24 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, case "name": out.Values[i] = ec.___Field_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "type": out.Values[i] = ec.___Field_type(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "isDeprecated": out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "deprecationReason": out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) @@ -1773,7 +1774,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1785,7 +1786,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ec.RequestContext, sel, __InputValueImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1793,14 +1794,14 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection case "name": out.Values[i] = ec.___InputValue_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "defaultValue": out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) @@ -1809,7 +1810,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1821,7 +1822,7 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, __SchemaImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1829,12 +1830,12 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, case "types": out.Values[i] = ec.___Schema_types(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "queryType": out.Values[i] = ec.___Schema_queryType(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "mutationType": out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) @@ -1843,14 +1844,14 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, case "directives": out.Values[i] = ec.___Schema_directives(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1862,7 +1863,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ec.RequestContext, sel, __TypeImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1870,7 +1871,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o case "kind": out.Values[i] = ec.___Type_kind(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "name": out.Values[i] = ec.___Type_name(ctx, field, obj) @@ -1893,7 +1894,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out diff --git a/example/dataloader/generated.go b/example/dataloader/generated.go index b4da41f3888..0236490c9c9 100644 --- a/example/dataloader/generated.go +++ b/example/dataloader/generated.go @@ -8,6 +8,7 @@ import ( "errors" "strconv" "sync" + "sync/atomic" "time" "github.com/99designs/gqlgen/graphql" @@ -1695,7 +1696,7 @@ func (ec *executionContext) _Address(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, addressImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1703,24 +1704,24 @@ func (ec *executionContext) _Address(ctx context.Context, sel ast.SelectionSet, case "id": out.Values[i] = ec._Address_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "street": out.Values[i] = ec._Address_street(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "country": out.Values[i] = ec._Address_country(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1732,7 +1733,7 @@ func (ec *executionContext) _Customer(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, customerImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1740,12 +1741,12 @@ func (ec *executionContext) _Customer(ctx context.Context, sel ast.SelectionSet, case "id": out.Values[i] = ec._Customer_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "name": out.Values[i] = ec._Customer_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "address": field := field @@ -1774,7 +1775,7 @@ func (ec *executionContext) _Customer(ctx context.Context, sel ast.SelectionSet, } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1786,7 +1787,7 @@ func (ec *executionContext) _Item(ctx context.Context, sel ast.SelectionSet, obj fields := graphql.CollectFields(ec.RequestContext, sel, itemImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1794,14 +1795,14 @@ func (ec *executionContext) _Item(ctx context.Context, sel ast.SelectionSet, obj case "name": out.Values[i] = ec._Item_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1813,7 +1814,7 @@ func (ec *executionContext) _Order(ctx context.Context, sel ast.SelectionSet, ob fields := graphql.CollectFields(ec.RequestContext, sel, orderImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1821,17 +1822,17 @@ func (ec *executionContext) _Order(ctx context.Context, sel ast.SelectionSet, ob case "id": out.Values[i] = ec._Order_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "date": out.Values[i] = ec._Order_date(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "amount": out.Values[i] = ec._Order_amount(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "items": field := field @@ -1849,7 +1850,7 @@ func (ec *executionContext) _Order(ctx context.Context, sel ast.SelectionSet, ob } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1865,7 +1866,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1912,7 +1913,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1924,7 +1925,7 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, __DirectiveImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1932,26 +1933,26 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec.___Directive_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "args": out.Values[i] = ec.___Directive_args(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1963,7 +1964,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, __EnumValueImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1971,14 +1972,14 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec.___EnumValue_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "deprecationReason": out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) @@ -1987,7 +1988,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1999,7 +2000,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, __FieldImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -2007,24 +2008,24 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, case "name": out.Values[i] = ec.___Field_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "type": out.Values[i] = ec.___Field_type(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "isDeprecated": out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "deprecationReason": out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) @@ -2033,7 +2034,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -2045,7 +2046,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ec.RequestContext, sel, __InputValueImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -2053,14 +2054,14 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection case "name": out.Values[i] = ec.___InputValue_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "defaultValue": out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) @@ -2069,7 +2070,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -2081,7 +2082,7 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, __SchemaImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -2089,12 +2090,12 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, case "types": out.Values[i] = ec.___Schema_types(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "queryType": out.Values[i] = ec.___Schema_queryType(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "mutationType": out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) @@ -2103,14 +2104,14 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, case "directives": out.Values[i] = ec.___Schema_directives(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -2122,7 +2123,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ec.RequestContext, sel, __TypeImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -2130,7 +2131,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o case "kind": out.Values[i] = ec.___Type_kind(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "name": out.Values[i] = ec.___Type_name(ctx, field, obj) @@ -2153,7 +2154,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out diff --git a/example/fileupload/generated.go b/example/fileupload/generated.go index b1dd3a545eb..b7a85666b25 100644 --- a/example/fileupload/generated.go +++ b/example/fileupload/generated.go @@ -8,6 +8,7 @@ import ( "errors" "strconv" "sync" + "sync/atomic" "github.com/99designs/gqlgen/example/fileupload/model" "github.com/99designs/gqlgen/graphql" @@ -1544,7 +1545,7 @@ func (ec *executionContext) _File(ctx context.Context, sel ast.SelectionSet, obj fields := graphql.CollectFields(ec.RequestContext, sel, fileImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1552,24 +1553,24 @@ func (ec *executionContext) _File(ctx context.Context, sel ast.SelectionSet, obj case "id": out.Values[i] = ec._File_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "name": out.Values[i] = ec._File_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "content": out.Values[i] = ec._File_content(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1585,7 +1586,7 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) }) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1593,29 +1594,29 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) case "singleUpload": out.Values[i] = ec._Mutation_singleUpload(ctx, field) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "singleUploadWithPayload": out.Values[i] = ec._Mutation_singleUploadWithPayload(ctx, field) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "multipleUpload": out.Values[i] = ec._Mutation_multipleUpload(ctx, field) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "multipleUploadWithPayload": out.Values[i] = ec._Mutation_multipleUploadWithPayload(ctx, field) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1631,7 +1632,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1646,7 +1647,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }() res = ec._Query_empty(ctx, field) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -1659,7 +1660,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1671,7 +1672,7 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, __DirectiveImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1679,26 +1680,26 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec.___Directive_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "args": out.Values[i] = ec.___Directive_args(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1710,7 +1711,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, __EnumValueImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1718,14 +1719,14 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec.___EnumValue_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "deprecationReason": out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) @@ -1734,7 +1735,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1746,7 +1747,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, __FieldImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1754,24 +1755,24 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, case "name": out.Values[i] = ec.___Field_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "type": out.Values[i] = ec.___Field_type(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "isDeprecated": out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "deprecationReason": out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) @@ -1780,7 +1781,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1792,7 +1793,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ec.RequestContext, sel, __InputValueImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1800,14 +1801,14 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection case "name": out.Values[i] = ec.___InputValue_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "defaultValue": out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) @@ -1816,7 +1817,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1828,7 +1829,7 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, __SchemaImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1836,12 +1837,12 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, case "types": out.Values[i] = ec.___Schema_types(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "queryType": out.Values[i] = ec.___Schema_queryType(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "mutationType": out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) @@ -1850,14 +1851,14 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, case "directives": out.Values[i] = ec.___Schema_directives(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1869,7 +1870,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ec.RequestContext, sel, __TypeImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1877,7 +1878,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o case "kind": out.Values[i] = ec.___Type_kind(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "name": out.Values[i] = ec.___Type_name(ctx, field, obj) @@ -1900,7 +1901,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out diff --git a/example/scalars/generated.go b/example/scalars/generated.go index 5b6cfc70955..e73b28e8a12 100644 --- a/example/scalars/generated.go +++ b/example/scalars/generated.go @@ -8,6 +8,7 @@ import ( "errors" "strconv" "sync" + "sync/atomic" "time" "github.com/99designs/gqlgen/example/scalars/external" @@ -1618,7 +1619,7 @@ func (ec *executionContext) _Address(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, addressImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1626,7 +1627,7 @@ func (ec *executionContext) _Address(ctx context.Context, sel ast.SelectionSet, case "id": out.Values[i] = ec._Address_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "location": out.Values[i] = ec._Address_location(ctx, field, obj) @@ -1635,7 +1636,7 @@ func (ec *executionContext) _Address(ctx context.Context, sel ast.SelectionSet, } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1651,7 +1652,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1677,7 +1678,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }() res = ec._Query_search(ctx, field) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -1690,7 +1691,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1702,7 +1703,7 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj fields := graphql.CollectFields(ec.RequestContext, sel, userImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1710,19 +1711,19 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj case "id": out.Values[i] = ec._User_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "name": out.Values[i] = ec._User_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "created": out.Values[i] = ec._User_created(ctx, field, obj) case "isBanned": out.Values[i] = ec._User_isBanned(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "primitiveResolver": field := field @@ -1734,7 +1735,7 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj }() res = ec._User_primitiveResolver(ctx, field, obj) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -1748,7 +1749,7 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj }() res = ec._User_customResolver(ctx, field, obj) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -1761,7 +1762,7 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1773,7 +1774,7 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, __DirectiveImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1781,26 +1782,26 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec.___Directive_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "args": out.Values[i] = ec.___Directive_args(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1812,7 +1813,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, __EnumValueImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1820,14 +1821,14 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec.___EnumValue_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "deprecationReason": out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) @@ -1836,7 +1837,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1848,7 +1849,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, __FieldImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1856,24 +1857,24 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, case "name": out.Values[i] = ec.___Field_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "type": out.Values[i] = ec.___Field_type(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "isDeprecated": out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "deprecationReason": out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) @@ -1882,7 +1883,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1894,7 +1895,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ec.RequestContext, sel, __InputValueImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1902,14 +1903,14 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection case "name": out.Values[i] = ec.___InputValue_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "defaultValue": out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) @@ -1918,7 +1919,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1930,7 +1931,7 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, __SchemaImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1938,12 +1939,12 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, case "types": out.Values[i] = ec.___Schema_types(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "queryType": out.Values[i] = ec.___Schema_queryType(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "mutationType": out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) @@ -1952,14 +1953,14 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, case "directives": out.Values[i] = ec.___Schema_directives(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1971,7 +1972,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ec.RequestContext, sel, __TypeImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1979,7 +1980,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o case "kind": out.Values[i] = ec.___Type_kind(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "name": out.Values[i] = ec.___Type_name(ctx, field, obj) @@ -2002,7 +2003,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out diff --git a/example/selection/generated.go b/example/selection/generated.go index e7315d522c6..26c3ef43848 100644 --- a/example/selection/generated.go +++ b/example/selection/generated.go @@ -1429,7 +1429,7 @@ func (ec *executionContext) _Like(ctx context.Context, sel ast.SelectionSet, obj fields := graphql.CollectFields(ec.RequestContext, sel, likeImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1437,12 +1437,12 @@ func (ec *executionContext) _Like(ctx context.Context, sel ast.SelectionSet, obj case "reaction": out.Values[i] = ec._Like_reaction(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "sent": out.Values[i] = ec._Like_sent(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "selection": out.Values[i] = ec._Like_selection(ctx, field, obj) @@ -1453,7 +1453,7 @@ func (ec *executionContext) _Like(ctx context.Context, sel ast.SelectionSet, obj } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1465,7 +1465,7 @@ func (ec *executionContext) _Post(ctx context.Context, sel ast.SelectionSet, obj fields := graphql.CollectFields(ec.RequestContext, sel, postImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1473,12 +1473,12 @@ func (ec *executionContext) _Post(ctx context.Context, sel ast.SelectionSet, obj case "message": out.Values[i] = ec._Post_message(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "sent": out.Values[i] = ec._Post_sent(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "selection": out.Values[i] = ec._Post_selection(ctx, field, obj) @@ -1489,7 +1489,7 @@ func (ec *executionContext) _Post(ctx context.Context, sel ast.SelectionSet, obj } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1505,7 +1505,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1530,7 +1530,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1542,7 +1542,7 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, __DirectiveImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1550,26 +1550,26 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec.___Directive_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "args": out.Values[i] = ec.___Directive_args(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1581,7 +1581,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, __EnumValueImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1589,14 +1589,14 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec.___EnumValue_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "deprecationReason": out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) @@ -1605,7 +1605,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1617,7 +1617,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, __FieldImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1625,24 +1625,24 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, case "name": out.Values[i] = ec.___Field_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "type": out.Values[i] = ec.___Field_type(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "isDeprecated": out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "deprecationReason": out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) @@ -1651,7 +1651,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1663,7 +1663,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ec.RequestContext, sel, __InputValueImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1671,14 +1671,14 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection case "name": out.Values[i] = ec.___InputValue_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "defaultValue": out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) @@ -1687,7 +1687,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1699,7 +1699,7 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, __SchemaImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1707,12 +1707,12 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, case "types": out.Values[i] = ec.___Schema_types(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "queryType": out.Values[i] = ec.___Schema_queryType(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "mutationType": out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) @@ -1721,14 +1721,14 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, case "directives": out.Values[i] = ec.___Schema_directives(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1740,7 +1740,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ec.RequestContext, sel, __TypeImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1748,7 +1748,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o case "kind": out.Values[i] = ec.___Type_kind(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "name": out.Values[i] = ec.___Type_name(ctx, field, obj) @@ -1771,7 +1771,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out diff --git a/example/starwars/generated/exec.go b/example/starwars/generated/exec.go index 3de5c9922aa..1310d7dc0ef 100644 --- a/example/starwars/generated/exec.go +++ b/example/starwars/generated/exec.go @@ -9,6 +9,7 @@ import ( "fmt" "strconv" "sync" + "sync/atomic" "time" "github.com/99designs/gqlgen/example/starwars/models" @@ -2976,7 +2977,7 @@ func (ec *executionContext) _Droid(ctx context.Context, sel ast.SelectionSet, ob fields := graphql.CollectFields(ec.RequestContext, sel, droidImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -2984,12 +2985,12 @@ func (ec *executionContext) _Droid(ctx context.Context, sel ast.SelectionSet, ob case "id": out.Values[i] = ec._Droid_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "name": out.Values[i] = ec._Droid_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "friends": field := field @@ -3012,14 +3013,14 @@ func (ec *executionContext) _Droid(ctx context.Context, sel ast.SelectionSet, ob }() res = ec._Droid_friendsConnection(ctx, field, obj) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) case "appearsIn": out.Values[i] = ec._Droid_appearsIn(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "primaryFunction": out.Values[i] = ec._Droid_primaryFunction(ctx, field, obj) @@ -3028,7 +3029,7 @@ func (ec *executionContext) _Droid(ctx context.Context, sel ast.SelectionSet, ob } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -3040,7 +3041,7 @@ func (ec *executionContext) _FriendsConnection(ctx context.Context, sel ast.Sele fields := graphql.CollectFields(ec.RequestContext, sel, friendsConnectionImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -3048,7 +3049,7 @@ func (ec *executionContext) _FriendsConnection(ctx context.Context, sel ast.Sele case "totalCount": out.Values[i] = ec._FriendsConnection_totalCount(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "edges": field := field @@ -3075,14 +3076,14 @@ func (ec *executionContext) _FriendsConnection(ctx context.Context, sel ast.Sele case "pageInfo": out.Values[i] = ec._FriendsConnection_pageInfo(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -3094,7 +3095,7 @@ func (ec *executionContext) _FriendsEdge(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, friendsEdgeImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -3102,7 +3103,7 @@ func (ec *executionContext) _FriendsEdge(ctx context.Context, sel ast.SelectionS case "cursor": out.Values[i] = ec._FriendsEdge_cursor(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "node": out.Values[i] = ec._FriendsEdge_node(ctx, field, obj) @@ -3111,7 +3112,7 @@ func (ec *executionContext) _FriendsEdge(ctx context.Context, sel ast.SelectionS } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -3123,7 +3124,7 @@ func (ec *executionContext) _Human(ctx context.Context, sel ast.SelectionSet, ob fields := graphql.CollectFields(ec.RequestContext, sel, humanImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -3131,17 +3132,17 @@ func (ec *executionContext) _Human(ctx context.Context, sel ast.SelectionSet, ob case "id": out.Values[i] = ec._Human_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "name": out.Values[i] = ec._Human_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "height": out.Values[i] = ec._Human_height(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "mass": out.Values[i] = ec._Human_mass(ctx, field, obj) @@ -3166,14 +3167,14 @@ func (ec *executionContext) _Human(ctx context.Context, sel ast.SelectionSet, ob }() res = ec._Human_friendsConnection(ctx, field, obj) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) case "appearsIn": out.Values[i] = ec._Human_appearsIn(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "starships": field := field @@ -3191,7 +3192,7 @@ func (ec *executionContext) _Human(ctx context.Context, sel ast.SelectionSet, ob } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -3207,7 +3208,7 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) }) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -3219,7 +3220,7 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -3231,7 +3232,7 @@ func (ec *executionContext) _PageInfo(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, pageInfoImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -3239,24 +3240,24 @@ func (ec *executionContext) _PageInfo(ctx context.Context, sel ast.SelectionSet, case "startCursor": out.Values[i] = ec._PageInfo_startCursor(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "endCursor": out.Values[i] = ec._PageInfo_endCursor(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "hasNextPage": out.Values[i] = ec._PageInfo_hasNextPage(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -3272,7 +3273,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -3298,7 +3299,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }() res = ec._Query_reviews(ctx, field) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -3312,7 +3313,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }() res = ec._Query_search(ctx, field) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -3369,7 +3370,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -3381,7 +3382,7 @@ func (ec *executionContext) _Review(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ec.RequestContext, sel, reviewImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -3389,7 +3390,7 @@ func (ec *executionContext) _Review(ctx context.Context, sel ast.SelectionSet, o case "stars": out.Values[i] = ec._Review_stars(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "commentary": out.Values[i] = ec._Review_commentary(ctx, field, obj) @@ -3400,7 +3401,7 @@ func (ec *executionContext) _Review(ctx context.Context, sel ast.SelectionSet, o } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -3412,7 +3413,7 @@ func (ec *executionContext) _Starship(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, starshipImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -3420,12 +3421,12 @@ func (ec *executionContext) _Starship(ctx context.Context, sel ast.SelectionSet, case "id": out.Values[i] = ec._Starship_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "name": out.Values[i] = ec._Starship_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "length": field := field @@ -3437,21 +3438,21 @@ func (ec *executionContext) _Starship(ctx context.Context, sel ast.SelectionSet, }() res = ec._Starship_length(ctx, field, obj) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) case "history": out.Values[i] = ec._Starship_history(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -3463,7 +3464,7 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, __DirectiveImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -3471,26 +3472,26 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec.___Directive_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "args": out.Values[i] = ec.___Directive_args(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -3502,7 +3503,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, __EnumValueImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -3510,14 +3511,14 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec.___EnumValue_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "deprecationReason": out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) @@ -3526,7 +3527,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -3538,7 +3539,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, __FieldImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -3546,24 +3547,24 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, case "name": out.Values[i] = ec.___Field_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "type": out.Values[i] = ec.___Field_type(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "isDeprecated": out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "deprecationReason": out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) @@ -3572,7 +3573,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -3584,7 +3585,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ec.RequestContext, sel, __InputValueImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -3592,14 +3593,14 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection case "name": out.Values[i] = ec.___InputValue_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "defaultValue": out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) @@ -3608,7 +3609,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -3620,7 +3621,7 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, __SchemaImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -3628,12 +3629,12 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, case "types": out.Values[i] = ec.___Schema_types(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "queryType": out.Values[i] = ec.___Schema_queryType(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "mutationType": out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) @@ -3642,14 +3643,14 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, case "directives": out.Values[i] = ec.___Schema_directives(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -3661,7 +3662,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ec.RequestContext, sel, __TypeImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -3669,7 +3670,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o case "kind": out.Values[i] = ec.___Type_kind(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "name": out.Values[i] = ec.___Type_name(ctx, field, obj) @@ -3692,7 +3693,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out diff --git a/example/todo/generated.go b/example/todo/generated.go index ec150f1a6a0..3631a2bdc5b 100644 --- a/example/todo/generated.go +++ b/example/todo/generated.go @@ -8,6 +8,7 @@ import ( "errors" "strconv" "sync" + "sync/atomic" "github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql/introspection" @@ -1563,7 +1564,7 @@ func (ec *executionContext) _MyMutation(ctx context.Context, sel ast.SelectionSe }) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1571,7 +1572,7 @@ func (ec *executionContext) _MyMutation(ctx context.Context, sel ast.SelectionSe case "createTodo": out.Values[i] = ec._MyMutation_createTodo(ctx, field) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "updateTodo": out.Values[i] = ec._MyMutation_updateTodo(ctx, field) @@ -1580,7 +1581,7 @@ func (ec *executionContext) _MyMutation(ctx context.Context, sel ast.SelectionSe } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1596,7 +1597,7 @@ func (ec *executionContext) _MyQuery(ctx context.Context, sel ast.SelectionSet) }) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1633,7 +1634,7 @@ func (ec *executionContext) _MyQuery(ctx context.Context, sel ast.SelectionSet) }() res = ec._MyQuery_todos(ctx, field) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -1646,7 +1647,7 @@ func (ec *executionContext) _MyQuery(ctx context.Context, sel ast.SelectionSet) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1658,7 +1659,7 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj fields := graphql.CollectFields(ec.RequestContext, sel, todoImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1666,24 +1667,24 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj case "id": out.Values[i] = ec._Todo_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "text": out.Values[i] = ec._Todo_text(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "done": out.Values[i] = ec._Todo_done(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1695,7 +1696,7 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, __DirectiveImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1703,26 +1704,26 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec.___Directive_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "args": out.Values[i] = ec.___Directive_args(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1734,7 +1735,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, __EnumValueImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1742,14 +1743,14 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec.___EnumValue_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "deprecationReason": out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) @@ -1758,7 +1759,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1770,7 +1771,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, __FieldImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1778,24 +1779,24 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, case "name": out.Values[i] = ec.___Field_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "type": out.Values[i] = ec.___Field_type(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "isDeprecated": out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "deprecationReason": out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) @@ -1804,7 +1805,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1816,7 +1817,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ec.RequestContext, sel, __InputValueImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1824,14 +1825,14 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection case "name": out.Values[i] = ec.___InputValue_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "defaultValue": out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) @@ -1840,7 +1841,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1852,7 +1853,7 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, __SchemaImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1860,12 +1861,12 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, case "types": out.Values[i] = ec.___Schema_types(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "queryType": out.Values[i] = ec.___Schema_queryType(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "mutationType": out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) @@ -1874,14 +1875,14 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, case "directives": out.Values[i] = ec.___Schema_directives(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1893,7 +1894,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ec.RequestContext, sel, __TypeImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1901,7 +1902,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o case "kind": out.Values[i] = ec.___Type_kind(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "name": out.Values[i] = ec.___Type_name(ctx, field, obj) @@ -1924,7 +1925,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out diff --git a/example/type-system-extension/generated.go b/example/type-system-extension/generated.go index ea5a77c238e..59e21935626 100644 --- a/example/type-system-extension/generated.go +++ b/example/type-system-extension/generated.go @@ -9,6 +9,7 @@ import ( "fmt" "strconv" "sync" + "sync/atomic" "github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql/introspection" @@ -1588,7 +1589,7 @@ func (ec *executionContext) _MyMutation(ctx context.Context, sel ast.SelectionSe }) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1596,14 +1597,14 @@ func (ec *executionContext) _MyMutation(ctx context.Context, sel ast.SelectionSe case "createTodo": out.Values[i] = ec._MyMutation_createTodo(ctx, field) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1619,7 +1620,7 @@ func (ec *executionContext) _MyQuery(ctx context.Context, sel ast.SelectionSet) }) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1634,7 +1635,7 @@ func (ec *executionContext) _MyQuery(ctx context.Context, sel ast.SelectionSet) }() res = ec._MyQuery_todos(ctx, field) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -1658,7 +1659,7 @@ func (ec *executionContext) _MyQuery(ctx context.Context, sel ast.SelectionSet) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1670,7 +1671,7 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj fields := graphql.CollectFields(ec.RequestContext, sel, todoImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1678,29 +1679,29 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj case "id": out.Values[i] = ec._Todo_id(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "text": out.Values[i] = ec._Todo_text(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "state": out.Values[i] = ec._Todo_state(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "verified": out.Values[i] = ec._Todo_verified(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1712,7 +1713,7 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, __DirectiveImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1720,26 +1721,26 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec.___Directive_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "args": out.Values[i] = ec.___Directive_args(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1751,7 +1752,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, __EnumValueImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1759,14 +1760,14 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec.___EnumValue_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "deprecationReason": out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) @@ -1775,7 +1776,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1787,7 +1788,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, __FieldImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1795,24 +1796,24 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, case "name": out.Values[i] = ec.___Field_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "type": out.Values[i] = ec.___Field_type(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "isDeprecated": out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "deprecationReason": out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) @@ -1821,7 +1822,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1833,7 +1834,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ec.RequestContext, sel, __InputValueImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1841,14 +1842,14 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection case "name": out.Values[i] = ec.___InputValue_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "defaultValue": out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) @@ -1857,7 +1858,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1869,7 +1870,7 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, __SchemaImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1877,12 +1878,12 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, case "types": out.Values[i] = ec.___Schema_types(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "queryType": out.Values[i] = ec.___Schema_queryType(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "mutationType": out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) @@ -1891,14 +1892,14 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, case "directives": out.Values[i] = ec.___Schema_directives(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1910,7 +1911,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ec.RequestContext, sel, __TypeImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1918,7 +1919,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o case "kind": out.Values[i] = ec.___Type_kind(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "name": out.Values[i] = ec.___Type_name(ctx, field, obj) @@ -1941,7 +1942,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out diff --git a/integration/generated.go b/integration/generated.go index 46881f41436..36c283c220d 100644 --- a/integration/generated.go +++ b/integration/generated.go @@ -8,6 +8,7 @@ import ( "errors" "strconv" "sync" + "sync/atomic" "github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql/introspection" @@ -1713,7 +1714,7 @@ func (ec *executionContext) _Element(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, elementImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1728,7 +1729,7 @@ func (ec *executionContext) _Element(ctx context.Context, sel ast.SelectionSet, }() res = ec._Element_child(ctx, field, obj) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -1742,7 +1743,7 @@ func (ec *executionContext) _Element(ctx context.Context, sel ast.SelectionSet, }() res = ec._Element_error(ctx, field, obj) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -1762,7 +1763,7 @@ func (ec *executionContext) _Element(ctx context.Context, sel ast.SelectionSet, } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1778,7 +1779,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1804,7 +1805,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }() res = ec._Query_date(ctx, field) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -1829,7 +1830,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }() res = ec._Query_jsonEncoding(ctx, field) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -1843,7 +1844,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }() res = ec._Query_error(ctx, field) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -1857,7 +1858,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }() res = ec._Query_complexity(ctx, field) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -1870,7 +1871,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1882,7 +1883,7 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj fields := graphql.CollectFields(ec.RequestContext, sel, userImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1890,7 +1891,7 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj case "name": out.Values[i] = ec._User_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } case "likes": field := field @@ -1902,7 +1903,7 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj }() res = ec._User_likes(ctx, field, obj) if res == graphql.Null { - invalid = true + atomic.AddUint32(&invalids, 1) } return res }) @@ -1911,7 +1912,7 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1923,7 +1924,7 @@ func (ec *executionContext) _Viewer(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ec.RequestContext, sel, viewerImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1935,7 +1936,7 @@ func (ec *executionContext) _Viewer(ctx context.Context, sel ast.SelectionSet, o } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1947,7 +1948,7 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, __DirectiveImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1955,26 +1956,26 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec.___Directive_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "args": out.Values[i] = ec.___Directive_args(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -1986,7 +1987,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ec.RequestContext, sel, __EnumValueImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -1994,14 +1995,14 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec.___EnumValue_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "deprecationReason": out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) @@ -2010,7 +2011,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -2022,7 +2023,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, __FieldImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -2030,24 +2031,24 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, case "name": out.Values[i] = ec.___Field_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "type": out.Values[i] = ec.___Field_type(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "isDeprecated": out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "deprecationReason": out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) @@ -2056,7 +2057,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -2068,7 +2069,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ec.RequestContext, sel, __InputValueImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -2076,14 +2077,14 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection case "name": out.Values[i] = ec.___InputValue_name(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + 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 { - invalid = true + invalids++ } case "defaultValue": out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) @@ -2092,7 +2093,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -2104,7 +2105,7 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ec.RequestContext, sel, __SchemaImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -2112,12 +2113,12 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, case "types": out.Values[i] = ec.___Schema_types(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "queryType": out.Values[i] = ec.___Schema_queryType(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "mutationType": out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) @@ -2126,14 +2127,14 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, case "directives": out.Values[i] = ec.___Schema_directives(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out @@ -2145,7 +2146,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ec.RequestContext, sel, __TypeImplementors) out := graphql.NewFieldSet(fields) - invalid := false + var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": @@ -2153,7 +2154,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o case "kind": out.Values[i] = ec.___Type_kind(ctx, field, obj) if out.Values[i] == graphql.Null { - invalid = true + invalids++ } case "name": out.Values[i] = ec.___Type_name(ctx, field, obj) @@ -2176,7 +2177,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o } } out.Dispatch() - if invalid { + if invalids > 0 { return graphql.Null } return out