hasura / hasura/graphql-engine
Server: Relay based pagination with multiple sorting keys not working as expected
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Version Information
Server Version: 2.8.1
### Environment
OSS
### What is the current behaviour?
When paginating a mutable dataset we found that cursor based pagination creates a more reliable experience. Currently, that means utilizing the relay schema endpoint. However, when trying to use multiple sort keys we've experienced multiple failure modes.
I've put the full query we're having issues with towards the end of this section, but the problem we're having is with the `order_by` clause.
First we tried the below version as it is the one that's built by the console. With this one we got results back, but the ordering wasn't respected.
```gql
order_by: { pinned_at: desc_nulls_last, published_at: desc }
```
Then we tried this version of the `order_by`. With this one we received the ordering that we were expecting, however when we queried for the second page of posts, the second page came back as empty.
```gql
order_by: [{ pinned_at: desc_nulls_last }, { published_at: desc }]
```
For reference here's the full query we were experimenting with:
```gql
query GetPostsRelay($author_id: Int!, $after: String, $first: Int = 5) {
activity_post_connection(
where: { author_id: { _eq: $author_id } }
# order_by: { pinned_at: desc_nulls_last, published_at: desc }
order_by: [{ pinned_at: desc_nulls_last }, { published_at: desc }]
first: $first
after: $after
) {
edges {
node {
id
pinned_at
published_at
author_id
}
cursor
}
pageInfo {
hasNextPage
endCursor
}
}
}
```
### What is the expected behaviour?
We expect to receive all pinned posts first and then the remaining posts.
### Any possible solutions?
We've worked around it, kinda, by performing multiple queries. One to receive the pinned posts and the second to receive the non-pinned posts.
### Keywords
Relay, ordering, sorting, pagination, cursor pagination
Contributor guide
Assessment
This issue has not been assessed yet.