Skip to content

Commit 5129fd5

Browse files
committed
Disambiguate result variable in runtime code; move depth calculation to method
1 parent 636a154 commit 5129fd5

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

lib/graphql/execution/interpreter/runtime.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,6 @@ def minimal_after_lazy(value, &block)
890890
# @return [GraphQL::Execution::Lazy, Object] If loading `object` will be deferred, it's a wrapper over it.
891891
def after_lazy(lazy_obj, field:, owner_object:, arguments:, ast_node:, result:, result_name:, eager: false, runtime_state:, trace: true, &block)
892892
if lazy?(lazy_obj)
893-
orig_result = result
894893
was_authorized_by_scope_items = runtime_state.was_authorized_by_scope_items
895894
lazy = GraphQL::Execution::Lazy.new(field: field) do
896895
# This block might be called in a new fiber;
@@ -900,13 +899,13 @@ def after_lazy(lazy_obj, field:, owner_object:, arguments:, ast_node:, result:,
900899
runtime_state.current_field = field
901900
runtime_state.current_arguments = arguments
902901
runtime_state.current_result_name = result_name
903-
runtime_state.current_result = orig_result
902+
runtime_state.current_result = result
904903
runtime_state.was_authorized_by_scope_items = was_authorized_by_scope_items
905904
# Wrap the execution of _this_ method with tracing,
906905
# but don't wrap the continuation below
907-
result = nil
906+
sync_result = nil
908907
inner_obj = begin
909-
result = if trace
908+
sync_result = if trace
910909
@current_trace.begin_execute_field(field, owner_object, arguments, query)
911910
@current_trace.execute_field_lazy(field: field, query: query, object: owner_object, arguments: arguments, ast_node: ast_node) do
912911
schema.sync_lazy(lazy_obj)
@@ -924,7 +923,7 @@ def after_lazy(lazy_obj, field:, owner_object:, arguments:, ast_node:, result:,
924923
end
925924
ensure
926925
if trace
927-
@current_trace.end_execute_field(field, owner_object, arguments, query, result)
926+
@current_trace.end_execute_field(field, owner_object, arguments, query, sync_result)
928927
end
929928
end
930929
yield(inner_obj, runtime_state)
@@ -934,12 +933,7 @@ def after_lazy(lazy_obj, field:, owner_object:, arguments:, ast_node:, result:,
934933
lazy.value
935934
else
936935
set_result(result, result_name, lazy, false, false) # is_non_null is irrelevant here
937-
current_depth = 0
938-
while result
939-
current_depth += 1
940-
result = result.graphql_parent
941-
end
942-
@dataloader.lazy_at_depth(current_depth, lazy)
936+
@dataloader.lazy_at_depth(result.depth, lazy)
943937
lazy
944938
end
945939
else

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ def build_path(path_array)
4242
end
4343
end
4444

45+
def depth
46+
@depth ||= if @graphql_parent
47+
@graphql_parent.depth + 1
48+
else
49+
1
50+
end
51+
end
52+
4553
attr_accessor :graphql_dead
4654
attr_reader :graphql_parent, :graphql_result_name, :graphql_is_non_null_in_parent,
4755
:graphql_application_value, :graphql_result_type, :graphql_selections, :graphql_is_eager, :ast_node, :graphql_arguments, :graphql_field

0 commit comments

Comments
 (0)