diff options
author | Michael Muré <batolettre@gmail.com> | 2018-09-14 12:40:31 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-09-14 12:41:59 +0200 |
commit | b478cd1bcb4756b20f7f4b15fcf81f23e1a60a02 (patch) | |
tree | 8ce232dcab3dd00708f8ba66c334472457e5980d /vendor/github.com/99designs/gqlgen/codegen/templates/field.gotpl | |
parent | a3fc9abb921f5ce7084d6ab7473442d0b72b1d78 (diff) | |
download | git-bug-b478cd1bcb4756b20f7f4b15fcf81f23e1a60a02.tar.gz |
graphql: update gqlgen to 0.5.1
fix #6
Diffstat (limited to 'vendor/github.com/99designs/gqlgen/codegen/templates/field.gotpl')
-rw-r--r-- | vendor/github.com/99designs/gqlgen/codegen/templates/field.gotpl | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/vendor/github.com/99designs/gqlgen/codegen/templates/field.gotpl b/vendor/github.com/99designs/gqlgen/codegen/templates/field.gotpl new file mode 100644 index 00000000..b33f2123 --- /dev/null +++ b/vendor/github.com/99designs/gqlgen/codegen/templates/field.gotpl @@ -0,0 +1,74 @@ +{{ $field := . }} +{{ $object := $field.Object }} + +{{- if $object.Stream }} + func (ec *executionContext) _{{$object.GQLType}}_{{$field.GQLName}}(ctx context.Context, field graphql.CollectedField) func() graphql.Marshaler { + {{- if $field.Args }} + rawArgs := field.ArgumentMap(ec.Variables) + args, err := {{ $field.ArgsFunc }}(rawArgs) + if err != nil { + ec.Error(ctx, err) + return nil + } + {{- end }} + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Field: field, + }) + results, err := ec.resolvers.{{ $field.ShortInvocation }} + if err != nil { + ec.Error(ctx, err) + return nil + } + return func() graphql.Marshaler { + res, ok := <-results + if !ok { + return nil + } + var out graphql.OrderedMap + out.Add(field.Alias, func() graphql.Marshaler { {{ $field.WriteJson }} }()) + return &out + } + } +{{ else }} + // 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) + args, err := {{ $field.ArgsFunc }}(rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + {{- end }} + rctx := &graphql.ResolverContext{ + Object: {{$object.GQLType|quote}}, + Args: {{if $field.Args }}args{{else}}nil{{end}}, + Field: field, + } + ctx = graphql.WithResolverContext(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, {{if $object.Root}}nil{{else}}obj{{end}}, func(ctx context.Context) (interface{}, error) { + {{- if $field.IsResolver }} + return ec.resolvers.{{ $field.ShortInvocation }} + {{- 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 resTmp == nil { + {{- if $field.ASTType.NonNull }} + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + {{- end }} + return graphql.Null + } + res := resTmp.({{$field.Signature}}) + rctx.Result = res + {{ $field.WriteJson }} + } +{{ end }} |