Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

Allow basic bi-directional windowed pagination according to Relay spec #2765

@codepunkt

Description

@codepunkt

The hasPreviousPage provided by PageInfo on connection queries seems to be false in circumstances where i would expect them to be true - which means that basic bi-directional windowed pagination can not be performed satisfyingly at the moment.

A simple example where you have a list of 5 posts (ids "1"-"5") in the database and query postsConnection, paginating forward using a first limit and an after cursor:

first after startCursor endCursor hasNextPage hasPreviousPage
2 "1" "2" true false
2 "2" "3" "4" true false
2 "4" "5" false false

We might only want to show 2 items at a time with forward & back buttons. The hasNextPage tells us reliably if we can expect another page or should disable the forward button. The hasPreviousPage doesn't do so. While we can still try to fetch the results from the previous page on click of the back button by querying with a before with the value of the startCursor, we don't know beforehand if we will get any results or simply turn up empty.

What is expected is instead this:

first after startCursor endCursor hasNextPage hasPreviousPage
2 "1" "2" true false
2 "2" "3" "4" true true
2 "4" "5" false true

The same problem occurs when paginating backwards using last and before instead of first and after - hasPreviousPage is correctly set but hasNextPage is always false.

The relay spec states:

hasPreviousPage is used to indicate whether more edges exist prior to the set defined by the clients arguments. If the client is paginating with last/before, then the server must return true if prior edges exist, otherwise false. 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.

hasNextPage is used to indicate whether more edges exist following the set defined by the clients arguments. If the client is paginating with first/after, then the server must return true if further edges exist, otherwise false. If the client is paginating with last/before, then the client may return true if edges further from before exist, if it can do so efficiently, otherwise may return false.

Therefore i propose that you handle this by returning true if edges prior or after exist regardless of pagination direction. That would be extremely helpful!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions