github.com/nonameffh/gqlgen@v0.7.2/codegen/templates/input.gotpl (about)

     1  	{{- if .IsMarshaled }}
     2  	func Unmarshal{{ .GQLType }}(v interface{}) ({{.FullName}}, error) {
     3  		var it {{.FullName}}
     4  		var asMap = v.(map[string]interface{})
     5  		{{ range $field := .Fields}}
     6  			{{- if $field.Default}}
     7  				if _, present := asMap[{{$field.GQLName|quote}}] ; !present {
     8  					asMap[{{$field.GQLName|quote}}] = {{ $field.Default | dump }}
     9  				}
    10  			{{- end}}
    11  		{{- end }}
    12  
    13  		for k, v := range asMap {
    14  			switch k {
    15  			{{- range $field := .Fields }}
    16  			case {{$field.GQLName|quote}}:
    17  				var err error
    18  				{{ $field.Unmarshal (print "it." $field.GoFieldName) "v" }}
    19  				if err != nil {
    20  					return it, err
    21  				}
    22  			{{- end }}
    23  			}
    24  		}
    25  
    26  		return it, nil
    27  	}
    28  	{{- end }}