From 6f3d73103dae0fa8f409b8b869421ba1c57f3e90 Mon Sep 17 00:00:00 2001 From: vvakame Date: Sun, 30 Jun 2019 10:24:47 +0900 Subject: [PATCH] Fix pointer returns from directive --- codegen/args.gotpl | 4 + codegen/field.gotpl | 5 + codegen/input.gotpl | 4 + codegen/testserver/directive.graphql | 10 +- codegen/testserver/directive_test.go | 31 ++- codegen/testserver/generated.go | 277 ++++++++++++++++++++++++++- codegen/testserver/models-gen.go | 6 + codegen/testserver/resolver.go | 5 +- codegen/testserver/stub.go | 10 +- 9 files changed, 340 insertions(+), 12 deletions(-) diff --git a/codegen/args.gotpl b/codegen/args.gotpl index c76bf0f764..318f1ff451 100644 --- a/codegen/args.gotpl +++ b/codegen/args.gotpl @@ -14,6 +14,10 @@ func (ec *executionContext) {{ $name }}(ctx context.Context, rawArgs map[string] } if data, ok := tmp.({{ $arg.TypeReference.GO | ref }}) ; ok { arg{{$i}} = data + {{- if $arg.TypeReference.IsNilable }} + } else if tmp == nil { + arg{{$i}} = nil + {{- end }} } else { return nil, fmt.Errorf(`unexpected type %T from directive, should be {{ $arg.TypeReference.GO }}`, tmp) } diff --git a/codegen/field.gotpl b/codegen/field.gotpl index c0f6fcae0d..1970614be2 100644 --- a/codegen/field.gotpl +++ b/codegen/field.gotpl @@ -107,6 +107,11 @@ 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/input.gotpl b/codegen/input.gotpl index b51d53a262..bdf3622caf 100644 --- a/codegen/input.gotpl +++ b/codegen/input.gotpl @@ -25,6 +25,10 @@ } if data, ok := tmp.({{ $field.TypeReference.GO | ref }}) ; ok { it.{{$field.GoFieldName}} = data + {{- if $field.TypeReference.IsNilable }} + } else if tmp == nil { + it.{{$field.GoFieldName}} = nil + {{- end }} } else { return it, fmt.Errorf(`unexpected type %T from directive, should be {{ $field.TypeReference.GO }}`, tmp) } diff --git a/codegen/testserver/directive.graphql b/codegen/testserver/directive.graphql index b2cc8501a6..531f5aec80 100644 --- a/codegen/testserver/directive.graphql +++ b/codegen/testserver/directive.graphql @@ -2,19 +2,22 @@ directive @length(min: Int!, max: Int, message: String) on ARGUMENT_DEFINITION | directive @range(min: Int = 0, max: Int) on ARGUMENT_DEFINITION directive @custom on ARGUMENT_DEFINITION directive @logged(id: UUID!) on FIELD +directive @toNull on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | FIELD_DEFINITION extend type Query { directiveArg(arg: String! @length(min:1, max: 255, message: "invalid length")): String - directiveNullableArg(arg: Int @range(min:0), arg2: Int @range): String + directiveNullableArg(arg: Int @range(min:0), arg2: Int @range, arg3: String @toNull): String directiveInputNullable(arg: InputDirectives): String directiveInput(arg: InputDirectives!): String directiveInputType(arg: InnerInput! @custom): String + directiveObject: ObjectDirectives directiveFieldDef(ret: String!): String! @length(min: 1, message: "not valid") directiveField: String } input InputDirectives { text: String! @length(min: 0, max: 7, message: "not valid") + nullableText: String @toNull inner: InnerDirectives! innerNullable: InnerDirectives thirdParty: ThirdParty @length(min: 0, max: 7) @@ -23,3 +26,8 @@ input InputDirectives { input InnerDirectives { message: String! @length(min: 1, message: "not valid") } + +type ObjectDirectives { + text: String! @length(min: 0, max: 7, message: "not valid") + nullableText: String @toNull +} diff --git a/codegen/testserver/directive_test.go b/codegen/testserver/directive_test.go index 9867b12705..894930ff87 100644 --- a/codegen/testserver/directive_test.go +++ b/codegen/testserver/directive_test.go @@ -29,7 +29,7 @@ func TestDirectives(t *testing.T) { return &s, nil } - resolvers.QueryResolver.DirectiveNullableArg = func(ctx context.Context, arg *int, arg2 *int) (i *string, e error) { + resolvers.QueryResolver.DirectiveNullableArg = func(ctx context.Context, arg *int, arg2 *int, arg3 *string) (*string, error) { s := "Ok" return &s, nil } @@ -39,6 +39,14 @@ func TestDirectives(t *testing.T) { return &s, nil } + resolvers.QueryResolver.DirectiveObject = func(ctx context.Context) (*ObjectDirectives, error) { + s := "Ok" + return &ObjectDirectives{ + Text: s, + NullableText: &s, + }, nil + } + resolvers.QueryResolver.DirectiveField = func(ctx context.Context) (*string, error) { if s, ok := ctx.Value("request_id").(*string); ok { return s, nil @@ -115,6 +123,9 @@ func TestDirectives(t *testing.T) { Logged: func(ctx context.Context, obj interface{}, next graphql.Resolver, id string) (interface{}, error) { return next(context.WithValue(ctx, "request_id", &id)) }, + ToNull: func(ctx context.Context, obj interface{}, next graphql.Resolver) (interface{}, error) { + return nil, nil + }, }, }), handler.ResolverMiddleware(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) { @@ -271,7 +282,7 @@ func TestDirectives(t *testing.T) { DirectiveInputNullable *string } - err := c.Post(`query { directiveInputNullable(arg: {text:"23",inner:{message:"1"},innerNullable:{message:"success"}}) }`, &resp) + err := c.Post(`query { directiveInputNullable(arg: {text:"23",nullableText:"23",inner:{message:"1"},innerNullable:{message:"success"}}) }`, &resp) require.Nil(t, err) require.Equal(t, "Ok", *resp.DirectiveInputNullable) @@ -287,4 +298,20 @@ func TestDirectives(t *testing.T) { require.Equal(t, "Ok", *resp.DirectiveInputType) }) }) + t.Run("object field directives", func(t *testing.T) { + t.Run("when function success", func(t *testing.T) { + var resp struct { + DirectiveObject *struct { + Text string + NullableText *string + } + } + + err := c.Post(`query { directiveObject{ text nullableText } }`, &resp) + + require.Nil(t, err) + require.Equal(t, "Ok", resp.DirectiveObject.Text) + require.True(t, resp.DirectiveObject.NullableText == nil) + }) + }) } diff --git a/codegen/testserver/generated.go b/codegen/testserver/generated.go index 97a5e10d0f..36fc211e2f 100644 --- a/codegen/testserver/generated.go +++ b/codegen/testserver/generated.go @@ -59,6 +59,8 @@ type DirectiveRoot struct { Logged func(ctx context.Context, obj interface{}, next graphql.Resolver, id string) (res interface{}, err error) Range func(ctx context.Context, obj interface{}, next graphql.Resolver, min *int, max *int) (res interface{}, err error) + + ToNull func(ctx context.Context, obj interface{}, next graphql.Resolver) (res interface{}, err error) } type ComplexityRoot struct { @@ -162,6 +164,11 @@ type ComplexityRoot struct { WithContext func(childComplexity int) int } + ObjectDirectives struct { + NullableText func(childComplexity int) int + Text func(childComplexity int) int + } + OuterObject struct { Inner func(childComplexity int) int } @@ -200,7 +207,8 @@ type ComplexityRoot struct { 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) 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 @@ -328,10 +336,11 @@ type QueryResolver interface { DeprecatedField(ctx context.Context) (string, error) Overlapping(ctx context.Context) (*OverlappingFields, error) DirectiveArg(ctx context.Context, arg string) (*string, error) - DirectiveNullableArg(ctx context.Context, arg *int, arg2 *int) (*string, error) + DirectiveNullableArg(ctx context.Context, arg *int, arg2 *int, arg3 *string) (*string, error) DirectiveInputNullable(ctx context.Context, arg *InputDirectives) (*string, error) DirectiveInput(ctx context.Context, arg InputDirectives) (*string, error) DirectiveInputType(ctx context.Context, arg InnerInput) (*string, error) + DirectiveObject(ctx context.Context) (*ObjectDirectives, error) DirectiveFieldDef(ctx context.Context, ret string) (string, error) DirectiveField(ctx context.Context) (*string, error) MapStringInterface(ctx context.Context, in map[string]interface{}) (map[string]interface{}, error) @@ -632,6 +641,20 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.ModelMethods.WithContext(childComplexity), true + case "ObjectDirectives.nullableText": + if e.complexity.ObjectDirectives.NullableText == nil { + break + } + + return e.complexity.ObjectDirectives.NullableText(childComplexity), true + + case "ObjectDirectives.text": + if e.complexity.ObjectDirectives.Text == nil { + break + } + + return e.complexity.ObjectDirectives.Text(childComplexity), true + case "OuterObject.inner": if e.complexity.OuterObject.Inner == nil { break @@ -836,7 +859,14 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Query.DirectiveNullableArg(childComplexity, args["arg"].(*int), args["arg2"].(*int)), true + return e.complexity.Query.DirectiveNullableArg(childComplexity, args["arg"].(*int), args["arg2"].(*int), args["arg3"].(*string)), true + + case "Query.directiveObject": + if e.complexity.Query.DirectiveObject == nil { + break + } + + return e.complexity.Query.DirectiveObject(childComplexity), true case "Query.errorBubble": if e.complexity.Query.ErrorBubble == nil { @@ -1327,19 +1357,22 @@ type OverlappingFields { directive @range(min: Int = 0, max: Int) on ARGUMENT_DEFINITION directive @custom on ARGUMENT_DEFINITION directive @logged(id: UUID!) on FIELD +directive @toNull on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | FIELD_DEFINITION extend type Query { directiveArg(arg: String! @length(min:1, max: 255, message: "invalid length")): String - directiveNullableArg(arg: Int @range(min:0), arg2: Int @range): String + directiveNullableArg(arg: Int @range(min:0), arg2: Int @range, arg3: String @toNull): String directiveInputNullable(arg: InputDirectives): String directiveInput(arg: InputDirectives!): String directiveInputType(arg: InnerInput! @custom): String + directiveObject: ObjectDirectives directiveFieldDef(ret: String!): String! @length(min: 1, message: "not valid") directiveField: String } input InputDirectives { text: String! @length(min: 0, max: 7, message: "not valid") + nullableText: String @toNull inner: InnerDirectives! innerNullable: InnerDirectives thirdParty: ThirdParty @length(min: 0, max: 7) @@ -1348,6 +1381,11 @@ input InputDirectives { input InnerDirectives { message: String! @length(min: 1, message: "not valid") } + +type ObjectDirectives { + text: String! @length(min: 0, max: 7, message: "not valid") + nullableText: String @toNull +} `}, &ast.Source{Name: "loops.graphql", Input: `type LoopA { b: LoopB! @@ -1928,6 +1966,8 @@ func (ec *executionContext) field_Query_directiveNullableArg_args(ctx context.Co } if data, ok := tmp.(*int); ok { arg0 = data + } else if tmp == nil { + arg0 = nil } else { return nil, fmt.Errorf(`unexpected type %T from directive, should be *int`, tmp) } @@ -1949,11 +1989,32 @@ func (ec *executionContext) field_Query_directiveNullableArg_args(ctx context.Co } if data, ok := tmp.(*int); ok { arg1 = data + } else if tmp == nil { + arg1 = nil } else { return nil, fmt.Errorf(`unexpected type %T from directive, should be *int`, tmp) } } args["arg2"] = arg1 + var arg2 *string + if tmp, ok := rawArgs["arg3"]; ok { + directive0 := func(ctx context.Context) (interface{}, error) { return ec.unmarshalOString2ᚖstring(ctx, tmp) } + directive1 := func(ctx context.Context) (interface{}, error) { + return ec.directives.ToNull(ctx, rawArgs, directive0) + } + tmp, err = directive1(ctx) + if err != nil { + return nil, err + } + if data, ok := tmp.(*string); ok { + arg2 = data + } else if tmp == nil { + arg2 = nil + } else { + return nil, fmt.Errorf(`unexpected type %T from directive, should be *string`, tmp) + } + } + args["arg3"] = arg2 return args, nil } @@ -3601,6 +3662,111 @@ func (ec *executionContext) _ModelMethods_withContext(ctx context.Context, field return ec.marshalNBoolean2bool(ctx, field.Selections, res) } +func (ec *executionContext) _ObjectDirectives_text(ctx context.Context, field graphql.CollectedField, obj *ObjectDirectives) (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: "ObjectDirectives", + 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.Text, nil + } + directive1 := func(ctx context.Context) (interface{}, error) { + min, err := ec.unmarshalNInt2int(ctx, 0) + if err != nil { + return nil, err + } + max, err := ec.unmarshalOInt2ᚖint(ctx, 7) + if err != nil { + return nil, err + } + message, err := ec.unmarshalOString2ᚖstring(ctx, "not valid") + if err != nil { + return nil, err + } + return ec.directives.Length(ctx, obj, directive0, min, max, message) + } + tmp, err := directive1(rctx) + if err != nil { + return nil, err + } + 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 { + 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) _ObjectDirectives_nullableText(ctx context.Context, field graphql.CollectedField, obj *ObjectDirectives) (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: "ObjectDirectives", + 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 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) + }) + + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2ᚖstring(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() { @@ -4674,7 +4840,7 @@ func (ec *executionContext) _Query_directiveNullableArg(ctx context.Context, fie 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().DirectiveNullableArg(rctx, args["arg"].(*int), args["arg2"].(*int)) + return ec.resolvers.Query().DirectiveNullableArg(rctx, args["arg"].(*int), args["arg2"].(*int), args["arg3"].(*string)) }) if resTmp == nil { @@ -4800,6 +4966,37 @@ func (ec *executionContext) _Query_directiveInputType(ctx context.Context, field return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } +func (ec *executionContext) _Query_directiveObject(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().DirectiveObject(rctx) + }) + + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*ObjectDirectives) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOObjectDirectives2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐObjectDirectives(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() { @@ -7345,6 +7542,23 @@ func (ec *executionContext) unmarshalInputInputDirectives(ctx context.Context, o } else { return it, fmt.Errorf(`unexpected type %T from directive, should be string`, tmp) } + case "nullableText": + var err error + directive0 := func(ctx context.Context) (interface{}, error) { return ec.unmarshalOString2ᚖstring(ctx, v) } + directive1 := func(ctx context.Context) (interface{}, error) { + return ec.directives.ToNull(ctx, obj, directive0) + } + tmp, err := directive1(ctx) + if err != nil { + return it, err + } + if data, ok := tmp.(*string); ok { + it.NullableText = data + } else if tmp == nil { + it.NullableText = nil + } else { + return it, fmt.Errorf(`unexpected type %T from directive, should be *string`, tmp) + } case "inner": var err error it.Inner, err = ec.unmarshalNInnerDirectives2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐInnerDirectives(ctx, v) @@ -7379,6 +7593,8 @@ func (ec *executionContext) unmarshalInputInputDirectives(ctx context.Context, o } if data, ok := tmp.(*ThirdParty); ok { it.ThirdParty = data + } else if tmp == nil { + it.ThirdParty = nil } else { return it, fmt.Errorf(`unexpected type %T from directive, should be *github.com/99designs/gqlgen/codegen/testserver.ThirdParty`, tmp) } @@ -8346,6 +8562,35 @@ func (ec *executionContext) _ModelMethods(ctx context.Context, sel ast.Selection return out } +var objectDirectivesImplementors = []string{"ObjectDirectives"} + +func (ec *executionContext) _ObjectDirectives(ctx context.Context, sel ast.SelectionSet, obj *ObjectDirectives) graphql.Marshaler { + fields := graphql.CollectFields(ec.RequestContext, sel, objectDirectivesImplementors) + + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("ObjectDirectives") + case "text": + out.Values[i] = ec._ObjectDirectives_text(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "nullableText": + out.Values[i] = ec._ObjectDirectives_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 { @@ -8836,6 +9081,17 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr res = ec._Query_directiveInputType(ctx, field) return res }) + case "directiveObject": + 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_directiveObject(ctx, field) + return res + }) case "directiveFieldDef": field := field out.Concurrently(i, func() (res graphql.Marshaler) { @@ -10583,6 +10839,17 @@ func (ec *executionContext) marshalOModelMethods2ᚖgithubᚗcomᚋ99designsᚋg return ec._ModelMethods(ctx, sel, v) } +func (ec *executionContext) marshalOObjectDirectives2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐObjectDirectives(ctx context.Context, sel ast.SelectionSet, v ObjectDirectives) graphql.Marshaler { + return ec._ObjectDirectives(ctx, sel, &v) +} + +func (ec *executionContext) marshalOObjectDirectives2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐObjectDirectives(ctx context.Context, sel ast.SelectionSet, v *ObjectDirectives) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._ObjectDirectives(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/models-gen.go b/codegen/testserver/models-gen.go index 5d6ad0e41a..d8921745ed 100644 --- a/codegen/testserver/models-gen.go +++ b/codegen/testserver/models-gen.go @@ -67,6 +67,7 @@ type InnerObject struct { type InputDirectives struct { Text string `json:"text"` + NullableText *string `json:"nullableText"` Inner *InnerDirectives `json:"inner"` InnerNullable *InnerDirectives `json:"innerNullable"` ThirdParty *ThirdParty `json:"thirdParty"` @@ -86,6 +87,11 @@ type Map struct { ID string `json:"id"` } +type ObjectDirectives struct { + Text string `json:"text"` + NullableText *string `json:"nullableText"` +} + type OuterInput struct { Inner *InnerInput `json:"inner"` } diff --git a/codegen/testserver/resolver.go b/codegen/testserver/resolver.go index 0af7087630..d151d4f6b3 100644 --- a/codegen/testserver/resolver.go +++ b/codegen/testserver/resolver.go @@ -152,7 +152,7 @@ func (r *queryResolver) Overlapping(ctx context.Context) (*OverlappingFields, er func (r *queryResolver) DirectiveArg(ctx context.Context, arg string) (*string, error) { panic("not implemented") } -func (r *queryResolver) DirectiveNullableArg(ctx context.Context, arg *int, arg2 *int) (*string, error) { +func (r *queryResolver) DirectiveNullableArg(ctx context.Context, arg *int, arg2 *int, arg3 *string) (*string, error) { panic("not implemented") } func (r *queryResolver) DirectiveInputNullable(ctx context.Context, arg *InputDirectives) (*string, error) { @@ -164,6 +164,9 @@ func (r *queryResolver) DirectiveInput(ctx context.Context, arg InputDirectives) func (r *queryResolver) DirectiveInputType(ctx context.Context, arg InnerInput) (*string, error) { panic("not implemented") } +func (r *queryResolver) DirectiveObject(ctx context.Context) (*ObjectDirectives, 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 4c79fed9eb..8f80cd800a 100644 --- a/codegen/testserver/stub.go +++ b/codegen/testserver/stub.go @@ -54,10 +54,11 @@ type Stub struct { 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) (*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) MapStringInterface func(ctx context.Context, in map[string]interface{}) (map[string]interface{}, error) @@ -226,8 +227,8 @@ func (r *stubQuery) Overlapping(ctx context.Context) (*OverlappingFields, error) func (r *stubQuery) DirectiveArg(ctx context.Context, arg string) (*string, error) { return r.QueryResolver.DirectiveArg(ctx, arg) } -func (r *stubQuery) DirectiveNullableArg(ctx context.Context, arg *int, arg2 *int) (*string, error) { - return r.QueryResolver.DirectiveNullableArg(ctx, arg, arg2) +func (r *stubQuery) DirectiveNullableArg(ctx context.Context, arg *int, arg2 *int, arg3 *string) (*string, error) { + return r.QueryResolver.DirectiveNullableArg(ctx, arg, arg2, arg3) } func (r *stubQuery) DirectiveInputNullable(ctx context.Context, arg *InputDirectives) (*string, error) { return r.QueryResolver.DirectiveInputNullable(ctx, arg) @@ -238,6 +239,9 @@ func (r *stubQuery) DirectiveInput(ctx context.Context, arg InputDirectives) (*s func (r *stubQuery) DirectiveInputType(ctx context.Context, arg InnerInput) (*string, error) { return r.QueryResolver.DirectiveInputType(ctx, arg) } +func (r *stubQuery) DirectiveObject(ctx context.Context) (*ObjectDirectives, error) { + return r.QueryResolver.DirectiveObject(ctx) +} func (r *stubQuery) DirectiveFieldDef(ctx context.Context, ret string) (string, error) { return r.QueryResolver.DirectiveFieldDef(ctx, ret) }