From 497551202238b0befd67d69b1da547bfff660948 Mon Sep 17 00:00:00 2001 From: Grace Noah Date: Sun, 11 Nov 2018 03:02:02 +0000 Subject: [PATCH 1/7] accept an optional ctx parameter on model methods --- codegen/object.go | 25 +++++++++++++++---------- codegen/util.go | 14 +++++++++++++- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/codegen/object.go b/codegen/object.go index c037344fe6..70a1e99ecb 100644 --- a/codegen/object.go +++ b/codegen/object.go @@ -33,16 +33,17 @@ type Object struct { type Field struct { *Type - Description string // Description of a field - GQLName string // The name of the field in graphql - GoFieldType GoFieldType // The field type in go, if any - GoReceiverName string // The name of method & var receiver in go, if any - GoFieldName string // The name of the method or var in go, if any - Args []FieldArgument // A list of arguments to be passed to this field - ForceResolver bool // Should be emit Resolver method - NoErr bool // If this is bound to a go method, does that method have an error as the second argument - Object *Object // A link back to the parent object - Default interface{} // The default value + Description string // Description of a field + GQLName string // The name of the field in graphql + GoFieldType GoFieldType // The field type in go, if any + GoReceiverName string // The name of method & var receiver in go, if any + GoFieldName string // The name of the method or var in go, if any + Args []FieldArgument // A list of arguments to be passed to this field + ForceResolver bool // Should be emit Resolver method + MethodHasContext bool // If this is bound to a go method, does the method also take a context + NoErr bool // If this is bound to a go method, does that method have an error as the second argument + Object *Object // A link back to the parent object + Default interface{} // The default value } type FieldArgument struct { @@ -209,6 +210,10 @@ func (f *Field) CallArgs() string { if !f.Object.Root { args = append(args, "obj") } + } else { + if f.MethodHasContext { + args = append(args, "ctx") + } } for _, arg := range f.Args { diff --git a/codegen/util.go b/codegen/util.go index 2ecd7c9e75..c6672bfc19 100644 --- a/codegen/util.go +++ b/codegen/util.go @@ -255,7 +255,19 @@ func bindMethod(imports *Imports, t types.Type, field *Field) error { } else if sig.Results().Len() != 2 { return fmt.Errorf("method has wrong number of args") } - newArgs, err := matchArgs(field, sig.Params()) + params := sig.Params() + // If the first argument is the context, remove it from the comparison and set + // the MethodHasContext flag so that the context will be passed to this model's method + if params.Len() > 0 && params.At(0).Type().String() == "context.Context" { + field.MethodHasContext = true + vars := make([]*types.Var, params.Len()-1) + for i := 1; i < params.Len(); i++ { + vars[i-1] = params.At(i) + } + params = types.NewTuple(vars...) + } + + newArgs, err := matchArgs(field, params) if err != nil { return err } From 602a83d6f1ac630b0abf6732375643b48f1b38db Mon Sep 17 00:00:00 2001 From: Grace Noah Date: Mon, 12 Nov 2018 18:30:32 +0000 Subject: [PATCH 2/7] make ctx method resolvers concurrent --- codegen/object.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/codegen/object.go b/codegen/object.go index 70a1e99ecb..656af297a0 100644 --- a/codegen/object.go +++ b/codegen/object.go @@ -104,7 +104,10 @@ func (f *Field) IsVariable() bool { } func (f *Field) IsConcurrent() bool { - return f.IsResolver() && !f.Object.DisableConcurrency + if f.Object.DisableConcurrency { + return false + } + return f.MethodHasContext || f.IsResolver() } func (f *Field) GoNameExported() string { From 9862c30f17df6dbcc1c3712dc3cff523950ee918 Mon Sep 17 00:00:00 2001 From: Grace Noah Date: Mon, 12 Nov 2018 18:38:27 +0000 Subject: [PATCH 3/7] mention contexts on model methods in docs --- docs/content/reference/resolvers.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/content/reference/resolvers.md b/docs/content/reference/resolvers.md index 0887f23480..ffac1046be 100644 --- a/docs/content/reference/resolvers.md +++ b/docs/content/reference/resolvers.md @@ -87,7 +87,10 @@ models: ``` Here, we see that there is a method on car with the name ```Owner```, thus the ```Owner``` function will be called if -a graphQL request includes that field to be resolved +a graphQL request includes that field to be resolved. + +Model methods can optionally take a context as their first argument. If a +context is required, the model method will also be run in parallel. ## Bind when the field names do not match From 8066edb719066f3b306b6e6165ff9e959f298deb Mon Sep 17 00:00:00 2001 From: Grace Noah Date: Tue, 13 Nov 2018 18:18:14 +0000 Subject: [PATCH 4/7] add tests --- codegen/testserver/generated.go | 212 +++++++++++++++++++++++++++ codegen/testserver/generated_test.go | 26 ++++ codegen/testserver/gqlgen.yml | 2 + codegen/testserver/models.go | 16 +- codegen/testserver/resolver.go | 12 ++ codegen/testserver/schema.graphql | 7 + 6 files changed, 274 insertions(+), 1 deletion(-) diff --git a/codegen/testserver/generated.go b/codegen/testserver/generated.go index 8b7c196cd7..64b490a25e 100644 --- a/codegen/testserver/generated.go +++ b/codegen/testserver/generated.go @@ -34,6 +34,7 @@ type Config struct { type ResolverRoot interface { ForcedResolver() ForcedResolverResolver + ModelMethods() ModelMethodsResolver Query() QueryResolver Subscription() SubscriptionResolver User() UserResolver @@ -76,6 +77,12 @@ type ComplexityRoot struct { Id func(childComplexity int) int } + ModelMethods struct { + ResolverField func(childComplexity int) int + NoContext func(childComplexity int) int + WithContext func(childComplexity int) int + } + OuterObject struct { Inner func(childComplexity int) int } @@ -90,6 +97,7 @@ type ComplexityRoot struct { Keywords func(childComplexity int, input *Keywords) int Shapes func(childComplexity int) int ErrorBubble func(childComplexity int) int + ModelMethods func(childComplexity int) int Valid func(childComplexity int) int User func(childComplexity int, id int) int NullableArg func(childComplexity int, arg *int) int @@ -116,6 +124,9 @@ type ComplexityRoot struct { type ForcedResolverResolver interface { Field(ctx context.Context, obj *ForcedResolver) (*Circle, error) } +type ModelMethodsResolver interface { + ResolverField(ctx context.Context, obj *ModelMethods) (bool, error) +} type QueryResolver interface { InvalidIdentifier(ctx context.Context) (*invalid_packagename.InvalidIdentifier, error) Collision(ctx context.Context) (*introspection1.It, error) @@ -126,6 +137,7 @@ type QueryResolver interface { Keywords(ctx context.Context, input *Keywords) (bool, 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) @@ -648,6 +660,27 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.It.Id(childComplexity), true + case "ModelMethods.resolverField": + if e.complexity.ModelMethods.ResolverField == nil { + break + } + + return e.complexity.ModelMethods.ResolverField(childComplexity), true + + case "ModelMethods.noContext": + if e.complexity.ModelMethods.NoContext == nil { + break + } + + return e.complexity.ModelMethods.NoContext(childComplexity), true + + case "ModelMethods.withContext": + if e.complexity.ModelMethods.WithContext == nil { + break + } + + return e.complexity.ModelMethods.WithContext(childComplexity), true + case "OuterObject.inner": if e.complexity.OuterObject.Inner == nil { break @@ -738,6 +771,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.ErrorBubble(childComplexity), true + case "Query.modelMethods": + if e.complexity.Query.ModelMethods == nil { + break + } + + return e.complexity.Query.ModelMethods(childComplexity), true + case "Query.valid": if e.complexity.Query.Valid == nil { break @@ -1432,6 +1472,136 @@ func (ec *executionContext) _It_id(ctx context.Context, field graphql.CollectedF return graphql.MarshalID(res) } +var modelMethodsImplementors = []string{"ModelMethods"} + +// nolint: gocyclo, errcheck, gas, goconst +func (ec *executionContext) _ModelMethods(ctx context.Context, sel ast.SelectionSet, obj *ModelMethods) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, modelMethodsImplementors) + + var wg sync.WaitGroup + out := graphql.NewOrderedMap(len(fields)) + invalid := false + for i, field := range fields { + out.Keys[i] = field.Alias + + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("ModelMethods") + case "resolverField": + wg.Add(1) + go func(i int, field graphql.CollectedField) { + out.Values[i] = ec._ModelMethods_resolverField(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + wg.Done() + }(i, field) + case "noContext": + out.Values[i] = ec._ModelMethods_noContext(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "withContext": + wg.Add(1) + go func(i int, field graphql.CollectedField) { + out.Values[i] = ec._ModelMethods_withContext(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + wg.Done() + }(i, field) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + wg.Wait() + if invalid { + return graphql.Null + } + return out +} + +// nolint: vetshadow +func (ec *executionContext) _ModelMethods_resolverField(ctx context.Context, field graphql.CollectedField, obj *ModelMethods) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer ec.Tracer.EndFieldExecution(ctx) + rctx := &graphql.ResolverContext{ + Object: "ModelMethods", + Args: nil, + Field: field, + } + 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.ModelMethods().ResolverField(rctx, obj) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return graphql.MarshalBoolean(res) +} + +// nolint: vetshadow +func (ec *executionContext) _ModelMethods_noContext(ctx context.Context, field graphql.CollectedField, obj *ModelMethods) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer ec.Tracer.EndFieldExecution(ctx) + rctx := &graphql.ResolverContext{ + Object: "ModelMethods", + Args: nil, + Field: field, + } + 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 obj.NoContext(), nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return graphql.MarshalBoolean(res) +} + +// nolint: vetshadow +func (ec *executionContext) _ModelMethods_withContext(ctx context.Context, field graphql.CollectedField, obj *ModelMethods) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer ec.Tracer.EndFieldExecution(ctx) + rctx := &graphql.ResolverContext{ + Object: "ModelMethods", + Args: nil, + Field: field, + } + 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 obj.WithContext(ctx), nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return graphql.MarshalBoolean(res) +} + var outerObjectImplementors = []string{"OuterObject"} // nolint: gocyclo, errcheck, gas, goconst @@ -1566,6 +1736,12 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr out.Values[i] = ec._Query_errorBubble(ctx, field) wg.Done() }(i, field) + case "modelMethods": + wg.Add(1) + go func(i int, field graphql.CollectedField) { + out.Values[i] = ec._Query_modelMethods(ctx, field) + wg.Done() + }(i, field) case "valid": wg.Add(1) go func(i int, field graphql.CollectedField) { @@ -1989,6 +2165,35 @@ func (ec *executionContext) _Query_errorBubble(ctx context.Context, field graphq return ec._Error(ctx, field.Selections, res) } +// nolint: vetshadow +func (ec *executionContext) _Query_modelMethods(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer ec.Tracer.EndFieldExecution(ctx) + rctx := &graphql.ResolverContext{ + Object: "Query", + Args: nil, + Field: field, + } + 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().ModelMethods(rctx) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*ModelMethods) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + + if res == nil { + return graphql.Null + } + + return ec._ModelMethods(ctx, field.Selections, res) +} + // nolint: vetshadow func (ec *executionContext) _Query_valid(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) @@ -4204,6 +4409,7 @@ var parsedSchema = gqlparser.MustLoadSchema( keywords(input: Keywords): Boolean! shapes: [Shape] errorBubble: Error + modelMethods: ModelMethods valid: String! user(id: Int!): User! nullableArg(arg: Int = 123): String @@ -4226,6 +4432,12 @@ type Error { nilOnRequiredField: String! } +type ModelMethods { + resolverField: Boolean! + noContext: Boolean! + withContext: Boolean! +} + type InvalidIdentifier { id: Int! } diff --git a/codegen/testserver/generated_test.go b/codegen/testserver/generated_test.go index cbfd54715b..a5169119a5 100644 --- a/codegen/testserver/generated_test.go +++ b/codegen/testserver/generated_test.go @@ -519,6 +519,29 @@ func TestTracer(t *testing.T) { require.NoError(t, err) require.True(t, called) }) + + t.Run("model methods", func(t *testing.T) { + t.Run("without context", func(t *testing.T) { + var resp struct { + ModelMethods struct { + NoContext bool + } + } + err := c.Post(`query { modelMethods{ noContext } }`, &resp) + require.NoError(t, err) + require.True(t, resp.ModelMethods.NoContext) + }) + t.Run("with context", func(t *testing.T) { + var resp struct { + ModelMethods struct { + WithContext bool + } + } + err := c.Post(`query { modelMethods{ withContext } }`, &resp) + require.NoError(t, err) + require.True(t, resp.ModelMethods.WithContext) + }) + }) } func TestResponseExtension(t *testing.T) { @@ -556,6 +579,9 @@ func (r *testResolver) User() UserResolver { func (r *testResolver) Query() QueryResolver { return &testQueryResolver{} } +func (r *testResolver) ModelMethods() ModelMethodsResolver { + return &modelMethodsResolver{} +} type testQueryResolver struct{ queryResolver } diff --git a/codegen/testserver/gqlgen.yml b/codegen/testserver/gqlgen.yml index 32c93d2a86..7a6e8e5674 100644 --- a/codegen/testserver/gqlgen.yml +++ b/codegen/testserver/gqlgen.yml @@ -11,6 +11,8 @@ resolver: models: It: model: "github.com/99designs/gqlgen/codegen/testserver/introspection.It" + ModelMethods: + model: "github.com/99designs/gqlgen/codegen/testserver.ModelMethods" InvalidIdentifier: model: "github.com/99designs/gqlgen/codegen/testserver/invalid-packagename.InvalidIdentifier" Changes: diff --git a/codegen/testserver/models.go b/codegen/testserver/models.go index f8cb15fd25..8647046a60 100644 --- a/codegen/testserver/models.go +++ b/codegen/testserver/models.go @@ -1,11 +1,25 @@ package testserver -import "fmt" +import ( + context "context" + "fmt" +) type ForcedResolver struct { Field Circle } +type ModelMethods struct { +} + +func (m ModelMethods) NoContext() bool { + return true +} + +func (m ModelMethods) WithContext(_ context.Context) bool { + return true +} + type Error struct { ID string } diff --git a/codegen/testserver/resolver.go b/codegen/testserver/resolver.go index 4406ed374a..d649188f1e 100644 --- a/codegen/testserver/resolver.go +++ b/codegen/testserver/resolver.go @@ -23,6 +23,15 @@ func (r *Resolver) Subscription() SubscriptionResolver { func (r *Resolver) User() UserResolver { return &userResolver{r} } +func (r *Resolver) ModelMethods() ModelMethodsResolver { + return &modelMethodsResolver{} +} + +type modelMethodsResolver struct{} + +func (r *modelMethodsResolver) ResolverField(ctx context.Context, obj *ModelMethods) (bool, error) { + return true, nil +} type forcedResolverResolver struct{ *Resolver } @@ -68,6 +77,9 @@ func (r *queryResolver) User(ctx context.Context, id int) (User, error) { func (r *queryResolver) NullableArg(ctx context.Context, arg *int) (*string, error) { panic("not implemented") } +func (r *queryResolver) ModelMethods(ctx context.Context) (*ModelMethods, error) { + return &ModelMethods{}, nil +} func (r *queryResolver) KeywordArgs(ctx context.Context, breakArg string, defaultArg string, funcArg string, interfaceArg string, selectArg string, caseArg string, deferArg string, goArg string, mapArg string, structArg string, chanArg string, elseArg string, gotoArg string, packageArg string, switchArg string, constArg string, fallthroughArg string, ifArg string, rangeArg string, typeArg string, continueArg string, forArg string, importArg string, returnArg string, varArg string) (bool, error) { panic("not implemented") } diff --git a/codegen/testserver/schema.graphql b/codegen/testserver/schema.graphql index 02a6921248..276e7130be 100644 --- a/codegen/testserver/schema.graphql +++ b/codegen/testserver/schema.graphql @@ -8,6 +8,7 @@ type Query { keywords(input: Keywords): Boolean! shapes: [Shape] errorBubble: Error + modelMethods: ModelMethods valid: String! user(id: Int!): User! nullableArg(arg: Int = 123): String @@ -30,6 +31,12 @@ type Error { nilOnRequiredField: String! } +type ModelMethods { + resolverField: Boolean! + noContext: Boolean! + withContext: Boolean! +} + type InvalidIdentifier { id: Int! } From 4c10ba55bb493839605673a63701a4cb84b364e2 Mon Sep 17 00:00:00 2001 From: Grace Noah Date: Tue, 13 Nov 2018 22:26:32 +0000 Subject: [PATCH 5/7] fix generated code --- codegen/testserver/generated_test.go | 12 +++++++++++- codegen/testserver/resolver.go | 22 +++++++++++----------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/codegen/testserver/generated_test.go b/codegen/testserver/generated_test.go index a5169119a5..42af5e4cf4 100644 --- a/codegen/testserver/generated_test.go +++ b/codegen/testserver/generated_test.go @@ -580,7 +580,13 @@ func (r *testResolver) Query() QueryResolver { return &testQueryResolver{} } func (r *testResolver) ModelMethods() ModelMethodsResolver { - return &modelMethodsResolver{} + return &testModelMethodsResolver{} +} + +type testModelMethodsResolver struct{} + +func (r *testModelMethodsResolver) ResolverField(ctx context.Context, obj *ModelMethods) (bool, error) { + return true, nil } type testQueryResolver struct{ queryResolver } @@ -602,6 +608,10 @@ func (r *testQueryResolver) NullableArg(ctx context.Context, arg *int) (*string, return &s, nil } +func (r *testQueryResolver) ModelMethods(ctx context.Context) (*ModelMethods, error) { + return &ModelMethods{}, nil +} + func (r *testResolver) Subscription() SubscriptionResolver { return &testSubscriptionResolver{r} } diff --git a/codegen/testserver/resolver.go b/codegen/testserver/resolver.go index d649188f1e..da0b97591a 100644 --- a/codegen/testserver/resolver.go +++ b/codegen/testserver/resolver.go @@ -14,6 +14,9 @@ type Resolver struct{} func (r *Resolver) ForcedResolver() ForcedResolverResolver { return &forcedResolverResolver{r} } +func (r *Resolver) ModelMethods() ModelMethodsResolver { + return &modelMethodsResolver{r} +} func (r *Resolver) Query() QueryResolver { return &queryResolver{r} } @@ -23,19 +26,16 @@ func (r *Resolver) Subscription() SubscriptionResolver { func (r *Resolver) User() UserResolver { return &userResolver{r} } -func (r *Resolver) ModelMethods() ModelMethodsResolver { - return &modelMethodsResolver{} -} -type modelMethodsResolver struct{} +type forcedResolverResolver struct{ *Resolver } -func (r *modelMethodsResolver) ResolverField(ctx context.Context, obj *ModelMethods) (bool, error) { - return true, nil +func (r *forcedResolverResolver) Field(ctx context.Context, obj *ForcedResolver) (*Circle, error) { + panic("not implemented") } -type forcedResolverResolver struct{ *Resolver } +type modelMethodsResolver struct{ *Resolver } -func (r *forcedResolverResolver) Field(ctx context.Context, obj *ForcedResolver) (*Circle, error) { +func (r *modelMethodsResolver) ResolverField(ctx context.Context, obj *ModelMethods) (bool, error) { panic("not implemented") } @@ -68,6 +68,9 @@ func (r *queryResolver) Shapes(ctx context.Context) ([]*Shape, error) { 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") } @@ -77,9 +80,6 @@ func (r *queryResolver) User(ctx context.Context, id int) (User, error) { func (r *queryResolver) NullableArg(ctx context.Context, arg *int) (*string, error) { panic("not implemented") } -func (r *queryResolver) ModelMethods(ctx context.Context) (*ModelMethods, error) { - return &ModelMethods{}, nil -} func (r *queryResolver) KeywordArgs(ctx context.Context, breakArg string, defaultArg string, funcArg string, interfaceArg string, selectArg string, caseArg string, deferArg string, goArg string, mapArg string, structArg string, chanArg string, elseArg string, gotoArg string, packageArg string, switchArg string, constArg string, fallthroughArg string, ifArg string, rangeArg string, typeArg string, continueArg string, forArg string, importArg string, returnArg string, varArg string) (bool, error) { panic("not implemented") } From 6fed89478253c95b400cb55dfb8d6b7fe47fb776 Mon Sep 17 00:00:00 2001 From: Grace Noah Date: Wed, 14 Nov 2018 00:00:43 +0000 Subject: [PATCH 6/7] rebase fixes --- codegen/testserver/generated_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/codegen/testserver/generated_test.go b/codegen/testserver/generated_test.go index 42af5e4cf4..2861f5358c 100644 --- a/codegen/testserver/generated_test.go +++ b/codegen/testserver/generated_test.go @@ -521,6 +521,12 @@ func TestTracer(t *testing.T) { }) t.Run("model methods", func(t *testing.T) { + srv := httptest.NewServer( + handler.GraphQL( + NewExecutableSchema(Config{Resolvers: &testResolver{}}), + )) + defer srv.Close() + c := client.New(srv.URL) t.Run("without context", func(t *testing.T) { var resp struct { ModelMethods struct { From 5faf3a2bdf592c8445655b915c56e2762e305dc8 Mon Sep 17 00:00:00 2001 From: Grace Noah Date: Wed, 14 Nov 2018 17:26:32 +0000 Subject: [PATCH 7/7] re-generate --- codegen/testserver/generated.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/codegen/testserver/generated.go b/codegen/testserver/generated.go index 64b490a25e..8f9c7966b2 100644 --- a/codegen/testserver/generated.go +++ b/codegen/testserver/generated.go @@ -1524,7 +1524,7 @@ func (ec *executionContext) _ModelMethods(ctx context.Context, sel ast.Selection // nolint: vetshadow func (ec *executionContext) _ModelMethods_resolverField(ctx context.Context, field graphql.CollectedField, obj *ModelMethods) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer ec.Tracer.EndFieldExecution(ctx) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "ModelMethods", Args: nil, @@ -1551,7 +1551,7 @@ func (ec *executionContext) _ModelMethods_resolverField(ctx context.Context, fie // nolint: vetshadow func (ec *executionContext) _ModelMethods_noContext(ctx context.Context, field graphql.CollectedField, obj *ModelMethods) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer ec.Tracer.EndFieldExecution(ctx) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "ModelMethods", Args: nil, @@ -1578,7 +1578,7 @@ func (ec *executionContext) _ModelMethods_noContext(ctx context.Context, field g // nolint: vetshadow func (ec *executionContext) _ModelMethods_withContext(ctx context.Context, field graphql.CollectedField, obj *ModelMethods) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer ec.Tracer.EndFieldExecution(ctx) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "ModelMethods", Args: nil, @@ -2168,7 +2168,7 @@ func (ec *executionContext) _Query_errorBubble(ctx context.Context, field graphq // nolint: vetshadow func (ec *executionContext) _Query_modelMethods(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer ec.Tracer.EndFieldExecution(ctx) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "Query", Args: nil,