aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/99designs/gqlgen/codegen/type.gotpl
diff options
context:
space:
mode:
authorAmine Hilaly <hilalyamine@gmail.com>2019-04-09 21:45:24 +0200
committerAmine Hilaly <hilalyamine@gmail.com>2019-04-09 21:45:24 +0200
commit26b5343e2160de172969e6834074cf8482ceb845 (patch)
tree04f27aa660a903d65f7b3d951bd1c6f92c59c0c3 /vendor/github.com/99designs/gqlgen/codegen/type.gotpl
parent6e8496f4c1767ca8a8b95716a04f1b492bef7397 (diff)
downloadgit-bug-26b5343e2160de172969e6834074cf8482ceb845.tar.gz
Update Gopkg.*
Diffstat (limited to 'vendor/github.com/99designs/gqlgen/codegen/type.gotpl')
-rw-r--r--vendor/github.com/99designs/gqlgen/codegen/type.gotpl131
1 files changed, 131 insertions, 0 deletions
diff --git a/vendor/github.com/99designs/gqlgen/codegen/type.gotpl b/vendor/github.com/99designs/gqlgen/codegen/type.gotpl
new file mode 100644
index 00000000..f727baac
--- /dev/null
+++ b/vendor/github.com/99designs/gqlgen/codegen/type.gotpl
@@ -0,0 +1,131 @@
+{{- range $type := .ReferencedTypes }}
+ {{ with $type.UnmarshalFunc }}
+ func (ec *executionContext) {{ . }}(ctx context.Context, v interface{}) ({{ $type.GO | ref }}, error) {
+ {{- if $type.IsNilable }}
+ if v == nil { return nil, nil }
+ {{- end }}
+ {{- if $type.IsPtr }}
+ res, err := ec.{{ $type.Elem.UnmarshalFunc }}(ctx, v)
+ return &res, err
+ {{- else if $type.IsSlice }}
+ var vSlice []interface{}
+ if v != nil {
+ if tmp1, ok := v.([]interface{}); ok {
+ vSlice = tmp1
+ } else {
+ vSlice = []interface{}{ v }
+ }
+ }
+ var err error
+ res := make([]{{$type.GO.Elem | ref}}, len(vSlice))
+ for i := range vSlice {
+ res[i], err = ec.{{ $type.Elem.UnmarshalFunc }}(ctx, vSlice[i])
+ if err != nil {
+ return nil, err
+ }
+ }
+ return res, nil
+ {{- else }}
+ {{- if $type.Unmarshaler }}
+ {{- if $type.CastType }}
+ tmp, err := {{ $type.Unmarshaler | call }}(v)
+ return {{ $type.GO | ref }}(tmp), err
+ {{- else}}
+ return {{ $type.Unmarshaler | call }}(v)
+ {{- end }}
+ {{- else if eq ($type.GO | ref) "map[string]interface{}" }}
+ return v.(map[string]interface{}), nil
+ {{- else if $type.IsMarshaler -}}
+ var res {{ $type.GO | ref }}
+ return res, res.UnmarshalGQL(v)
+ {{- else }}
+ return ec.unmarshalInput{{ $type.GQL.Name }}(ctx, v)
+ {{- end }}
+ {{- end }}
+ }
+ {{- end }}
+
+ {{ with $type.MarshalFunc }}
+ func (ec *executionContext) {{ . }}(ctx context.Context, sel ast.SelectionSet, v {{ $type.GO | ref }}) graphql.Marshaler {
+ {{- if $type.IsNilable }}
+ if v == nil {
+ {{- if $type.GQL.NonNull }}
+ if !ec.HasError(graphql.GetResolverContext(ctx)) {
+ ec.Errorf(ctx, "must not be null")
+ }
+ {{- end }}
+ return graphql.Null
+ }
+ {{- else if $type.HasIsZero }}
+ if v.IsZero() {
+ {{- if $type.GQL.NonNull }}
+ if !ec.HasError(graphql.GetResolverContext(ctx)) {
+ ec.Errorf(ctx, "must not be null")
+ }
+ {{- end }}
+ return graphql.Null
+ }
+ {{- end }}
+
+ {{- if $type.IsSlice }}
+ {{- if not $type.GQL.NonNull }}
+ if v == nil {
+ return graphql.Null
+ }
+ {{- end }}
+ ret := make(graphql.Array, len(v))
+ {{- if not $type.IsScalar }}
+ var wg sync.WaitGroup
+ isLen1 := len(v) == 1
+ if !isLen1 {
+ wg.Add(len(v))
+ }
+ {{- end }}
+ for i := range v {
+ {{- if not $type.IsScalar }}
+ i := i
+ rctx := &graphql.ResolverContext{
+ Index: &i,
+ Result: &v[i],
+ }
+ ctx := graphql.WithResolverContext(ctx, rctx)
+ f := func(i int) {
+ defer func() {
+ if r := recover(); r != nil {
+ ec.Error(ctx, ec.Recover(ctx, r))
+ ret = nil
+ }
+ }()
+ if !isLen1 {
+ defer wg.Done()
+ }
+ ret[i] = ec.{{ $type.Elem.MarshalFunc }}(ctx, sel, v[i])
+ }
+ if isLen1 {
+ f(i)
+ } else {
+ go f(i)
+ }
+ {{ else }}
+ ret[i] = ec.{{ $type.Elem.MarshalFunc }}(ctx, sel, v[i])
+ {{- end}}
+ }
+ {{ if not $type.IsScalar }} wg.Wait() {{ end }}
+ return ret
+ {{- else }}
+
+ {{- if $type.IsMarshaler }}
+ return v
+ {{- else if $type.Marshaler }}
+ {{- if $type.IsPtr }}
+ return ec.{{ $type.Elem.MarshalFunc }}(ctx, sel, *v)
+ {{- else }}
+ return {{ $type.Marshaler | call }}({{- if $type.CastType }}{{ $type.CastType | ref }}(v){{else}}v{{- end }})
+ {{- end }}
+ {{- else }}
+ return ec._{{$type.Definition.Name}}(ctx, sel, {{ if not $type.IsNilable}}&{{end}} v)
+ {{- end }}
+ {{- end }}
+ }
+ {{- end }}
+{{- end }}