@@ -348,6 +348,13 @@ def set_result(selection_result, result_name, value)
348348 ( ( 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
349349 )
350350 # 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?
351358 parent = selection_result . graphql_parent
352359 name_in_parent = selection_result . graphql_result_name
353360 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
369376 case value
370377 when nil
371378 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 )
374382 schema . type_error ( err , context )
375- set_result ( selection_result , result_name , nil )
376- selection_result . graphql_dead = true
377383 end
378384 else
379385 set_result ( selection_result , result_name , nil )
0 commit comments