aboutsummaryrefslogblamecommitdiffstats
path: root/vendor/github.com/99designs/gqlgen/codegen/input.gotpl
blob: bdf3622caf11069379dffc210a8751061d3c8dd5 (plain) (tree)
1
2
3
4
5

                                   
                                                                                                                              
                                      
                                                        












                                                                                                  



                                                                                                                                                                   




                                                                                                       



                                                                                       
















                                                                                                                                                        
{{- range $input := .Inputs }}
	{{- if not .HasUnmarshal }}
	func (ec *executionContext) unmarshalInput{{ .Name }}(ctx context.Context, obj interface{}) ({{.Type | ref}}, error) {
		var it {{.Type | ref}}
		var asMap = obj.(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.ImplDirectives }}
					directive0 := func(ctx context.Context) (interface{}, error) { return ec.{{ $field.TypeReference.UnmarshalFunc }}(ctx, v) }
					{{ template "implDirectives" $field }}
					tmp, err := directive{{$field.ImplDirectives|len}}(ctx)
					if err != nil {
						return it, err
					}
					if data, ok := tmp.({{ $field.TypeReference.GO | ref }}) ; ok {
						it.{{$field.GoFieldName}} = data
					{{- if $field.TypeReference.IsNilable }}
						} else if tmp == nil {
							it.{{$field.GoFieldName}} = nil
					{{- end }}
					} 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 }}