Windowed Pagination Plugin #333
-
Have you considered extending the Relay plugin to implement windowed pagination? Artsy have a thorough write-up of their schema design on their blog that is very interesting. Would be nice to support this behaviour out of the box, and I may have a use-case for it coming up. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 10 replies
-
This is not something I've thought about. It's a little more manual than having it added via a plugin, but would be simple to just add manuallly witha few helpers. You could probably just wrap the resolveOffsetConnection helper with something that adds the page cursors data (this is a little awkward right now, because you get the decoded limit and offset inside the callback) Then you can just define the page cursors field on the connection (you can even do this globally so every connection has it automatically) On my phone, sorry this is going to be pretty incomplete: async function resolveWindowedConnrction(...args) {
let cursors;
const result = await resolveOffsetConnection(...args, (...moreArgs) =>
const results = args.cb(moreArgs) // to lazy to destructure args for real on my phone, pretend this makes sense
cursors = ...
return results
})
return {...results, pageCursors: cursors }
} The for extending all connections (and updating the types so that connections need to return): Hope thisakes some amount of sense |
Beta Was this translation helpful? Give feedback.
-
@rogerballard Created a working example for you: https://github.com/hayes/pothos/blob/main/examples/relay-windowed-pagination/src/schema.ts#L141-L148 Pagination is something that isn't standardized enough to write a plugin that doesn't feel overly opinionated. Relay cursor pagination has a specification that I can follow, but there are too many open questions for windowed pagination. I think an approach like the one in the above example is simple enough to implement while letting users customize the exact format of their pagination types as needed. Let me know if this works for you, happy to discuss further if you have other ideas on how this should be handled. |
Beta Was this translation helpful? Give feedback.
-
@hayes thank you for creating a working example, much appreciated! 🙂 Agreed that pagination isn't exactly standardised in GraphQL. I think it's probably one of the least discussed topics within the GraphQL community, and similarly one essential feature that most GraphQL libraries don't help so much with - which I find surprising considering that many clients eventually want some sort of paginated datasets! I think from this perspective, having a simple (and reasonably opinionated) plugin/example would be beneficial for many users of pothos. Again, thanks for implementing an example - I'll base my implementation on your example, and let you know how it goes, and whether anything might be missing. 👍 |
Beta Was this translation helpful? Give feedback.
-
I'm needing to implement windowed pagination within the context of a
I'm new to all this and would really appreciate any guidance! Thanks :) |
Beta Was this translation helpful? Give feedback.
@rogerballard Created a working example for you: https://github.com/hayes/pothos/blob/main/examples/relay-windowed-pagination/src/schema.ts#L141-L148
Pagination is something that isn't standardized enough to write a plugin that doesn't feel overly opinionated. Relay cursor pagination has a specification that I can follow, but there are too many open questions for windowed pagination.
I think an approach like the one in the above example is simple enough to implement while letting users customize the exact format of their pagination types as needed.
Let me know if this works for you, happy to discuss further if you have other ideas on how this should be handled.