Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Change metadata #84

Open
bruno-b-martins opened this issue Oct 12, 2020 · 1 comment · May be fixed by #133
Open

Suggestion: Change metadata #84

bruno-b-martins opened this issue Oct 12, 2020 · 1 comment · May be fixed by #133

Comments

@bruno-b-martins
Copy link
Contributor

bruno-b-martins commented Oct 12, 2020

TL;DR

Make after and before always present and add has_next_page and has_previous_page booleans to metada.


Hello there 👋

I've recently started using this library to cursor paginate a list in a small Phoenix + Vue project and bumped into an issue that required a lot of work-arounds when using this in an infinite scroll scenario.

Problem

Picture this:
We want to paginate through 5 records ([1, 2, 3, 4, 5]) 3 at a time (limit: 3).
So, the first query returns something like this:

entries: [1, 2, 3], metadata: { after: 3, before: nil, ... }

On the client-side application I push the 3 entries to an items array and store the after cursor in a pagination object.
The second query then will ask for 3 records after the cursor 3 and paginatior returns the following:

entries: [4, 5], metadata: { after: nil, before: 4, ... }

On the client-side application I push the 2 entries to the items array and now the after cursor is null so if I store it and use it, the next query will return the first 3 entries again. I can't use the before cursor as well because the next query would then return me the 5th item again.

I built a bit of a complex work-around on the client-side where I fetch the before the last and the last items just to get the cursor of the last item.

Suggestion

Make the after and before cursors be always present so that the consumers of the API always have the beginning and end of the page.
Add two different metadata properties to show that there is a next page and a previous page.
I suggest has_next_page and has_previous_page mimicking graphQL's relay style pagination - https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo

What do you think?

@benwoodward
Copy link

benwoodward commented Mar 8, 2021

Add two different metadata properties to show that there is a next page and a previous page.
I suggest has_next_page and has_previous_page mimicking graphQL's relay style pagination -

Came here to ask for the same functionality. This would simplify graphql-consuming code on the client.

ericsullivan added a commit to annkissam/paginator that referenced this issue Aug 24, 2021
@ericsullivan ericsullivan linked a pull request Aug 24, 2021 that will close this issue
ericsullivan added a commit to annkissam/paginator that referenced this issue Jan 4, 2022
ericsullivan added a commit to annkissam/paginator that referenced this issue Feb 15, 2022
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 a pull request may close this issue.

2 participants