Skip to content

Commit

Permalink
Fix issue 99designs#2470
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman A. Grigorovich committed Dec 14, 2022
1 parent 3008f4e commit 461069d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
4 changes: 3 additions & 1 deletion codegen/field.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ func (ec *executionContext) _{{$object.Name}}_{{$field.Name}}(ctx context.Contex
})
if err != nil {
ec.Error(ctx, err)
return {{ $null }}
{{- if not $object.Root }}
return {{ $null }}
{{- end }}
}
{{- end }}
if resTmp == nil {
Expand Down
44 changes: 26 additions & 18 deletions codegen/object.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.Selec
})
{{end}}
out := graphql.NewFieldSet(fields)
var invalids uint32
{{- if not $object.Root }}
var invalids uint32
{{- end }}
for i, field := range fields {
{{- if $object.Root }}
innerCtx := graphql.WithRootFieldContext(ctx, &graphql.RootFieldContext{
Expand All @@ -54,14 +56,16 @@ func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.Selec
}
}()
res = ec._{{$object.Name}}_{{$field.Name}}(ctx, field{{if not $object.Root}}, obj{{end}})
{{- if $field.TypeReference.GQL.NonNull }}
if res == graphql.Null {
{{- if $object.IsConcurrent }}
atomic.AddUint32(&invalids, 1)
{{- else }}
invalids++
{{- end }}
}
{{- if not $object.Root }}
{{- if $field.TypeReference.GQL.NonNull }}
if res == graphql.Null {
{{- if $object.IsConcurrent }}
atomic.AddUint32(&invalids, 1)
{{- else }}
invalids++
{{- end }}
}
{{- end }}
{{- end }}
return res
}
Expand All @@ -88,14 +92,16 @@ func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.Selec
out.Values[i] = ec._{{$object.Name}}_{{$field.Name}}(ctx, field, obj)
{{end}}

{{- if $field.TypeReference.GQL.NonNull }}
if out.Values[i] == graphql.Null {
{{- if $object.IsConcurrent }}
atomic.AddUint32(&invalids, 1)
{{- else }}
invalids++
{{- end }}
}
{{- if not $object.Root }}
{{- if $field.TypeReference.GQL.NonNull }}
if out.Values[i] == graphql.Null {
{{- if $object.IsConcurrent }}
atomic.AddUint32(&invalids, 1)
{{- else }}
invalids++
{{- end }}
}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
Expand All @@ -104,7 +110,9 @@ func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.Selec
}
}
out.Dispatch()
if invalids > 0 { return graphql.Null }
{{- if not $object.Root }}
if invalids > 0 { return graphql.Null }
{{- end }}
return out
}
{{- end }}
Expand Down

0 comments on commit 461069d

Please sign in to comment.