Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions lib/graphql/execution/interpreter/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lib/graphql/execution/interpreter/runtime/graphql_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading