Skip to content

Commit

Permalink
Run resolver middleware for all fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathew Byrne committed Jul 24, 2018
1 parent f67f839 commit b512176
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
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.

43 changes: 19 additions & 24 deletions codegen/templates/field.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,27 @@
rctx.PushField(field.Alias)
defer rctx.Pop()
{{- end }}

{{- if $field.IsResolver }}
resTmp, err := ec.ResolverMiddleware(ctx, func(ctx context.Context) (interface{}, error) {
resTmp, err := ec.ResolverMiddleware(ctx, func(ctx context.Context) (interface{}, error) {
{{- if $field.IsResolver }}
return ec.resolvers.{{ $field.ShortInvocation }}
})
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
if resTmp == nil {
return graphql.Null
}
res := resTmp.({{$field.Signature}})
{{- else if $field.GoVarName }}
res := obj.{{$field.GoVarName}}
{{- else if $field.GoMethodName }}
{{- if $field.NoErr }}
res := {{$field.GoMethodName}}({{ $field.CallArgs }})
{{- else }}
res, err := {{$field.GoMethodName}}({{ $field.CallArgs }})
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
{{- else if $field.GoVarName }}
return obj.{{$field.GoVarName}}, nil
{{- else if $field.GoMethodName }}
{{- if $field.NoErr }}
return {{$field.GoMethodName}}({{ $field.CallArgs }}), nil
{{- else }}
return {{$field.GoMethodName}}({{ $field.CallArgs }})
{{- end }}
{{- end }}
{{- end }}
})
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
if resTmp == nil {
return graphql.Null
}
res := resTmp.({{$field.Signature}})
{{ $field.WriteJson }}
{{- if $field.IsConcurrent }}
})
Expand Down

0 comments on commit b512176

Please sign in to comment.