diff --git a/lib/graphql/execution/interpreter/runtime.rb b/lib/graphql/execution/interpreter/runtime.rb index c13bea48a2..4724830817 100644 --- a/lib/graphql/execution/interpreter/runtime.rb +++ b/lib/graphql/execution/interpreter/runtime.rb @@ -890,7 +890,6 @@ def minimal_after_lazy(value, &block) # @return [GraphQL::Execution::Lazy, Object] If loading `object` will be deferred, it's a wrapper over it. def after_lazy(lazy_obj, field:, owner_object:, arguments:, ast_node:, result:, result_name:, eager: false, runtime_state:, trace: true, &block) if lazy?(lazy_obj) - orig_result = result was_authorized_by_scope_items = runtime_state.was_authorized_by_scope_items lazy = GraphQL::Execution::Lazy.new(field: field) do # 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:, runtime_state.current_field = field runtime_state.current_arguments = arguments runtime_state.current_result_name = result_name - runtime_state.current_result = orig_result + runtime_state.current_result = result runtime_state.was_authorized_by_scope_items = was_authorized_by_scope_items # Wrap the execution of _this_ method with tracing, # but don't wrap the continuation below - result = nil + sync_result = nil inner_obj = begin - result = if trace + sync_result = if trace @current_trace.begin_execute_field(field, owner_object, arguments, query) @current_trace.execute_field_lazy(field: field, query: query, object: owner_object, arguments: arguments, ast_node: ast_node) do schema.sync_lazy(lazy_obj) @@ -924,7 +923,7 @@ def after_lazy(lazy_obj, field:, owner_object:, arguments:, ast_node:, result:, end ensure if trace - @current_trace.end_execute_field(field, owner_object, arguments, query, result) + @current_trace.end_execute_field(field, owner_object, arguments, query, sync_result) end end yield(inner_obj, runtime_state) @@ -934,12 +933,7 @@ def after_lazy(lazy_obj, field:, owner_object:, arguments:, ast_node:, result:, lazy.value else set_result(result, result_name, lazy, false, false) # is_non_null is irrelevant here - current_depth = 0 - while result - current_depth += 1 - result = result.graphql_parent - end - @dataloader.lazy_at_depth(current_depth, lazy) + @dataloader.lazy_at_depth(result.depth, lazy) lazy end else diff --git a/lib/graphql/execution/interpreter/runtime/graphql_result.rb b/lib/graphql/execution/interpreter/runtime/graphql_result.rb index 00e78586bd..e42ea4bd21 100644 --- a/lib/graphql/execution/interpreter/runtime/graphql_result.rb +++ b/lib/graphql/execution/interpreter/runtime/graphql_result.rb @@ -42,6 +42,14 @@ def build_path(path_array) end end + def depth + @depth ||= if @graphql_parent + @graphql_parent.depth + 1 + else + 1 + end + end + attr_accessor :graphql_dead attr_reader :graphql_parent, :graphql_result_name, :graphql_is_non_null_in_parent, :graphql_application_value, :graphql_result_type, :graphql_selections, :graphql_is_eager, :ast_node, :graphql_arguments, :graphql_field