Skip to content

Commit

Permalink
Parent resolver generated contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Scarr committed Oct 2, 2018
1 parent 14cf46b commit faf0416
Show file tree
Hide file tree
Showing 17 changed files with 1,250 additions and 511 deletions.
2 changes: 1 addition & 1 deletion codegen/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (f *Field) CallArgs() string {
var args []string

if f.IsResolver() {
args = append(args, "ctx")
args = append(args, "rctx")

if !f.Object.Root {
args = append(args, "obj")
Expand Down
2 changes: 1 addition & 1 deletion codegen/templates/data.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion codegen/templates/field.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{
Field: field,
})
rctx := ctx // FIXME: subscriptions are missing request middleware stack https://github.com/99designs/gqlgen/issues/259
results, err := ec.resolvers.{{ $field.ShortInvocation }}
if err != nil {
ec.Error(ctx, err)
Expand Down Expand Up @@ -46,7 +47,8 @@
Field: field,
}
ctx = graphql.WithResolverContext(ctx, rctx)
resTmp := ec.FieldMiddleware(ctx, {{if $object.Root}}nil{{else}}obj{{end}}, func(ctx context.Context) (interface{}, error) {
resTmp := ec.FieldMiddleware(ctx, {{if $object.Root}}nil{{else}}obj{{end}}, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
{{- if $field.IsResolver }}
return ec.resolvers.{{ $field.ShortInvocation }}
{{- else if $field.IsMethod }}
Expand Down
Loading

0 comments on commit faf0416

Please sign in to comment.