Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Result field to ResolverContext #301

Merged
merged 8 commits into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions codegen/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,13 @@ func (f *Field) doWriteJson(val string, remainingMods []string, astType *ast.Typ

return tpl(`{{.arr}} := graphql.Array{}
for {{.index}} := range {{.val}} {
{{.arr}} = append({{.arr}}, func() graphql.Marshaler {
rctx := graphql.GetResolverContext(ctx)
rctx.PushIndex({{.index}})
defer rctx.Pop()
{{.arr}} = append({{.arr}}, func(ctx context.Context) graphql.Marshaler {
rctx := &graphql.ResolverContext{
Copy link
Collaborator

@vektah vektah Aug 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is strange. array marshalling isn't a resolver, and it shouldn't need a new context?

Copy link
Collaborator Author

@vvakame vvakame Aug 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it is right.
this change required default: case under case len(remainingMods) > 0 && remainingMods[0] == modList:.
I'll move this code to right place and add some arguments to method signature.

🤔 ❓

Index: &{{.index}},
}
ctx = graphql.WithResolverContext(ctx, rctx)
{{ .next }}
}())
}(ctx))
}
return {{.arr}}`, map[string]interface{}{
"val": val,
Expand Down
4 changes: 2 additions & 2 deletions codegen/templates/data.go

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion codegen/templates/field.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
rawArgs := field.ArgumentMap(ec.Variables)
{{ template "args.gotpl" $field.Args }}
{{- end }}
ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field})
ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{
Field: field,
})
results, err := ec.resolvers.{{ $field.ShortInvocation }}
if err != nil {
ec.Error(ctx, err)
Expand All @@ -24,6 +26,7 @@
}
}
{{ else }}
// nolint: megacheck, ineffassign
func (ec *executionContext) _{{$object.GQLType}}_{{$field.GQLName}}(ctx context.Context, field graphql.CollectedField, {{if not $object.Root}}obj *{{$object.FullName}}{{end}}) graphql.Marshaler {
{{- if $field.Args }}
rawArgs := field.ArgumentMap(ec.Variables)
Expand Down
2 changes: 2 additions & 0 deletions codegen/templates/object.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func (ec *executionContext) _{{$object.GQLType}}(ctx context.Context, sel ast.Se
ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{
Object: {{$object.GQLType|quote}},
})
{{else}}
graphql.GetResolverContext(ctx).Result = obj
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably happen using res around field.gotpl:62, here its going to be repeated for every child

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah... make sense...
It was a bit different from what I thought.
so I'll write what I want to do.

{{end}}

{{if $object.IsConcurrent}} var wg sync.WaitGroup {{end}}
Expand Down
Loading