aboutsummaryrefslogblamecommitdiffstats
path: root/vendor/github.com/99designs/gqlgen/codegen/templates/input.gotpl
blob: f543608df0c8029a03ce448b8c83126f9af7d5fa (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
















                                                                                                     
                                                                                           









                                                      
	{{- if .IsMarshaled }}
	func Unmarshal{{ .GQLType }}(v interface{}) ({{.FullName}}, error) {
		var it {{.FullName}}
		var asMap = v.(map[string]interface{})
		{{ range $field := .Fields}}
			{{- if $field.Default}}
				if _, present := asMap[{{$field.GQLName|quote}}] ; !present {
					asMap[{{$field.GQLName|quote}}] = {{ $field.Default | dump }}
				}
			{{- end}}
		{{- end }}

		for k, v := range asMap {
			switch k {
			{{- range $field := .Fields }}
			case {{$field.GQLName|quote}}:
				var err error
				{{ $field.Unmarshal (print "it." $field.GoFieldName) "v" }}
				if err != nil {
					return it, err
				}
			{{- end }}
			}
		}

		return it, nil
	}
	{{- end }}