Skip to content

Commit

Permalink
Showing 13 changed files with 4,225 additions and 5,588 deletions.
18 changes: 4 additions & 14 deletions codegen/object.go
Original file line number Diff line number Diff line change
@@ -220,15 +220,7 @@ func (f *Field) CallArgs() string {

// should be in the template, but its recursive and has a bunch of args
func (f *Field) WriteJson() string {
return strings.TrimSpace(
tpl(`
func () graphql.Marshaler {
{{ .next }}
}()
`, map[string]interface{}{
"next": f.doWriteJson("res", f.Type.Modifiers, f.ASTType, false, 1),
}),
)
return f.doWriteJson("res", f.Type.Modifiers, f.ASTType, false, 1)
}

func (f *Field) doWriteJson(val string, remainingMods []string, astType *ast.Type, isPtr bool, depth int) string {
@@ -243,8 +235,7 @@ func (f *Field) doWriteJson(val string, remainingMods []string, astType *ast.Typ
{{- end }}
return graphql.Null
}
{{ .next -}}
`, map[string]interface{}{
{{.next }}`, map[string]interface{}{
"val": val,
"nonNull": astType.NonNull,
"next": f.doWriteJson(val, remainingMods[1:], astType, true, depth+1),
@@ -298,8 +289,7 @@ func (f *Field) doWriteJson(val string, remainingMods []string, astType *ast.Typ
{{- end}}
}
{{ if and .top (not .isScalar) }} wg.Wait() {{ end }}
return {{ .arr -}}
`, map[string]interface{}{
return {{.arr}}`, map[string]interface{}{
"val": val,
"arr": arr,
"index": index,
@@ -314,7 +304,7 @@ func (f *Field) doWriteJson(val string, remainingMods []string, astType *ast.Typ
if isPtr {
val = "*" + val
}
return "return " + f.Marshal(val)
return f.Marshal(val)

default:
if !isPtr {
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.

7 changes: 3 additions & 4 deletions codegen/templates/field.gotpl
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@
return nil
}
var out graphql.OrderedMap
out.Add(field.Alias, func() graphql.Marshaler { return {{ $field.WriteJson }} }())
out.Add(field.Alias, func() graphql.Marshaler { {{ $field.WriteJson }} }())
return &out
}
}
@@ -50,6 +50,7 @@
}
ctx = graphql.WithResolverContext(ctx, rctx)
ctx = ec.Tracer.StartFieldExecution(ctx)
defer ec.Tracer.EndFieldExecution(ctx)
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 }}
@@ -74,8 +75,6 @@
}
res := resTmp.({{$field.Signature}})
rctx.Result = res
resMarshaler := {{ $field.WriteJson }}
ec.Tracer.EndFieldExecution(ctx)
return resMarshaler
{{ $field.WriteJson }}
}
{{ end }}
Loading

0 comments on commit 8eb2675

Please sign in to comment.