Skip to content

Commit 8f04cc9

Browse files
committed
Make a RunQueue object
1 parent fdbfd2f commit 8f04cc9

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

lib/graphql/execution/interpreter/runtime.rb

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,28 @@ def current_object
3434
:current_arguments, :current_field, :was_authorized_by_scope_items
3535
end
3636

37+
class RunQueue
38+
def initialize(dataloader:, lazies_at_depth:)
39+
@next_flush = []
40+
@dataloader = dataloader
41+
@lazies_at_depth = lazies_at_depth
42+
end
43+
44+
def <<(step)
45+
@next_flush << step
46+
end
47+
48+
def complete
49+
while (fl = @next_flush) && !fl.empty?
50+
@next_flush = []
51+
while (step = fl.shift)
52+
step.run
53+
end
54+
Interpreter::Resolve.resolve_each_depth(@lazies_at_depth, @dataloader)
55+
end
56+
end
57+
end
58+
3759
# @return [GraphQL::Query]
3860
attr_reader :query
3961

@@ -64,13 +86,11 @@ def initialize(query:, lazies_at_depth:)
6486
end
6587
# { Class => Boolean }
6688
@lazy_cache = {}.compare_by_identity
67-
@run_queue = []
89+
@run_queue = RunQueue.new(dataloader: @dataloader, lazies_at_depth: @lazies_at_depth)
6890
end
6991

7092
def final_result
71-
while (step = @run_queue.shift)
72-
step.run
73-
end
93+
@run_queue.complete
7494
@response.respond_to?(:graphql_result_data) ? @response.graphql_result_data : @response
7595
end
7696

@@ -222,9 +242,7 @@ def run_eager
222242
else
223243
raise "Invariant: unsupported type kind for partial execution: #{root_type.kind.inspect} (#{root_type})"
224244
end
225-
while (run_step = @run_queue.shift)
226-
run_step.run
227-
end
245+
@run_queue.complete
228246
nil
229247
end
230248

lib/graphql/execution/interpreter/runtime/graphql_result.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def run
295295
end
296296
end
297297
# Detect whether this error came while calling `.each` (before `idx` is set) or while running list *items* (after `idx` is set)
298-
error_is_non_null = idx.nil? ? is_non_null : inner_type.non_null?
298+
error_is_non_null = idx.nil? ? @graphql_is_non_null_in_parent : inner_type.non_null?
299299
@runtime.continue_value(list_value, @graphql_field, error_is_non_null, @ast_node, @graphql_result_name, @graphql_parent)
300300
end
301301

0 commit comments

Comments
 (0)