@@ -239,31 +239,30 @@ func execFieldSelection(ctx context.Context, r *Request, s *resolvable.Schema, f
239
239
240
240
func (r * Request ) execSelectionSet (ctx context.Context , sels []selected.Selection , typ common.Type , path * pathSegment , s * resolvable.Schema , resolver reflect.Value , out * bytes.Buffer ) {
241
241
t , nonNull := unwrapNonNull (typ )
242
- switch t := t .(type ) {
243
- case * schema.Object , * schema.Interface , * schema.Union :
244
- // a reflect.Value of a nil interface will show up as an Invalid value
245
- if resolver .Kind () == reflect .Invalid || ((resolver .Kind () == reflect .Ptr || resolver .Kind () == reflect .Interface ) && resolver .IsNil ()) {
246
- // If a field of a non-null type resolves to null (either because the
247
- // function to resolve the field returned null or because an error occurred),
248
- // add an error to the "errors" list in the response.
249
- if nonNull {
250
- err := errors .Errorf ("graphql: got nil for non-null %q" , t )
251
- err .Path = path .toSlice ()
252
- r .AddError (err )
253
- }
254
- out .WriteString ("null" )
255
- return
242
+
243
+ // a reflect.Value of a nil interface will show up as an Invalid value
244
+ if resolver .Kind () == reflect .Invalid || ((resolver .Kind () == reflect .Ptr || resolver .Kind () == reflect .Interface ) && resolver .IsNil ()) {
245
+ // If a field of a non-null type resolves to null (either because the
246
+ // function to resolve the field returned null or because an error occurred),
247
+ // add an error to the "errors" list in the response.
248
+ if nonNull {
249
+ err := errors .Errorf ("graphql: got nil for non-null %q" , t )
250
+ err .Path = path .toSlice ()
251
+ r .AddError (err )
256
252
}
253
+ out .WriteString ("null" )
254
+ return
255
+ }
257
256
257
+ switch t .(type ) {
258
+ case * schema.Object , * schema.Interface , * schema.Union :
258
259
r .execSelections (ctx , sels , path , s , resolver , out , false )
259
260
return
260
261
}
261
262
262
- if ! nonNull {
263
- if resolver .IsNil () {
264
- out .WriteString ("null" )
265
- return
266
- }
263
+ // Any pointers or interfaces at this point should be non-nil, so we can get the actual value of them
264
+ // for serialization
265
+ if resolver .Kind () == reflect .Ptr || resolver .Kind () == reflect .Interface {
267
266
resolver = resolver .Elem ()
268
267
}
269
268
0 commit comments