@@ -58,7 +58,7 @@ def run_eager
58
58
write_in_response ( path , nil )
59
59
nil
60
60
else
61
- evaluate_selections ( path , object_proxy , root_type , root_operation . selections , root_operation_type : root_op_type )
61
+ evaluate_selections ( path , context . scoped_context , object_proxy , root_type , root_operation . selections , root_operation_type : root_op_type )
62
62
nil
63
63
end
64
64
end
@@ -118,7 +118,7 @@ def gather_selections(owner_object, owner_type, selections, selections_by_name)
118
118
end
119
119
end
120
120
121
- def evaluate_selections ( path , owner_object , owner_type , selections , root_operation_type : nil )
121
+ def evaluate_selections ( path , scoped_context , owner_object , owner_type , selections , root_operation_type : nil )
122
122
@interpreter_context [ :current_object ] = owner_object
123
123
@interpreter_context [ :current_path ] = path
124
124
selections_by_name = { }
@@ -163,6 +163,7 @@ def evaluate_selections(path, owner_object, owner_type, selections, root_operati
163
163
@interpreter_context [ :current_path ] = next_path
164
164
@interpreter_context [ :current_field ] = field_defn
165
165
166
+ context . scoped_context = scoped_context
166
167
object = owner_object
167
168
168
169
if is_introspection
@@ -221,7 +222,7 @@ def evaluate_selections(path, owner_object, owner_type, selections, root_operati
221
222
rescue GraphQL ::ExecutionError => err
222
223
err
223
224
end
224
- after_lazy ( app_result , owner : owner_type , field : field_defn , path : next_path , owner_object : object , arguments : kwarg_arguments ) do |inner_result |
225
+ after_lazy ( app_result , owner : owner_type , field : field_defn , path : next_path , scoped_context : context . scoped_context , owner_object : object , arguments : kwarg_arguments ) do |inner_result |
225
226
continue_value = continue_value ( next_path , inner_result , field_defn , return_type . non_null? , ast_node )
226
227
if HALT != continue_value
227
228
continue_field ( next_path , continue_value , field_defn , return_type , ast_node , next_selections , false , object , kwarg_arguments )
@@ -295,7 +296,7 @@ def continue_field(path, value, field, type, ast_node, next_selections, is_non_n
295
296
r
296
297
when "UNION" , "INTERFACE"
297
298
resolved_type_or_lazy = query . resolve_type ( type , value )
298
- after_lazy ( resolved_type_or_lazy , owner : type , path : path , field : field , owner_object : owner_object , arguments : arguments ) do |resolved_type |
299
+ after_lazy ( resolved_type_or_lazy , owner : type , path : path , scoped_context : context . scoped_context , field : field , owner_object : owner_object , arguments : arguments ) do |resolved_type |
299
300
possible_types = query . possible_types ( type )
300
301
301
302
if !possible_types . include? ( resolved_type )
@@ -315,12 +316,12 @@ def continue_field(path, value, field, type, ast_node, next_selections, is_non_n
315
316
rescue GraphQL ::ExecutionError => err
316
317
err
317
318
end
318
- after_lazy ( object_proxy , owner : type , path : path , field : field , owner_object : owner_object , arguments : arguments ) do |inner_object |
319
+ after_lazy ( object_proxy , owner : type , path : path , scoped_context : context . scoped_context , field : field , owner_object : owner_object , arguments : arguments ) do |inner_object |
319
320
continue_value = continue_value ( path , inner_object , field , is_non_null , ast_node )
320
321
if HALT != continue_value
321
322
response_hash = { }
322
323
write_in_response ( path , response_hash )
323
- evaluate_selections ( path , continue_value , type , next_selections )
324
+ evaluate_selections ( path , context . scoped_context , continue_value , type , next_selections )
324
325
response_hash
325
326
end
326
327
end
@@ -329,14 +330,15 @@ def continue_field(path, value, field, type, ast_node, next_selections, is_non_n
329
330
write_in_response ( path , response_list )
330
331
inner_type = type . of_type
331
332
idx = 0
333
+ scoped_context = context . scoped_context
332
334
value . each do |inner_value |
333
335
next_path = path . dup
334
336
next_path << idx
335
337
next_path . freeze
336
338
idx += 1
337
339
set_type_at_path ( next_path , inner_type )
338
340
# This will update `response_list` with the lazy
339
- after_lazy ( inner_value , owner : inner_type , path : next_path , field : field , owner_object : owner_object , arguments : arguments ) do |inner_inner_value |
341
+ after_lazy ( inner_value , owner : inner_type , path : next_path , scoped_context : scoped_context , field : field , owner_object : owner_object , arguments : arguments ) do |inner_inner_value |
340
342
# reset `is_non_null` here and below, because the inner type will have its own nullability constraint
341
343
continue_value = continue_value ( next_path , inner_inner_value , field , false , ast_node )
342
344
if HALT != continue_value
@@ -402,7 +404,7 @@ def resolve_if_late_bound_type(type)
402
404
# @param field [GraphQL::Schema::Field]
403
405
# @param eager [Boolean] Set to `true` for mutation root fields only
404
406
# @return [GraphQL::Execution::Lazy, Object] If loading `object` will be deferred, it's a wrapper over it.
405
- def after_lazy ( lazy_obj , owner :, field :, path :, owner_object :, arguments :, eager : false )
407
+ def after_lazy ( lazy_obj , owner :, field :, path :, scoped_context : , owner_object :, arguments :, eager : false )
406
408
@interpreter_context [ :current_object ] = owner_object
407
409
@interpreter_context [ :current_arguments ] = arguments
408
410
@interpreter_context [ :current_path ] = path
@@ -413,6 +415,7 @@ def after_lazy(lazy_obj, owner:, field:, path:, owner_object:, arguments:, eager
413
415
@interpreter_context [ :current_field ] = field
414
416
@interpreter_context [ :current_object ] = owner_object
415
417
@interpreter_context [ :current_arguments ] = arguments
418
+ context . scoped_context = scoped_context
416
419
# Wrap the execution of _this_ method with tracing,
417
420
# but don't wrap the continuation below
418
421
inner_obj = begin
@@ -424,7 +427,7 @@ def after_lazy(lazy_obj, owner:, field:, path:, owner_object:, arguments:, eager
424
427
rescue GraphQL ::ExecutionError , GraphQL ::UnauthorizedError => err
425
428
yield ( err )
426
429
end
427
- after_lazy ( inner_obj , owner : owner , field : field , path : path , owner_object : owner_object , arguments : arguments , eager : eager ) do |really_inner_obj |
430
+ after_lazy ( inner_obj , owner : owner , field : field , path : path , scoped_context : context . scoped_context , owner_object : owner_object , arguments : arguments , eager : eager ) do |really_inner_obj |
428
431
yield ( really_inner_obj )
429
432
end
430
433
end
0 commit comments