From 94ad3f2e92e0fd7ffc99566f3c4e1abe7a616acc Mon Sep 17 00:00:00 2001 From: vvakame Date: Sat, 17 Aug 2019 13:41:26 +0900 Subject: [PATCH] fix directives return nil handling --- codegen/field.gotpl | 8 +- codegen/testserver/directive.graphql | 5 + codegen/testserver/directive_test.go | 19 ++ codegen/testserver/generated.go | 244 +++++++++++++++++---- codegen/testserver/gqlgen.yml | 2 + codegen/testserver/models.go | 4 + codegen/testserver/resolver.go | 3 + codegen/testserver/stub.go | 82 +++---- example/todo/generated.go | 3 + example/type-system-extension/generated.go | 3 + 10 files changed, 286 insertions(+), 87 deletions(-) diff --git a/codegen/field.gotpl b/codegen/field.gotpl index 1970614be27..04986c8e15f 100644 --- a/codegen/field.gotpl +++ b/codegen/field.gotpl @@ -104,14 +104,12 @@ if err != nil { return nil, err } + if tmp == nil { + return nil, nil + } if data, ok := tmp.({{ .TypeReference.GO | ref }}) ; ok { return data, nil } - {{- if .TypeReference.IsNilable -}} - else if tmp == nil { - return nil, nil - } - {{- end }} return nil, fmt.Errorf(`unexpected type %T from directive, should be {{ .TypeReference.GO }}`, tmp) {{- else -}} ctx = rctx // use context from middleware stack in children diff --git a/codegen/testserver/directive.graphql b/codegen/testserver/directive.graphql index 6058d8756ea..c3173805478 100644 --- a/codegen/testserver/directive.graphql +++ b/codegen/testserver/directive.graphql @@ -13,6 +13,7 @@ extend type Query { directiveInput(arg: InputDirectives!): String directiveInputType(arg: InnerInput! @custom): String directiveObject: ObjectDirectives + directiveObjectWithCustomGoModel: ObjectDirectivesWithCustomGoModel directiveFieldDef(ret: String!): String! @length(min: 1, message: "not valid") directiveField: String directiveDouble: String @directive1 @directive2 @@ -34,3 +35,7 @@ type ObjectDirectives { text: String! @length(min: 0, max: 7, message: "not valid") nullableText: String @toNull } + +type ObjectDirectivesWithCustomGoModel { + nullableText: String @toNull +} diff --git a/codegen/testserver/directive_test.go b/codegen/testserver/directive_test.go index e4815d3707c..b605acf6e34 100644 --- a/codegen/testserver/directive_test.go +++ b/codegen/testserver/directive_test.go @@ -47,6 +47,13 @@ func TestDirectives(t *testing.T) { }, nil } + resolvers.QueryResolver.DirectiveObjectWithCustomGoModel = func(ctx context.Context) (*ObjectDirectivesWithCustomGoModel, error) { + s := "Ok" + return &ObjectDirectivesWithCustomGoModel{ + NullableText: s, + }, nil + } + resolvers.QueryResolver.DirectiveField = func(ctx context.Context) (*string, error) { if s, ok := ctx.Value("request_id").(*string); ok { return s, nil @@ -334,5 +341,17 @@ func TestDirectives(t *testing.T) { require.Equal(t, "Ok", resp.DirectiveObject.Text) require.True(t, resp.DirectiveObject.NullableText == nil) }) + t.Run("when directive returns nil & custom go field is not nilable", func(t *testing.T) { + var resp struct { + DirectiveObjectWithCustomGoModel *struct { + NullableText *string + } + } + + err := c.Post(`query { directiveObjectWithCustomGoModel{ nullableText } }`, &resp) + + require.Nil(t, err) + require.True(t, resp.DirectiveObjectWithCustomGoModel.NullableText == nil) + }) }) } diff --git a/codegen/testserver/generated.go b/codegen/testserver/generated.go index 72fef86ffce..b8fc77803cd 100644 --- a/codegen/testserver/generated.go +++ b/codegen/testserver/generated.go @@ -173,6 +173,10 @@ type ComplexityRoot struct { Text func(childComplexity int) int } + ObjectDirectivesWithCustomGoModel struct { + NullableText func(childComplexity int) int + } + OuterObject struct { Inner func(childComplexity int) int } @@ -201,45 +205,46 @@ type ComplexityRoot struct { } Query struct { - Autobind func(childComplexity int) int - Collision func(childComplexity int) int - DefaultScalar func(childComplexity int, arg string) int - DeprecatedField func(childComplexity int) int - DirectiveArg func(childComplexity int, arg string) int - DirectiveDouble func(childComplexity int) int - DirectiveField func(childComplexity int) int - DirectiveFieldDef func(childComplexity int, ret string) int - DirectiveInput func(childComplexity int, arg InputDirectives) int - DirectiveInputNullable func(childComplexity int, arg *InputDirectives) int - DirectiveInputType func(childComplexity int, arg InnerInput) int - DirectiveNullableArg func(childComplexity int, arg *int, arg2 *int, arg3 *string) int - DirectiveObject func(childComplexity 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 - MapInput func(childComplexity int, input map[string]interface{}) int - MapStringInterface func(childComplexity int, in map[string]interface{}) int - ModelMethods func(childComplexity int) int - NestedInputs func(childComplexity int, input [][]*OuterInput) int - NestedOutputs func(childComplexity int) int - NullableArg func(childComplexity int, arg *int) int - OptionalUnion func(childComplexity int) int - Overlapping func(childComplexity int) int - Panics func(childComplexity int) int - PrimitiveObject func(childComplexity int) int - PrimitiveStringObject func(childComplexity int) int - Recursive func(childComplexity int, input *RecursiveInputSlice) int - ScalarSlice func(childComplexity int) int - ShapeUnion func(childComplexity int) int - Shapes func(childComplexity int) int - Slices func(childComplexity int) int - User func(childComplexity int, id int) int - Valid func(childComplexity int) int - ValidType func(childComplexity int) int - WrappedScalar func(childComplexity int) int - WrappedStruct func(childComplexity int) int + Autobind func(childComplexity int) int + Collision func(childComplexity int) int + DefaultScalar func(childComplexity int, arg string) int + DeprecatedField func(childComplexity int) int + DirectiveArg func(childComplexity int, arg string) int + DirectiveDouble func(childComplexity int) int + DirectiveField func(childComplexity int) int + DirectiveFieldDef func(childComplexity int, ret string) int + DirectiveInput func(childComplexity int, arg InputDirectives) int + DirectiveInputNullable func(childComplexity int, arg *InputDirectives) int + DirectiveInputType func(childComplexity int, arg InnerInput) int + DirectiveNullableArg func(childComplexity int, arg *int, arg2 *int, arg3 *string) int + DirectiveObject func(childComplexity int) int + DirectiveObjectWithCustomGoModel func(childComplexity 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 + MapInput func(childComplexity int, input map[string]interface{}) int + MapStringInterface func(childComplexity int, in map[string]interface{}) int + ModelMethods func(childComplexity int) int + NestedInputs func(childComplexity int, input [][]*OuterInput) int + NestedOutputs func(childComplexity int) int + NullableArg func(childComplexity int, arg *int) int + OptionalUnion func(childComplexity int) int + Overlapping func(childComplexity int) int + Panics func(childComplexity int) int + PrimitiveObject func(childComplexity int) int + PrimitiveStringObject func(childComplexity int) int + Recursive func(childComplexity int, input *RecursiveInputSlice) int + ScalarSlice func(childComplexity int) int + ShapeUnion func(childComplexity int) int + Shapes func(childComplexity int) int + Slices func(childComplexity int) int + User func(childComplexity int, id int) int + Valid func(childComplexity int) int + ValidType func(childComplexity int) int + WrappedScalar func(childComplexity int) int + WrappedStruct func(childComplexity int) int } Rectangle struct { @@ -346,6 +351,7 @@ type QueryResolver interface { DirectiveInput(ctx context.Context, arg InputDirectives) (*string, error) DirectiveInputType(ctx context.Context, arg InnerInput) (*string, error) DirectiveObject(ctx context.Context) (*ObjectDirectives, error) + DirectiveObjectWithCustomGoModel(ctx context.Context) (*ObjectDirectivesWithCustomGoModel, error) DirectiveFieldDef(ctx context.Context, ret string) (string, error) DirectiveField(ctx context.Context) (*string, error) DirectiveDouble(ctx context.Context) (*string, error) @@ -661,6 +667,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.ObjectDirectives.Text(childComplexity), true + case "ObjectDirectivesWithCustomGoModel.nullableText": + if e.complexity.ObjectDirectivesWithCustomGoModel.NullableText == nil { + break + } + + return e.complexity.ObjectDirectivesWithCustomGoModel.NullableText(childComplexity), true + case "OuterObject.inner": if e.complexity.OuterObject.Inner == nil { break @@ -881,6 +894,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.DirectiveObject(childComplexity), true + case "Query.directiveObjectWithCustomGoModel": + if e.complexity.Query.DirectiveObjectWithCustomGoModel == nil { + break + } + + return e.complexity.Query.DirectiveObjectWithCustomGoModel(childComplexity), true + case "Query.errorBubble": if e.complexity.Query.ErrorBubble == nil { break @@ -1381,6 +1401,7 @@ extend type Query { directiveInput(arg: InputDirectives!): String directiveInputType(arg: InnerInput! @custom): String directiveObject: ObjectDirectives + directiveObjectWithCustomGoModel: ObjectDirectivesWithCustomGoModel directiveFieldDef(ret: String!): String! @length(min: 1, message: "not valid") directiveField: String directiveDouble: String @directive1 @directive2 @@ -1402,6 +1423,10 @@ type ObjectDirectives { text: String! @length(min: 0, max: 7, message: "not valid") nullableText: String @toNull } + +type ObjectDirectivesWithCustomGoModel { + nullableText: String @toNull +} `}, &ast.Source{Name: "loops.graphql", Input: `type LoopA { b: LoopB! @@ -3725,6 +3750,9 @@ func (ec *executionContext) _ObjectDirectives_text(ctx context.Context, field gr if err != nil { return nil, err } + if tmp == nil { + return nil, nil + } if data, ok := tmp.(string); ok { return data, nil } @@ -3773,10 +3801,11 @@ func (ec *executionContext) _ObjectDirectives_nullableText(ctx context.Context, if err != nil { return nil, err } + if tmp == nil { + return nil, nil + } if data, ok := tmp.(*string); ok { return data, nil - } else if tmp == nil { - return nil, nil } return nil, fmt.Errorf(`unexpected type %T from directive, should be *string`, tmp) }) @@ -3790,6 +3819,54 @@ func (ec *executionContext) _ObjectDirectives_nullableText(ctx context.Context, return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } +func (ec *executionContext) _ObjectDirectivesWithCustomGoModel_nullableText(ctx context.Context, field graphql.CollectedField, obj *ObjectDirectivesWithCustomGoModel) (ret graphql.Marshaler) { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + ec.Tracer.EndFieldExecution(ctx) + }() + rctx := &graphql.ResolverContext{ + Object: "ObjectDirectivesWithCustomGoModel", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + directive0 := func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.NullableText, nil + } + directive1 := func(ctx context.Context) (interface{}, error) { + return ec.directives.ToNull(ctx, obj, directive0) + } + + tmp, err := directive1(rctx) + if err != nil { + return nil, err + } + if tmp == nil { + return nil, nil + } + if data, ok := tmp.(string); ok { + return data, nil + } + return nil, fmt.Errorf(`unexpected type %T from directive, should be string`, tmp) + }) + + if resTmp == nil { + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2string(ctx, field.Selections, res) +} + func (ec *executionContext) _OuterObject_inner(ctx context.Context, field graphql.CollectedField, obj *OuterObject) (ret graphql.Marshaler) { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { @@ -5020,6 +5097,37 @@ func (ec *executionContext) _Query_directiveObject(ctx context.Context, field gr return ec.marshalOObjectDirectives2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐObjectDirectives(ctx, field.Selections, res) } +func (ec *executionContext) _Query_directiveObjectWithCustomGoModel(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + 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().DirectiveObjectWithCustomGoModel(rctx) + }) + + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*ObjectDirectivesWithCustomGoModel) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOObjectDirectivesWithCustomGoModel2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐObjectDirectivesWithCustomGoModel(ctx, field.Selections, res) +} + func (ec *executionContext) _Query_directiveFieldDef(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { @@ -5065,6 +5173,9 @@ func (ec *executionContext) _Query_directiveFieldDef(ctx context.Context, field if err != nil { return nil, err } + if tmp == nil { + return nil, nil + } if data, ok := tmp.(string); ok { return data, nil } @@ -5147,10 +5258,11 @@ func (ec *executionContext) _Query_directiveDouble(ctx context.Context, field gr if err != nil { return nil, err } + if tmp == nil { + return nil, nil + } if data, ok := tmp.(*string); ok { return data, nil - } else if tmp == nil { - return nil, nil } return nil, fmt.Errorf(`unexpected type %T from directive, should be *string`, tmp) }) @@ -8669,6 +8781,30 @@ func (ec *executionContext) _ObjectDirectives(ctx context.Context, sel ast.Selec return out } +var objectDirectivesWithCustomGoModelImplementors = []string{"ObjectDirectivesWithCustomGoModel"} + +func (ec *executionContext) _ObjectDirectivesWithCustomGoModel(ctx context.Context, sel ast.SelectionSet, obj *ObjectDirectivesWithCustomGoModel) graphql.Marshaler { + fields := graphql.CollectFields(ec.RequestContext, sel, objectDirectivesWithCustomGoModelImplementors) + + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("ObjectDirectivesWithCustomGoModel") + case "nullableText": + out.Values[i] = ec._ObjectDirectivesWithCustomGoModel_nullableText(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + var outerObjectImplementors = []string{"OuterObject"} func (ec *executionContext) _OuterObject(ctx context.Context, sel ast.SelectionSet, obj *OuterObject) graphql.Marshaler { @@ -9170,6 +9306,17 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr res = ec._Query_directiveObject(ctx, field) return res }) + case "directiveObjectWithCustomGoModel": + 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_directiveObjectWithCustomGoModel(ctx, field) + return res + }) case "directiveFieldDef": field := field out.Concurrently(i, func() (res graphql.Marshaler) { @@ -10939,6 +11086,17 @@ func (ec *executionContext) marshalOObjectDirectives2ᚖgithubᚗcomᚋ99designs return ec._ObjectDirectives(ctx, sel, v) } +func (ec *executionContext) marshalOObjectDirectivesWithCustomGoModel2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐObjectDirectivesWithCustomGoModel(ctx context.Context, sel ast.SelectionSet, v ObjectDirectivesWithCustomGoModel) graphql.Marshaler { + return ec._ObjectDirectivesWithCustomGoModel(ctx, sel, &v) +} + +func (ec *executionContext) marshalOObjectDirectivesWithCustomGoModel2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐObjectDirectivesWithCustomGoModel(ctx context.Context, sel ast.SelectionSet, v *ObjectDirectivesWithCustomGoModel) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._ObjectDirectivesWithCustomGoModel(ctx, sel, v) +} + func (ec *executionContext) unmarshalOOuterInput2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOuterInput(ctx context.Context, v interface{}) (OuterInput, error) { return ec.unmarshalInputOuterInput(ctx, v) } diff --git a/codegen/testserver/gqlgen.yml b/codegen/testserver/gqlgen.yml index 4a8292fb5bd..92434e8544e 100644 --- a/codegen/testserver/gqlgen.yml +++ b/codegen/testserver/gqlgen.yml @@ -72,6 +72,8 @@ models: oneFoo: { fieldName: foo } twoFoo: { fieldName: foo } oldFoo: { fieldName: foo, resolver: true } + ObjectDirectivesWithCustomGoModel: + model: "github.com/99designs/gqlgen/codegen/testserver.ObjectDirectivesWithCustomGoModel" FallbackToStringEncoding: model: "github.com/99designs/gqlgen/codegen/testserver.FallbackToStringEncoding" Bytes: diff --git a/codegen/testserver/models.go b/codegen/testserver/models.go index 4901100f323..bf013ed08d3 100644 --- a/codegen/testserver/models.go +++ b/codegen/testserver/models.go @@ -79,6 +79,10 @@ type OverlappingFields struct { NewFoo int } +type ObjectDirectivesWithCustomGoModel struct { + NullableText string // not *string, but schema is `String @toNull` type. +} + type FallbackToStringEncoding string const ( diff --git a/codegen/testserver/resolver.go b/codegen/testserver/resolver.go index ede989be7cd..353e11dfa6f 100644 --- a/codegen/testserver/resolver.go +++ b/codegen/testserver/resolver.go @@ -167,6 +167,9 @@ func (r *queryResolver) DirectiveInputType(ctx context.Context, arg InnerInput) func (r *queryResolver) DirectiveObject(ctx context.Context) (*ObjectDirectives, error) { panic("not implemented") } +func (r *queryResolver) DirectiveObjectWithCustomGoModel(ctx context.Context) (*ObjectDirectivesWithCustomGoModel, error) { + panic("not implemented") +} func (r *queryResolver) DirectiveFieldDef(ctx context.Context, ret string) (string, error) { panic("not implemented") } diff --git a/codegen/testserver/stub.go b/codegen/testserver/stub.go index 8ede5f353c0..e5fadd6dc10 100644 --- a/codegen/testserver/stub.go +++ b/codegen/testserver/stub.go @@ -38,45 +38,46 @@ type Stub struct { Len func(ctx context.Context, obj *PrimitiveString) (int, error) } QueryResolver struct { - InvalidIdentifier func(ctx context.Context) (*invalid_packagename.InvalidIdentifier, error) - Collision func(ctx context.Context) (*introspection1.It, error) - MapInput func(ctx context.Context, input map[string]interface{}) (*bool, error) - Recursive func(ctx context.Context, input *RecursiveInputSlice) (*bool, error) - NestedInputs func(ctx context.Context, input [][]*OuterInput) (*bool, error) - NestedOutputs func(ctx context.Context) ([][]*OuterObject, error) - Shapes func(ctx context.Context) ([]Shape, error) - ModelMethods func(ctx context.Context) (*ModelMethods, error) - User func(ctx context.Context, id int) (*User, error) - NullableArg func(ctx context.Context, arg *int) (*string, error) - InputSlice func(ctx context.Context, arg []string) (bool, error) - ShapeUnion func(ctx context.Context) (ShapeUnion, error) - Autobind func(ctx context.Context) (*Autobind, error) - DeprecatedField func(ctx context.Context) (string, error) - Overlapping func(ctx context.Context) (*OverlappingFields, error) - DirectiveArg func(ctx context.Context, arg string) (*string, error) - DirectiveNullableArg func(ctx context.Context, arg *int, arg2 *int, arg3 *string) (*string, error) - DirectiveInputNullable func(ctx context.Context, arg *InputDirectives) (*string, error) - DirectiveInput func(ctx context.Context, arg InputDirectives) (*string, error) - DirectiveInputType func(ctx context.Context, arg InnerInput) (*string, error) - DirectiveObject func(ctx context.Context) (*ObjectDirectives, error) - DirectiveFieldDef func(ctx context.Context, ret string) (string, error) - DirectiveField func(ctx context.Context) (*string, error) - DirectiveDouble func(ctx context.Context) (*string, 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) - PrimitiveObject func(ctx context.Context) ([]Primitive, error) - PrimitiveStringObject func(ctx context.Context) ([]PrimitiveString, error) - DefaultScalar func(ctx context.Context, arg string) (string, error) - Slices func(ctx context.Context) (*Slices, error) - ScalarSlice func(ctx context.Context) ([]byte, error) - Fallback func(ctx context.Context, arg FallbackToStringEncoding) (FallbackToStringEncoding, error) - OptionalUnion func(ctx context.Context) (TestUnion, error) - ValidType func(ctx context.Context) (*ValidType, error) - WrappedStruct func(ctx context.Context) (*WrappedStruct, error) - WrappedScalar func(ctx context.Context) (WrappedScalar, error) + InvalidIdentifier func(ctx context.Context) (*invalid_packagename.InvalidIdentifier, error) + Collision func(ctx context.Context) (*introspection1.It, error) + MapInput func(ctx context.Context, input map[string]interface{}) (*bool, error) + Recursive func(ctx context.Context, input *RecursiveInputSlice) (*bool, error) + NestedInputs func(ctx context.Context, input [][]*OuterInput) (*bool, error) + NestedOutputs func(ctx context.Context) ([][]*OuterObject, error) + Shapes func(ctx context.Context) ([]Shape, error) + ModelMethods func(ctx context.Context) (*ModelMethods, error) + User func(ctx context.Context, id int) (*User, error) + NullableArg func(ctx context.Context, arg *int) (*string, error) + InputSlice func(ctx context.Context, arg []string) (bool, error) + ShapeUnion func(ctx context.Context) (ShapeUnion, error) + Autobind func(ctx context.Context) (*Autobind, error) + DeprecatedField func(ctx context.Context) (string, error) + Overlapping func(ctx context.Context) (*OverlappingFields, error) + DirectiveArg func(ctx context.Context, arg string) (*string, error) + DirectiveNullableArg func(ctx context.Context, arg *int, arg2 *int, arg3 *string) (*string, error) + DirectiveInputNullable func(ctx context.Context, arg *InputDirectives) (*string, error) + DirectiveInput func(ctx context.Context, arg InputDirectives) (*string, error) + DirectiveInputType func(ctx context.Context, arg InnerInput) (*string, error) + DirectiveObject func(ctx context.Context) (*ObjectDirectives, error) + DirectiveObjectWithCustomGoModel func(ctx context.Context) (*ObjectDirectivesWithCustomGoModel, error) + DirectiveFieldDef func(ctx context.Context, ret string) (string, error) + DirectiveField func(ctx context.Context) (*string, error) + DirectiveDouble func(ctx context.Context) (*string, 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) + PrimitiveObject func(ctx context.Context) ([]Primitive, error) + PrimitiveStringObject func(ctx context.Context) ([]PrimitiveString, error) + DefaultScalar func(ctx context.Context, arg string) (string, error) + Slices func(ctx context.Context) (*Slices, error) + ScalarSlice func(ctx context.Context) ([]byte, error) + Fallback func(ctx context.Context, arg FallbackToStringEncoding) (FallbackToStringEncoding, error) + OptionalUnion func(ctx context.Context) (TestUnion, error) + ValidType func(ctx context.Context) (*ValidType, error) + WrappedStruct func(ctx context.Context) (*WrappedStruct, error) + WrappedScalar func(ctx context.Context) (WrappedScalar, error) } SubscriptionResolver struct { Updated func(ctx context.Context) (<-chan string, error) @@ -243,6 +244,9 @@ func (r *stubQuery) DirectiveInputType(ctx context.Context, arg InnerInput) (*st func (r *stubQuery) DirectiveObject(ctx context.Context) (*ObjectDirectives, error) { return r.QueryResolver.DirectiveObject(ctx) } +func (r *stubQuery) DirectiveObjectWithCustomGoModel(ctx context.Context) (*ObjectDirectivesWithCustomGoModel, error) { + return r.QueryResolver.DirectiveObjectWithCustomGoModel(ctx) +} func (r *stubQuery) DirectiveFieldDef(ctx context.Context, ret string) (string, error) { return r.QueryResolver.DirectiveFieldDef(ctx, ret) } diff --git a/example/todo/generated.go b/example/todo/generated.go index bb30fafee11..0d84800d808 100644 --- a/example/todo/generated.go +++ b/example/todo/generated.go @@ -839,6 +839,9 @@ func (ec *executionContext) _Todo_done(ctx context.Context, field graphql.Collec if err != nil { return nil, err } + if tmp == nil { + return nil, nil + } if data, ok := tmp.(bool); ok { return data, nil } diff --git a/example/type-system-extension/generated.go b/example/type-system-extension/generated.go index db8a20eefab..1908e5b3e67 100644 --- a/example/type-system-extension/generated.go +++ b/example/type-system-extension/generated.go @@ -714,6 +714,9 @@ func (ec *executionContext) _Todo_verified(ctx context.Context, field graphql.Co if err != nil { return nil, err } + if tmp == nil { + return nil, nil + } if data, ok := tmp.(bool); ok { return data, nil }