@@ -12,7 +12,14 @@ class Runtime
12
12
module GraphQLResult
13
13
# These methods are private concerns of GraphQL-Ruby,
14
14
# they aren't guaranteed to continue working in the future.
15
- attr_accessor :graphql_dead , :graphql_non_null , :graphql_parent , :graphql_result_name
15
+ attr_accessor :graphql_dead , :graphql_parent , :graphql_result_name
16
+ # Although these are used by only one of the Result classes,
17
+ # it's handy to have the methods implemented on both (even though they just return `nil`)
18
+ # because it makes it easy to check if anything is assigned.
19
+ # @return [nil, Array<String>]
20
+ attr_accessor :graphql_non_null_field_names
21
+ # @return [nil, true]
22
+ attr_accessor :graphql_non_null_list_items
16
23
end
17
24
18
25
class GraphQLResultHash < Hash
@@ -204,7 +211,7 @@ def evaluate_selection(path, result_name, field_ast_nodes_or_ast_node, scoped_co
204
211
# the field's return type at this path in order
205
212
# to propagate `null`
206
213
if return_type . non_null?
207
- ( selections_result . graphql_non_null ||= [ ] ) . push ( result_name )
214
+ ( selections_result . graphql_non_null_field_names ||= [ ] ) . push ( result_name )
208
215
end
209
216
# Set this before calling `run_with_directives`, so that the directive can have the latest path
210
217
set_all_interpreter_context ( nil , field_defn , nil , next_path )
@@ -336,8 +343,10 @@ def dead_result?(selection_result)
336
343
def set_result ( selection_result , result_name , value )
337
344
if !dead_result? ( selection_result )
338
345
if value . nil? &&
339
- ( nn = selection_result . graphql_non_null ) &&
340
- ( nn == true || nn . include? ( result_name ) )
346
+ ( # there are two conditions under which `nil` is not allowed in the response:
347
+ ( selection_result . graphql_non_null_list_items ) || # this value would be written into a list that doesn't allow nils
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
+ )
341
350
# This is an invalid nil that should be propagated
342
351
parent = selection_result . graphql_parent
343
352
name_in_parent = selection_result . graphql_result_name
@@ -480,7 +489,7 @@ def continue_field(path, value, owner_type, field, current_type, ast_node, next_
480
489
when "LIST"
481
490
inner_type = current_type . of_type
482
491
response_list = GraphQLResultArray . new
483
- response_list . graphql_non_null = inner_type . non_null?
492
+ response_list . graphql_non_null_list_items = inner_type . non_null?
484
493
response_list . graphql_parent = selection_result
485
494
response_list . graphql_result_name = result_name
486
495
set_result ( selection_result , result_name , response_list )
0 commit comments