aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/99designs/gqlgen/codegen/input.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/input.gotpl
parent6e8496f4c1767ca8a8b95716a04f1b492bef7397 (diff)
downloadgit-bug-26b5343e2160de172969e6834074cf8482ceb845.tar.gz
Update Gopkg.*
Diffstat (limited to 'vendor/github.com/99designs/gqlgen/codegen/input.gotpl')
-rw-r--r--vendor/github.com/99designs/gqlgen/codegen/input.gotpl56
1 files changed, 56 insertions, 0 deletions
diff --git a/vendor/github.com/99designs/gqlgen/codegen/input.gotpl b/vendor/github.com/99designs/gqlgen/codegen/input.gotpl
new file mode 100644
index 00000000..c8ac7ad3
--- /dev/null
+++ b/vendor/github.com/99designs/gqlgen/codegen/input.gotpl
@@ -0,0 +1,56 @@
+{{- range $input := .Inputs }}
+ {{- if not .HasUnmarshal }}
+ func (ec *executionContext) unmarshalInput{{ .Name }}(ctx context.Context, v interface{}) ({{.Type | ref}}, error) {
+ var it {{.Type | ref}}
+ var asMap = v.(map[string]interface{})
+ {{ range $field := .Fields}}
+ {{- if $field.Default}}
+ if _, present := asMap[{{$field.Name|quote}}] ; !present {
+ asMap[{{$field.Name|quote}}] = {{ $field.Default | dump }}
+ }
+ {{- end}}
+ {{- end }}
+
+ for k, v := range asMap {
+ switch k {
+ {{- range $field := .Fields }}
+ case {{$field.Name|quote}}:
+ var err error
+ {{- if $field.Directives }}
+ getField0 := func(ctx context.Context) (interface{}, error) { return ec.{{ $field.TypeReference.UnmarshalFunc }}(ctx, v) }
+
+ {{- range $i, $directive := $field.Directives }}
+ getField{{add $i 1}} := func(ctx context.Context) (res interface{}, err error) {
+ {{- range $dArg := $directive.Args }}
+ {{- if and $dArg.TypeReference.IsPtr ( notNil "Value" $dArg ) }}
+ {{ $dArg.VarName }} := {{ $dArg.Value | dump }}
+ {{- end }}
+ {{- end }}
+ n := getField{{$i}}
+ return ec.directives.{{$directive.Name|ucFirst}}({{$directive.ResolveArgs "it" "n" }})
+ }
+ {{- end }}
+
+ tmp, err := getField{{$field.Directives|len}}(ctx)
+ if err != nil {
+ return it, err
+ }
+ if data, ok := tmp.({{ $field.TypeReference.GO | ref }}) ; ok {
+ it.{{$field.GoFieldName}} = data
+ } else {
+ return it, fmt.Errorf(`unexpected type %T from directive, should be {{ $field.TypeReference.GO }}`, tmp)
+ }
+ {{- else }}
+ it.{{$field.GoFieldName}}, err = ec.{{ $field.TypeReference.UnmarshalFunc }}(ctx, v)
+ if err != nil {
+ return it, err
+ }
+ {{- end }}
+ {{- end }}
+ }
+ }
+
+ return it, nil
+ }
+ {{- end }}
+{{ end }}