Skip to content

Fix hasPreviousPage/hasNextPage logic for array connections#400

Open
fraunos wants to merge 1 commit intographql:mainfrom
fraunos:main
Open

Fix hasPreviousPage/hasNextPage logic for array connections#400
fraunos wants to merge 1 commit intographql:mainfrom
fraunos:main

Conversation

@fraunos
Copy link
Copy Markdown

@fraunos fraunos commented Mar 12, 2026

Update connectionFromArraySlice to follow Relay spec for hasPreviousPage and hasNextPage.

This makes the PageInfo return hasPreviousPage and hasNextPage regardless of the direction of pagination (first with after or last with before)

Update connectionFromArraySlice to follow Relay spec for hasPreviousPage
and hasNextPage.
@linux-foundation-easycla
Copy link
Copy Markdown

CLA Not Signed

@benjie
Copy link
Copy Markdown
Member

benjie commented Mar 12, 2026

The relay spec is a bit wishy-washy on this, in particular:

hasPreviousPage [...] If the client is paginating with first/after, then the client may return true if edges prior to after exist, if it can do so efficiently, otherwise may return false.

The "if it can do so efficiently" is typically "no".

With limit/offset pagination it's cheap to determine if you have a previous/next page (previous: is offset > 0, next: fetch 1 extra, if present then has next) but with actual cursor pagination (where cursors are not a simple offset) it's normally much harder to determine if there's a previous page when paginating forward, often requiring a second (reverse) fetch. The end result is that most implementations simply say "we can't do it efficiently" and return false. I've not reviewed this library or your edits, but wanted to make you aware of this subtlety in case you didn't already know.

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.

2 participants