blob: f543608df0c8029a03ce448b8c83126f9af7d5fa (
plain) (
tree)
|
|
{{- 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 }}
|