Skip to content

Commit

Permalink
Move current_object implementation to GraphQLResult
Browse files Browse the repository at this point in the history
  • Loading branch information
rmosolgo committed Apr 26, 2024
1 parent e0ef989 commit 613ec24
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lib/graphql/execution/interpreter/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ class Interpreter
class Runtime
class CurrentState
def initialize
@current_object = nil
@current_field = nil
@current_arguments = nil
@current_result_name = nil
@current_result = nil
@was_authorized_by_scope_items = nil
end

def current_object
@current_result.graphql_application_value
end

attr_accessor :current_result, :current_result_name,
:current_arguments, :current_field, :current_object, :was_authorized_by_scope_items
:current_arguments, :current_field, :was_authorized_by_scope_items
end

# @return [GraphQL::Query]
Expand Down Expand Up @@ -79,9 +82,8 @@ def run_eager
root_operation = query.selected_operation
root_op_type = root_operation.operation_type || "query"
root_type = schema.root_type_for_operation(root_op_type)
@response = GraphQLResultHash.new(nil, root_type, nil, nil, false)
@response = GraphQLResultHash.new(nil, root_type, @query.root_value, nil, false)
st = get_current_runtime_state
st.current_object = query.root_value
st.current_result = @response
runtime_object = root_type.wrap(query.root_value, context)
runtime_object = schema.sync_lazy(runtime_object)
Expand All @@ -101,7 +103,7 @@ def run_eager
# directly evaluated and the results can be written right into the main response hash.
tap_or_each(gathered_selections) do |selections, is_selection_array|
if is_selection_array
selection_response = GraphQLResultHash.new(nil, root_type, nil, nil, false)
selection_response = GraphQLResultHash.new(nil, root_type, @query.root_value, nil, false)
final_response = @response
else
selection_response = @response
Expand All @@ -110,7 +112,6 @@ def run_eager

@dataloader.append_job {
st = get_current_runtime_state
st.current_object = query.root_value
st.current_result_name = nil
st.current_result = selection_response
# This is a less-frequent case; use a fast check since it's often not there.
Expand Down Expand Up @@ -334,7 +335,6 @@ def evaluate_selection_with_args(arguments, field_defn, ast_node, field_ast_node

def evaluate_selection_with_resolved_keyword_args(kwarg_arguments, resolved_arguments, field_defn, ast_node, field_ast_nodes, object, is_eager_field, result_name, selection_result, parent_object, return_type, return_type_non_null, runtime_state) # rubocop:disable Metrics/ParameterLists
runtime_state.current_field = field_defn
runtime_state.current_object = object
runtime_state.current_arguments = resolved_arguments
runtime_state.current_result_name = result_name
runtime_state.current_result = selection_result
Expand All @@ -356,7 +356,6 @@ def evaluate_selection_with_resolved_keyword_args(kwarg_arguments, resolved_argu
# This might be executed in a different context; reset this info
runtime_state = get_current_runtime_state
runtime_state.current_field = field_defn
runtime_state.current_object = object
runtime_state.current_arguments = resolved_arguments
runtime_state.current_result_name = result_name
runtime_state.current_result = selection_result
Expand Down Expand Up @@ -631,7 +630,6 @@ def continue_field(value, owner_type, field, current_type, ast_node, next_select
end
# reset this mutable state
# Unset `result_name` here because it's already included in the new response hash
runtime_state.current_object = continue_value
runtime_state.current_result_name = nil
runtime_state.current_result = this_result
# This is a less-frequent case; use a fast check since it's often not there.
Expand Down Expand Up @@ -795,7 +793,6 @@ def after_lazy(lazy_obj, field:, owner_object:, arguments:, ast_node:, result:,
# In that case, this will initialize a new state
# to avoid conflicting with the parent fiber.
runtime_state = get_current_runtime_state
runtime_state.current_object = owner_object
runtime_state.current_field = field
runtime_state.current_arguments = arguments
runtime_state.current_result_name = result_name
Expand Down

0 comments on commit 613ec24

Please sign in to comment.