object.gotpl

 1{{ $object := . }}
 2
 3var {{ $object.GQLType|lcFirst}}Implementors = {{$object.Implementors}}
 4
 5// nolint: gocyclo, errcheck, gas, goconst
 6{{- if .Stream }}
 7func (ec *executionContext) _{{$object.GQLType}}(ctx context.Context, sel []query.Selection) func() graphql.Marshaler {
 8	fields := graphql.CollectFields(ec.Doc, sel, {{$object.GQLType|lcFirst}}Implementors, ec.Variables)
 9	ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{
10		Object: {{$object.GQLType|quote}},
11	})
12	if len(fields) != 1 {
13		ec.Errorf(ctx, "must subscribe to exactly one stream")
14		return nil
15	}
16
17	switch fields[0].Name {
18	{{- range $field := $object.Fields }}
19	case "{{$field.GQLName}}":
20		return ec._{{$object.GQLType}}_{{$field.GQLName}}(ctx, fields[0])
21	{{- end }}
22	default:
23		panic("unknown field " + strconv.Quote(fields[0].Name))
24	}
25}
26{{- else }}
27func (ec *executionContext) _{{$object.GQLType}}(ctx context.Context, sel []query.Selection{{if not $object.Root}}, obj *{{$object.FullName}} {{end}}) graphql.Marshaler {
28	fields := graphql.CollectFields(ec.Doc, sel, {{$object.GQLType|lcFirst}}Implementors, ec.Variables)
29	{{if $object.Root}}
30		ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{
31			Object: {{$object.GQLType|quote}},
32		})
33	{{end}}
34	out := graphql.NewOrderedMap(len(fields))
35	for i, field := range fields {
36		out.Keys[i] = field.Alias
37
38		switch field.Name {
39		case "__typename":
40			out.Values[i] = graphql.MarshalString({{$object.GQLType|quote}})
41		{{- range $field := $object.Fields }}
42		case "{{$field.GQLName}}":
43			out.Values[i] = ec._{{$object.GQLType}}_{{$field.GQLName}}(ctx, field{{if not $object.Root}}, obj{{end}})
44		{{- end }}
45		default:
46			panic("unknown field " + strconv.Quote(field.Name))
47		}
48	}
49
50	return out
51}
52{{- end }}