Skip to content

Commit

Permalink
add some refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
vvakame committed Aug 23, 2018
1 parent c7fd841 commit 568a72e
Show file tree
Hide file tree
Showing 12 changed files with 1,317 additions and 1,181 deletions.
15 changes: 11 additions & 4 deletions codegen/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,21 @@ 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 {
{{- if not .isScalar }}
rctx := &graphql.ResolverContext{
Index: &{{.index}},
}
ctx = graphql.WithResolverContext(ctx, rctx)
ctx := graphql.WithResolverContext(ctx, rctx)
{{- end}}
{{.arr}} = append({{.arr}}, func() graphql.Marshaler {
{{ .next }}
}(ctx))
}())
}
return {{.arr}}`, map[string]interface{}{
"val": val,
"arr": arr,
"index": index,
"isScalar": f.IsScalar,
"next": f.doWriteJson(val+"["+index+"]", remainingMods[1:], astType.Elem, false, depth+1),
})

Expand All @@ -240,7 +243,11 @@ func (f *Field) doWriteJson(val string, remainingMods []string, astType *ast.Typ
if !isPtr {
val = "&" + val
}
return fmt.Sprintf("return ec._%s(ctx, field.Selections, %s)", f.GQLType, val)
return tpl(`
return ec._{{.type}}(ctx, field.Selections, {{.val}})`, map[string]interface{}{
"type": f.GQLType,
"val": val,
})
}
}

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.

2 changes: 1 addition & 1 deletion codegen/templates/field.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
}
}
{{ else }}
// nolint: megacheck, ineffassign
// nolint: vetshadow
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 568a72e

Please sign in to comment.