Skip to content

Make the cursor pager's previous page return the page before the current one - #101

Merged
joadan merged 1 commit into
mainfrom
fix-previous-page
Oct 13, 2026
Merged

joadan merged 1 commit into
mainfrom
fix-previous-page

Conversation

@joadan

@joadan joadan commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

GraphCursorPager.PreviousPageAsync / PreviousPageWithResultAsync sent the current page's end cursor as before while keeping first: N. first + before asks for the first N items before that cursor, which always counts from the top of the list - so going back from page 3 returned page 1. The existing Orders_Paging test only went back from page 2, where the two coincide, so it passed by accident.

Fix

  • The pager remembers the page size the query was built with (first, else last).
  • Previous page: last: <page size>, before: StartCursor; clears first/after.
  • Next page: first: <page size>, after: EndCursor; clears last/before so you can go back and forth.

Tests

Two new tests in QueryPagingTests page forward to page 3 with Orders(first: 1), go back, and assert they land on page 2 (and that going forward again returns page 3). Both failed before the fix.

Known limitation

If the query sets neither first nor last (server default page size), the pager has no page size to send as last, so going back is still only correct from page 2.

…ent one

PreviousPageAsync sent the current page's end cursor as 'before' while keeping 'first', which asks for the first N items before that cursor - always the top of the list. Going back from page 3 returned page 1, and the existing test only went back from page 2, so it passed by accident.

The pager now remembers the page size the query was built with and pages backwards with 'last' plus the current page's start cursor, and forwards with 'first' plus the end cursor, clearing the other pair each way.
@joadan
joadan merged commit 16d35cf into main Oct 13, 2026
@joadan
joadan deleted the fix-previous-page branch October 13, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant