DEV Community

Discussion on: GraphQL Pagination

Collapse
acidic9 profile image
Ari Seyhun • Edited on

Thanks for this article El Housseine Jaafari!

I am implementing this for myself and using the ID as the cursor works just fine when sorting by time, but in my case I also want to sort by "rating" (a column in my database).

Would it be appropriate to make the cursor be in the shape of {rating}:{created_at} encoded as base64?
For example: 30:1613828846856 for a rating of 30 with the timestamp as 1613828846856 (which would be MzA6MTYxMzgyODg0Njg1Ng== encoded as base64).

I'm not sure if this is hacky but it's the only kind of solution I can come up with for an SQL which ends with ORDER BY rating, created_at

Collapse
jefferyhus profile image
El Housseine Jaafari Author

Your case is not easy in case of using a relational database. But there is the solution to create a view from your query and add an attribute that will be a combination of the rating & the ID and then use the view to fetch data from it and this way the pagination will work like a charm for you.