Skip to content

Commit

Permalink
refactor ResolverContext#indicies and suppress lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
vvakame committed Aug 22, 2018
1 parent 09e4bf8 commit e57464f
Show file tree
Hide file tree
Showing 13 changed files with 824 additions and 272 deletions.
5 changes: 3 additions & 2 deletions codegen/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,9 @@ func (f *Field) doWriteJson(val string, remainingMods []string, astType *ast.Typ
return tpl(`{{.arr}} := graphql.Array{}
for {{.index}} := range {{.val}} {
{{.arr}} = append({{.arr}}, func(ctx context.Context) graphql.Marshaler {
rctx := graphql.GetResolverContext(ctx).Copy()
rctx.PushIndex({{.index}})
rctx := &graphql.ResolverContext{
Index: &{{.index}},
}
ctx = graphql.WithResolverContext(ctx, rctx)
{{ .next }}
}(ctx))
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.

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
Loading

0 comments on commit e57464f

Please sign in to comment.