aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/99designs/gqlgen/codegen/field.gotpl
diff options
context:
space:
mode:
authorAmine Hilaly <hilalyamine@gmail.com>2019-07-07 13:37:03 +0200
committerAmine Hilaly <hilalyamine@gmail.com>2019-07-07 13:37:03 +0200
commite381d5554a1b2b6e3a750206a853e090ec8183ab (patch)
treec4e19908c27389f9ccf030112efbf1f72e2469c5 /vendor/github.com/99designs/gqlgen/codegen/field.gotpl
parentcb7fefdc99cac1952c7a6f6765420819aee71d63 (diff)
downloadgit-bug-e381d5554a1b2b6e3a750206a853e090ec8183ab.tar.gz
Update gqlgen vendors
Diffstat (limited to 'vendor/github.com/99designs/gqlgen/codegen/field.gotpl')
-rw-r--r--vendor/github.com/99designs/gqlgen/codegen/field.gotpl94
1 files changed, 67 insertions, 27 deletions
diff --git a/vendor/github.com/99designs/gqlgen/codegen/field.gotpl b/vendor/github.com/99designs/gqlgen/codegen/field.gotpl
index 9718a08a..c0f6fcae 100644
--- a/vendor/github.com/99designs/gqlgen/codegen/field.gotpl
+++ b/vendor/github.com/99designs/gqlgen/codegen/field.gotpl
@@ -37,9 +37,15 @@
}
}
{{ else }}
- func (ec *executionContext) _{{$object.Name}}_{{$field.Name}}(ctx context.Context, field graphql.CollectedField{{ if not $object.Root }}, obj {{$object.Reference | ref}}{{end}}) graphql.Marshaler {
+ func (ec *executionContext) _{{$object.Name}}_{{$field.Name}}(ctx context.Context, field graphql.CollectedField{{ if not $object.Root }}, obj {{$object.Reference | ref}}{{end}}) (ret graphql.Marshaler) {
ctx = ec.Tracer.StartFieldExecution(ctx, field)
- defer func () { ec.Tracer.EndFieldExecution(ctx) }()
+ defer func () {
+ if r := recover(); r != nil {
+ ec.Error(ctx, ec.Recover(ctx, r))
+ ret = graphql.Null
+ }
+ ec.Tracer.EndFieldExecution(ctx)
+ }()
rctx := &graphql.ResolverContext{
Object: {{$object.Name|quote}},
Field: field,
@@ -57,31 +63,19 @@
rctx.Args = args
{{- end }}
ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx)
- 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 }}
- return ec.resolvers.{{ $field.ShortInvocation }}
- {{- else if $field.IsMap }}
- switch v := {{$field.GoReceiverName}}[{{$field.Name|quote}}].(type) {
- case {{$field.TypeReference.GO | ref}}:
- return v, nil
- case {{$field.TypeReference.Elem.GO | ref}}:
- return &v, nil
- case nil:
- return ({{$field.TypeReference.GO | ref}})(nil), nil
- default:
- return nil, fmt.Errorf("unexpected type %T for field %s", v, {{ $field.Name | quote}})
- }
- {{- else if $field.IsMethod }}
- {{- if $field.NoErr }}
- return {{$field.GoReceiverName}}.{{$field.GoFieldName}}({{ $field.CallArgs }}), nil
- {{- else }}
- return {{$field.GoReceiverName}}.{{$field.GoFieldName}}({{ $field.CallArgs }})
- {{- end }}
- {{- else if $field.IsVariable }}
- return {{$field.GoReceiverName}}.{{$field.GoFieldName}}, nil
- {{- end }}
- })
+ {{- if $.Directives.LocationDirectives "FIELD" }}
+ resTmp := ec._fieldMiddleware(ctx, {{if $object.Root}}nil{{else}}obj{{end}}, func(rctx context.Context) (interface{}, error) {
+ {{ template "field" $field }}
+ })
+ {{ else }}
+ resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
+ {{ template "field" $field }}
+ })
+ if err != nil {
+ ec.Error(ctx, err)
+ return graphql.Null
+ }
+ {{- end }}
if resTmp == nil {
{{- if $field.TypeReference.GQL.NonNull }}
if !ec.HasError(rctx) {
@@ -98,3 +92,49 @@
{{ end }}
{{- end }}{{- end}}
+
+{{ define "field" }}
+ {{- if .HasDirectives -}}
+ directive0 := func(rctx context.Context) (interface{}, error) {
+ ctx = rctx // use context from middleware stack in children
+ {{ template "fieldDefinition" . }}
+ }
+ {{ template "implDirectives" . }}
+ tmp, err := directive{{.ImplDirectives|len}}(rctx)
+ if err != nil {
+ return nil, err
+ }
+ if data, ok := tmp.({{ .TypeReference.GO | ref }}) ; ok {
+ return data, nil
+ }
+ return nil, fmt.Errorf(`unexpected type %T from directive, should be {{ .TypeReference.GO }}`, tmp)
+ {{- else -}}
+ ctx = rctx // use context from middleware stack in children
+ {{ template "fieldDefinition" . }}
+ {{- end -}}
+{{ end }}
+
+{{ define "fieldDefinition" }}
+ {{- if .IsResolver -}}
+ return ec.resolvers.{{ .ShortInvocation }}
+ {{- else if .IsMap -}}
+ switch v := {{.GoReceiverName}}[{{.Name|quote}}].(type) {
+ case {{.TypeReference.GO | ref}}:
+ return v, nil
+ case {{.TypeReference.Elem.GO | ref}}:
+ return &v, nil
+ case nil:
+ return ({{.TypeReference.GO | ref}})(nil), nil
+ default:
+ return nil, fmt.Errorf("unexpected type %T for field %s", v, {{ .Name | quote}})
+ }
+ {{- else if .IsMethod -}}
+ {{- if .NoErr -}}
+ return {{.GoReceiverName}}.{{.GoFieldName}}({{ .CallArgs }}), nil
+ {{- else -}}
+ return {{.GoReceiverName}}.{{.GoFieldName}}({{ .CallArgs }})
+ {{- end -}}
+ {{- else if .IsVariable -}}
+ return {{.GoReceiverName}}.{{.GoFieldName}}, nil
+ {{- end }}
+{{- end }}