we have to rebuild a backend app based on REST services and since we have a lot of nested levels in the services we decided to innovate and try GraphQL.
We started doing simple things and the project looks very promising, however we started facing real world problems like pagination. In REST, pagination approach was straightforward, we use GET method with some parameters like pageSize and pageNumber (or offset) and we build sql queries to perform this pagination.
In GraphQL we were tackling the problem following the same approach, for example having this query:
users(size:5 offset:2) {
id
name
}
This approach looked simple to implement, however after digging deeper we found that the "best" pattern to implement this is the Connection one, which the query would look like this:
users(first:2) {
totalCount
edges {
node {
name
}
cursor
}
pageInfo {
endCursor
hasNextPage
}
}
Our data is persisted in a relational database, therefore I don't see how cursors can help (unless perhaps if I use autoincrement ID?).
Why is this complex approach the recommended one over the simple one? And also what cursor and endCursor will be storing? Am I misunderstanding something in my learning path?