Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/graphql/execution/selections_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def graphql_objects
def call
@all_selections = [{}, (prototype_result = {})]
@runner.gather_selections(@parent_type, @selections, self, self.query, @all_selections, @all_selections[1], into: @all_selections[0])
continue_selections = []
i = 0
l = @all_selections.length
while i < l
continue_selections = []
grouped_selections = @all_selections[i]
selections_prototype_result = @all_selections[i + 1]
if (directives_owner = grouped_selections.delete(:__node))
Expand Down
52 changes: 52 additions & 0 deletions spec/graphql/execution/selections_step_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frozen_string_literal: true
require "spec_helper"

describe GraphQL::Execution::SelectionsStep do
class SelectionsStepRunner
attr_reader :steps

def initialize(groups)
@groups = groups
@steps = []
end

def gather_selections(_parent_type, _selections, _step, _query, all_selections, _prototype_result, into:)
all_selections.replace(@groups)
end

def runtime_directives
GraphQL::EmptyObjects::EMPTY_HASH
end

def add_step(step)
@steps << step
end
end

it "enqueues each field step once across selection groups" do
first_step = Object.new
second_step = Object.new
inline_fragment = GraphQL.parse("{ ... @include(if: true) { __typename } }").definitions.first.selections.first
runner = SelectionsStepRunner.new([
{ "first" => first_step },
{ "first" => nil },
{ __node: inline_fragment, "second" => second_step },
{ "second" => nil },
])
step = GraphQL::Execution::SelectionsStep.new(
parent_type: nil,
field_resolve_step: nil,
selections: [],
objects: [],
results: [{}],
runner: runner,
query: Object.new,
path: [],
clobber: false,
)

step.call

assert_equal [first_step, second_step], runner.steps
end
end
Loading