-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add support for cursor-based pagination #8313
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit ae7094c:
|
A few tests to satisfy, but the on the face of it, this pull request looks great @marekryb! 💛
I'm happy to not block on this pull request for that, but we should add documentation for |
@dcousens Seems everything is passing now. Looks good from my point of view. |
}`, | ||
}); | ||
expect(errors).toEqual(undefined); | ||
let currentOrder = 6; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should alter this to use an autoincrement
identifier rather than something named order
, but we won't block merging on that
Currently Keystone supports only offset-based pagination through
take
andskip
arguments in GraphQL queries.However Prisma, which is used under the hood, supports both offset and cursor pagination.
Above article summarizes pros and cons of each solution very well. My motivation comes from the fact that I am using infinite scrolling exclusively on the frontend.
Related issue: #34
This PR add cursor-based pagination that follow Prisma's syntax by:
cursor
argument to GraphQL queries that returns array (also through relation)cursor
to context.query / context.db APIcursor
value to Prismacursor
argument is an object with same type as eg.connect
in relation - all unique fields are allowed. Existingtake
andskip
do not change andcursor
usage is optional. Therefore this is (as fat as I can tell) non-breaking change.Currently this PR includes some very basic unit tests. I can add more, but keep in mind that no special logic is introduced here, so extensive testing would actually test Prisma and not Keystone.
Please have a look and let me know whether you are interested in going forward with this PR. What did I miss? What other changes are needed? I would say documentation, but surprisingly I could not find anything in the docs on
take
andskip
either ^_^