Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RelationConnections when relation already has limit #4104

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/graphql/pagination/relation_connection.rb
Expand Up @@ -117,6 +117,8 @@ def calculate_sliced_nodes_parameters
return
else
next_offset = relation_offset(items) || 0
relation_limit = relation_limit(items)

if after_offset
next_offset += after_offset
end
Expand Down
33 changes: 31 additions & 2 deletions spec/graphql/pagination/active_record_relation_connection_spec.rb
Expand Up @@ -27,14 +27,16 @@ def total_count
total_count_connection_class: RelationConnectionWithTotalCount,
get_items: -> {
if Food.respond_to?(:scoped)
Food.scoped # Rails 3-friendly version of .all
Food.scoped.limit(limit) # Rails 3-friendly version of .all
else
Food.all
Food.all.limit(limit)
end
}
)
}

let(:limit) { nil }

include ConnectionAssertions

it "maintains an application-provided offset" do
Expand Down Expand Up @@ -62,6 +64,33 @@ def total_count
assert_equal ["Cucumber", "Dill"], results["data"]["offsetItems"]["nodes"].map { |n| n["name"] }
end

describe 'with application-provided limit, which is smaller than the max_page_size' do
let(:limit) { 1 }

it "maintains an application-provided limit" do
results = schema.execute("{
limitedItems {
nodes { name }
}
}")
assert_equal ["Avocado"], results["data"]["limitedItems"]["nodes"].map { |n| n["name"] }
end
end

describe 'with application-provided limit, which is larger than the max_page_size' do
let(:limit) { 3 }

it "applies a field-level max-page-size configuration" do
results = schema.execute("{
limitedItems {
nodes { name }
}
}")
assert_equal ["Avocado", "Beet"], results["data"]["limitedItems"]["nodes"].map { |n| n["name"] }
end
end


it "doesn't run pageInfo queries when not necessary" do
results = nil
log = with_active_record_log do
Expand Down