{{- range $type := .ReferencedTypes }} {{ with $type.UnmarshalFunc }} func (ec *executionContext) {{ . }}(ctx context.Context, v interface{}) ({{ $type.GO | ref }}, error) { {{- if and $type.IsNilable (not $type.GQL.NonNull) (not $type.IsPtrToPtr) }} if v == nil { return nil, nil } {{- end }} {{- if or $type.IsPtrToSlice $type.IsPtrToIntf }} res, err := ec.{{ $type.Elem.UnmarshalFunc }}(ctx, v) return &res, graphql.ErrorOnPath(ctx, err) {{- else if $type.IsSlice }} var vSlice []interface{} if v != nil { vSlice = graphql.CoerceList(v) } var err error res := make([]{{$type.GO.Elem | ref}}, len(vSlice)) for i := range vSlice { ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) res[i], err = ec.{{ $type.Elem.UnmarshalFunc }}(ctx, vSlice[i]) if err != nil { return nil, err } } return res, nil {{- else if and $type.IsPtrToPtr (not $type.Unmarshaler) (not $type.IsMarshaler) }} var pres {{ $type.Elem.GO | ref }} if v != nil { res, err := ec.{{ $type.Elem.UnmarshalFunc }}(ctx, v) if err != nil { return nil, graphql.ErrorOnPath(ctx, err) } pres = res } return &pres, nil {{- else }} {{- if $type.Unmarshaler }} {{- if $type.CastType }} {{- if $type.IsContext }} tmp, err := {{ $type.Unmarshaler | call }}(ctx, v) {{- else }} tmp, err := {{ $type.Unmarshaler | call }}(v) {{- end }} {{- if and $type.IsNilable $type.Elem }} res := {{ $type.Elem.GO | ref }}(tmp) {{- else}} res := {{ $type.GO | ref }}(tmp) {{- end }} {{- else}} {{- if $type.IsContext }} res, err := {{ $type.Unmarshaler | call }}(ctx, v) {{- else }} res, err := {{ $type.Unmarshaler | call }}(v) {{- end }} {{- end }} {{- if and $type.IsTargetNilable (not $type.IsNilable) }} return *res, graphql.ErrorOnPath(ctx, err) {{- else if and (not $type.IsTargetNilable) $type.IsNilable }} return &res, graphql.ErrorOnPath(ctx, err) {{- else}} return res, graphql.ErrorOnPath(ctx, err) {{- end }} {{- else if $type.IsMarshaler }} {{- if and $type.IsNilable $type.Elem }} var res = new({{ $type.Elem.GO | ref }}) {{- else}} var res {{ $type.GO | ref }} {{- end }} {{- if $type.IsContext }} err := res.UnmarshalGQLContext(ctx, v) {{- else }} err := res.UnmarshalGQL(v) {{- end }} return res, graphql.ErrorOnPath(ctx, err) {{- else }} res, err := ec.unmarshalInput{{ $type.GQL.Name }}(ctx, v) {{- if and $type.IsNilable (not $type.IsMap) (not $type.PointersInUmarshalInput) }} return &res, graphql.ErrorOnPath(ctx, err) {{- else if and (not $type.IsNilable) $type.PointersInUmarshalInput }} return *res, graphql.ErrorOnPath(ctx, err) {{- else }} return res, graphql.ErrorOnPath(ctx, err) {{- end }} {{- end }} {{- end }} } {{- end }} {{ with $type.MarshalFunc }} func (ec *executionContext) {{ . }}(ctx context.Context, sel ast.SelectionSet, v {{ $type.GO | ref }}) graphql.Marshaler { {{- if or $type.IsPtrToSlice $type.IsPtrToIntf }} return ec.{{ $type.Elem.MarshalFunc }}(ctx, sel, *v) {{- else if $type.IsSlice }} {{- if not $type.GQL.NonNull }} if v == nil { return graphql.Null } {{- end }} ret := make(graphql.Array, len(v)) {{- if not $type.IsScalar }} var wg sync.WaitGroup isLen1 := len(v) == 1 if !isLen1 { wg.Add(len(v)) } {{- end }} for i := range v { {{- if not $type.IsScalar }} i := i fc := &graphql.FieldContext{ Index: &i, Result: &v[i], } ctx := graphql.WithFieldContext(ctx, fc) f := func(i int) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) ret = nil } }() if !isLen1 { defer wg.Done() } ret[i] = ec.{{ $type.Elem.MarshalFunc }}(ctx, sel, v[i]) } if isLen1 { f(i) } else { go f(i) } {{ else }} ret[i] = ec.{{ $type.Elem.MarshalFunc }}(ctx, sel, v[i]) {{- end }} } {{ if not $type.IsScalar }} wg.Wait() {{ end }} {{ if $type.Elem.GQL.NonNull }} for _, e := range ret { if e == graphql.Null { return graphql.Null } } {{ end }} return ret {{- else if and $type.IsPtrToPtr (not $type.Unmarshaler) (not $type.IsMarshaler) }} if v == nil { return graphql.Null } return ec.{{ $type.Elem.MarshalFunc }}(ctx, sel, *v) {{- else }} {{- if $type.IsNilable }} if v == nil { {{- if $type.GQL.NonNull }} if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { ec.Errorf(ctx, "the requested element is null which the schema does not allow") } {{- end }} return graphql.Null } {{- end }} {{- if $type.IsMarshaler }} {{- if $type.IsContext }} return graphql.WrapContextMarshaler(ctx, v) {{- else }} return v {{- end }} {{- else if $type.Marshaler }} {{- $v := "v" }} {{- if and $type.IsTargetNilable (not $type.IsNilable) }} {{- $v = "&v" }} {{- else if and (not $type.IsTargetNilable) $type.IsNilable }} {{- $v = "*v" }} {{- end }} res := {{ $type.Marshaler | call }}({{- if $type.CastType }}{{ $type.CastType | ref }}({{ $v }}){{else}}{{ $v }}{{- end }}) {{- if $type.GQL.NonNull }} if res == graphql.Null { if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { ec.Errorf(ctx, "the requested element is null which the schema does not allow") } } {{- end }} {{- if $type.IsContext }} return graphql.WrapContextMarshaler(ctx, res) {{- else }} return res {{- end }} {{- else if $type.IsRoot }} {{- if eq $type.Definition.Name "Subscription" }} res := ec._{{$type.Definition.Name}}(ctx, sel) return res(ctx) {{- else }} return ec._{{$type.Definition.Name}}(ctx, sel) {{- end }} {{- else }} return ec._{{$type.Definition.Name}}(ctx, sel, {{ if not $type.IsNilable}}&{{end}} v) {{- end }} {{- end }} } {{- end }} {{- end }}