github.com/maeglindeveloper/gqlgen@v0.13.1-0.20210413081235-57808b12a0a0/codegen/object.gotpl (about) 1 {{- range $object := .Objects }} 2 3 var {{ $object.Name|lcFirst}}Implementors = {{$object.Implementors}} 4 5 {{- if .Stream }} 6 func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.SelectionSet) func() graphql.Marshaler { 7 fields := graphql.CollectFields(ec.OperationContext, sel, {{$object.Name|lcFirst}}Implementors) 8 ctx = graphql.WithFieldContext(ctx, &graphql.FieldContext{ 9 Object: {{$object.Name|quote}}, 10 }) 11 if len(fields) != 1 { 12 ec.Errorf(ctx, "must subscribe to exactly one stream") 13 return nil 14 } 15 16 switch fields[0].Name { 17 {{- range $field := $object.Fields }} 18 case "{{$field.Name}}": 19 return ec._{{$object.Name}}_{{$field.Name}}(ctx, fields[0]) 20 {{- end }} 21 default: 22 panic("unknown field " + strconv.Quote(fields[0].Name)) 23 } 24 } 25 {{- else }} 26 func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.SelectionSet{{ if not $object.Root }},obj {{$object.Reference | ref }}{{ end }}) graphql.Marshaler { 27 fields := graphql.CollectFields(ec.OperationContext, sel, {{$object.Name|lcFirst}}Implementors) 28 {{if $object.Root}} 29 ctx = graphql.WithFieldContext(ctx, &graphql.FieldContext{ 30 Object: {{$object.Name|quote}}, 31 }) 32 {{end}} 33 34 out := graphql.NewFieldSet(fields) 35 var invalids uint32 36 for i, field := range fields { 37 switch field.Name { 38 case "__typename": 39 out.Values[i] = graphql.MarshalString({{$object.Name|quote}}) 40 {{- range $field := $object.Fields }} 41 case "{{$field.Name}}": 42 {{- if $field.IsConcurrent }} 43 field := field 44 out.Concurrently(i, func() (res graphql.Marshaler) { 45 defer func() { 46 if r := recover(); r != nil { 47 ec.Error(ctx, ec.Recover(ctx, r)) 48 } 49 }() 50 res = ec._{{$object.Name}}_{{$field.Name}}(ctx, field{{if not $object.Root}}, obj{{end}}) 51 {{- if $field.TypeReference.GQL.NonNull }} 52 if res == graphql.Null { 53 {{- if $object.IsConcurrent }} 54 atomic.AddUint32(&invalids, 1) 55 {{- else }} 56 invalids++ 57 {{- end }} 58 } 59 {{- end }} 60 return res 61 }) 62 {{- else }} 63 out.Values[i] = ec._{{$object.Name}}_{{$field.Name}}(ctx, field{{if not $object.Root}}, obj{{end}}) 64 {{- if $field.TypeReference.GQL.NonNull }} 65 if out.Values[i] == graphql.Null { 66 {{- if $object.IsConcurrent }} 67 atomic.AddUint32(&invalids, 1) 68 {{- else }} 69 invalids++ 70 {{- end }} 71 } 72 {{- end }} 73 {{- end }} 74 {{- end }} 75 default: 76 panic("unknown field " + strconv.Quote(field.Name)) 77 } 78 } 79 out.Dispatch() 80 if invalids > 0 { return graphql.Null } 81 return out 82 } 83 {{- end }} 84 85 {{- end }}