Skip to content

Commit f41bad4

Browse files
authored
Merge pull request rmosolgo#4866 from rmosolgo/treat-max-page-size-as-implicit-first
Revert hasNextPage change when first isn't present
2 parents 393402e + 9582e76 commit f41bad4

File tree

7 files changed

+16
-15
lines changed

7 files changed

+16
-15
lines changed

gemfiles/rails_7.1.gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
1313
gem "sequel"
1414
gem "evt"
1515
gem "async"
16+
gem "libev_scheduler"
1617

1718
gemspec path: "../"

lib/graphql/pagination/array_connection.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ def load_nodes
5656
false
5757
end
5858

59-
@has_next_page = if first_value && first
60-
# There are more items after these items
61-
sliced_nodes.count > first
62-
elsif before
59+
@has_next_page = if before
6360
# The original array is longer than the `before` index
6461
index_from_cursor(before) < items.length + 1
62+
elsif first
63+
# There are more items after these items
64+
sliced_nodes.count > first
6565
else
6666
false
6767
end

lib/graphql/pagination/relation_connection.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ def has_previous_page
2929

3030
def has_next_page
3131
if @has_next_page.nil?
32-
@has_next_page = if first && first_value
32+
@has_next_page = if before_offset && before_offset > 0
33+
true
34+
elsif first
3335
if @nodes && @nodes.count < first
3436
false
3537
else
3638
relation_larger_than(sliced_nodes, @sliced_nodes_offset, first)
3739
end
38-
elsif before_offset && before_offset > 0
39-
true
4040
else
4141
false
4242
end

spec/integration/mongoid/graphql/relay/mongo_relation_connection_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def get_last_cursor(result)
238238
# Max page size is applied _without_ `first`, also
239239
result = star_trek_query(query_string)
240240
assert_equal(2, result["data"]["federation"]["bases"]["edges"].size)
241-
assert_equal(false, result["data"]["federation"]["bases"]["pageInfo"]["hasNextPage"], "hasNextPage is false when first is not specified")
241+
assert_equal(true, result["data"]["federation"]["bases"]["pageInfo"]["hasNextPage"], "hasNextPage is false when first is not specified")
242242
end
243243

244244
it "applies to queries by `last`" do
@@ -297,7 +297,7 @@ def get_last_cursor(result)
297297
# Max page size is applied _without_ `first`, also
298298
result = star_trek_query(query_string)
299299
assert_equal(3, result["data"]["federation"]["bases"]["edges"].size)
300-
assert_equal(false, result["data"]["federation"]["bases"]["pageInfo"]["hasNextPage"], "hasNextPage is false when first is not specified")
300+
assert_equal(true, result["data"]["federation"]["bases"]["pageInfo"]["hasNextPage"], "hasNextPage is false when first is not specified")
301301
end
302302

303303
it "applies to queries by `last`" do

spec/integration/rails/graphql/relay/array_connection_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def get_names(result)
174174
# Max page size is applied _without_ `first`, also
175175
result = star_wars_query(query_string)
176176
assert_equal(["Yavin", "Echo Base"], get_names(result))
177-
assert_equal(false, get_page_info(result)["hasNextPage"], "hasNextPage is false when first is not specified")
177+
assert_equal(true, get_page_info(result)["hasNextPage"], "hasNextPage is false when first is not specified")
178178
end
179179

180180
it "applies to queries by `last`" do
@@ -234,7 +234,7 @@ def get_page_info(result)
234234
# Max page size is applied _without_ `first`, also
235235
result = star_wars_query(query_string)
236236
assert_equal(["Yavin", "Echo Base", "Secret Hideout"], get_names(result))
237-
assert_equal(false, get_page_info(result)["hasNextPage"], "hasNextPage is false when first is not specified")
237+
assert_equal(true, get_page_info(result)["hasNextPage"], "hasNextPage is false when first is not specified")
238238
end
239239

240240
it "applies to queries by `last`" do

spec/integration/rails/graphql/relay/relation_connection_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def get_last_cursor(result)
287287
# Max page size is applied _without_ `first`, also
288288
result = star_wars_query(query_string)
289289
assert_equal(2, result["data"]["empire"]["bases"]["edges"].size)
290-
assert_equal(false, result["data"]["empire"]["bases"]["pageInfo"]["hasNextPage"], "hasNextPage is false when first is not specified")
290+
assert_equal(true, result["data"]["empire"]["bases"]["pageInfo"]["hasNextPage"], "hasNextPage is false when first is not specified")
291291
end
292292

293293
it "applies to queries by `last`" do
@@ -346,7 +346,7 @@ def get_last_cursor(result)
346346
# Max page size is applied _without_ `first`, also
347347
result = star_wars_query(query_string)
348348
assert_equal(3, result["data"]["empire"]["bases"]["edges"].size)
349-
assert_equal(false, result["data"]["empire"]["bases"]["pageInfo"]["hasNextPage"], "hasNextPage is false when first is not specified")
349+
assert_equal(true, result["data"]["empire"]["bases"]["pageInfo"]["hasNextPage"], "hasNextPage is false when first is not specified")
350350
end
351351

352352
it "applies to queries by `last`" do

spec/support/connection_assertions.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def assert_names(expected_names, result)
255255
assert_names [], res
256256

257257
res = exec_query(query_str, after: after_cursor, before: before_cursor, first: 3)
258-
assert_equal false, get_page_info(res, "hasNextPage")
258+
assert_equal true, get_page_info(res, "hasNextPage")
259259
assert_equal true, get_page_info(res, "hasPreviousPage")
260260
assert_names [], res
261261
end
@@ -317,7 +317,7 @@ def assert_names(expected_names, result)
317317
res = exec_query(query_str, {})
318318
# Neither first nor last was provided, so default_page_size was applied.
319319
assert_names(["Avocado", "Beet", "Cucumber", "Dill"], res)
320-
assert_equal false, get_page_info(res, "hasNextPage")
320+
assert_equal true, get_page_info(res, "hasNextPage")
321321
assert_equal false, get_page_info(res, "hasPreviousPage")
322322
end
323323

0 commit comments

Comments
 (0)