@@ -348,6 +348,13 @@ def set_result(selection_result, result_name, value)
348
348
( ( nn = selection_result . graphql_non_null_field_names ) && nn . include? ( result_name ) ) # this value would be written into a field that doesn't allow nils
349
349
)
350
350
# This is an invalid nil that should be propagated
351
+ # One caller of this method passes a block,
352
+ # namely when application code returns a `nil` to GraphQL and it doesn't belong there.
353
+ # The other possibility for reaching here is when a field returns an ExecutionError, so we write
354
+ # `nil` to the response, not knowing whether it's an invalid `nil` or not.
355
+ # (And in that case, we don't have to call the schema's handler, since it's not a bug in the application.)
356
+ # TODO the code is trying to tell me something.
357
+ yield if block_given?
351
358
parent = selection_result . graphql_parent
352
359
name_in_parent = selection_result . graphql_result_name
353
360
if parent . nil? # This is a top-level result hash
@@ -369,11 +376,10 @@ def continue_value(path, value, parent_type, field, is_non_null, ast_node, resul
369
376
case value
370
377
when nil
371
378
if is_non_null
372
- err = parent_type ::InvalidNullError . new ( parent_type , field , value )
373
- if !dead_result? ( selection_result )
379
+ set_result ( selection_result , result_name , nil ) do
380
+ # This block is called if `result_name` is not dead. (Maybe a previous invalid nil caused it be marked dead.)
381
+ err = parent_type ::InvalidNullError . new ( parent_type , field , value )
374
382
schema . type_error ( err , context )
375
- set_result ( selection_result , result_name , nil )
376
- selection_result . graphql_dead = true
377
383
end
378
384
else
379
385
set_result ( selection_result , result_name , nil )
0 commit comments