DEV Community


Discussion on: Connection based pagination in GraphQL

kazekyo profile image
Kyohei Nakamori

Great article, thank you for writing it up!

If you're a backend engineer and looking at this comment, be careful of generating cursors. Many of the GraphQL frameworks used on the backend convert offsets to cursors, so they can't automatically generate stable pagination.
graphql-relay-js uses offsets, and many frameworks follow it. Of course, graphql-relay-js says "It uses array offsets as pagination, so pagination will only work if the array is static."

To make pagination stable, I think the cursor needs to be persistent; something like an id.
But we have to write code that sorts the list by some column and uses an id to get 10 items from the middle of the list. Some DBs allow you to do this easily, and some DBs make it very difficult for you to do it.
Also, we should think about what happens if you generate a cursor from an id and then the data is deleted.
Anyway, this isn't easy.

*What is explained in this article is correct, but I just wanted to share the point above.