Skip to content

Commit 0cbf0a2

Browse files
committed
Add a test for different response when first is given by client
1 parent 17919f3 commit 0cbf0a2

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

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 before_offset && before_offset > 0
33-
true
34-
elsif first && first_value
32+
@has_next_page = if first && first_value
3533
if @nodes && @nodes.count < first
3634
false
3735
else
3836
relation_larger_than(sliced_nodes, @sliced_nodes_offset, first)
3937
end
38+
elsif before_offset && before_offset > 0
39+
true
4040
else
4141
false
4242
end

spec/support/connection_assertions.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ def assert_names(expected_names, result)
253253
assert_equal true, get_page_info(res, "hasNextPage")
254254
assert_equal true, get_page_info(res, "hasPreviousPage")
255255
assert_names [], res
256+
257+
res = exec_query(query_str, after: after_cursor, before: before_cursor, first: 3)
258+
assert_equal false, get_page_info(res, "hasNextPage")
259+
assert_equal true, get_page_info(res, "hasPreviousPage")
260+
assert_names [], res
256261
end
257262

258263
it "handles out-of-bounds cursors" do

0 commit comments

Comments
 (0)