mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
* Update to go 1.19 * Update dependencies * Update cross-compile script * Add missing targets to cross-compile-all * Update cache action to remove warning
78 lines
2.4 KiB
Plaintext
78 lines
2.4 KiB
Plaintext
{{- range $input := .Inputs }}
|
|
{{- if not .HasUnmarshal }}
|
|
func (ec *executionContext) unmarshalInput{{ .Name }}(ctx context.Context, obj interface{}) ({{.Type | ref}}, error) {
|
|
var it {{.Type | ref}}
|
|
asMap := map[string]interface{}{}
|
|
for k, v := range obj.(map[string]interface{}) {
|
|
asMap[k] = v
|
|
}
|
|
{{ range $field := .Fields}}
|
|
{{- if notNil "Default" $field }}
|
|
if _, present := asMap[{{$field.Name|quote}}] ; !present {
|
|
asMap[{{$field.Name|quote}}] = {{ $field.Default | dump }}
|
|
}
|
|
{{- end}}
|
|
{{- end }}
|
|
|
|
fieldsInOrder := [...]string{ {{ range .Fields }}{{ quote .Name }},{{ end }} }
|
|
for _, k := range fieldsInOrder {
|
|
v, ok := asMap[k]
|
|
if !ok {
|
|
continue
|
|
}
|
|
switch k {
|
|
{{- range $field := .Fields }}
|
|
case {{$field.Name|quote}}:
|
|
var err error
|
|
|
|
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField({{$field.Name|quote}}))
|
|
{{- 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, graphql.ErrorOnPath(ctx, err)
|
|
}
|
|
if data, ok := tmp.({{ $field.TypeReference.GO | ref }}) ; ok {
|
|
{{- if $field.IsResolver }}
|
|
if err = ec.resolvers.{{ $field.ShortInvocation }}; err != nil {
|
|
return it, err
|
|
}
|
|
{{- else }}
|
|
it.{{$field.GoFieldName}} = data
|
|
{{- end }}
|
|
{{- if $field.TypeReference.IsNilable }}
|
|
{{- if not $field.IsResolver }}
|
|
} else if tmp == nil {
|
|
it.{{$field.GoFieldName}} = nil
|
|
{{- end }}
|
|
{{- end }}
|
|
} else {
|
|
err := fmt.Errorf(`unexpected type %T from directive, should be {{ $field.TypeReference.GO }}`, tmp)
|
|
return it, graphql.ErrorOnPath(ctx, err)
|
|
}
|
|
{{- else }}
|
|
{{- if $field.IsResolver }}
|
|
data, err := ec.{{ $field.TypeReference.UnmarshalFunc }}(ctx, v)
|
|
if err != nil {
|
|
return it, err
|
|
}
|
|
if err = ec.resolvers.{{ $field.ShortInvocation }}; err != nil {
|
|
return it, err
|
|
}
|
|
{{- else }}
|
|
it.{{$field.GoFieldName}}, err = ec.{{ $field.TypeReference.UnmarshalFunc }}(ctx, v)
|
|
if err != nil {
|
|
return it, err
|
|
}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- end }}
|
|
}
|
|
}
|
|
|
|
return it, nil
|
|
}
|
|
{{- end }}
|
|
{{ end }}
|