graphql-python / graphql-python/graphene-django
Backward pagination when QuerySet larger than Relay Connection limit
- Dominant language
- Python
- Stars
- 4.4k
- Forks
- 760
- PR merge metrics
- No merged PRs in 30d
Description
It appears that backward pagination may not work as expected when the size of the underlying QuerySet is larger than the [RELAY_CONNECTION_MAX_LIMIT](https://docs.graphene-python.org/projects/django/en/latest/settings/#relay-connection-max-limit).
Below is an example.
Assume a `Project` model, with a `number` property used as the default ordering, and that the database contains 500 projects (with `number` incrementing from `1` to `500`).
The following query:
```gql
query {
projects (last: 2) {
edges {
node {
number
}
}
}
}
```
will return:
```json
{
"data": {
"projects": {
"edges": [
{
"node": {
"number": 99
}
},
{
"node": {
"number": 100
}
}
]
}
}
}
```
instead of `Project 499` and `Project 500` (the actual last 2 projects in the database).
This is because `RELAY_CONNECTION_MAX_LIMIT=100` and therefore, the last 2 projects of the first 100 projects are returned instead.
*To confirm my understanding of pagination, I've tried running a similar query on the public [GitLab GraphQL API](https://gitlab.com/-/graphql-explorer), which behaves as expected (i.e., in the absence of `before`, it implicitly uses the last object in DB, according to the natural table ordering).*
---
Environment:
- Version: `v2.12.1`
- Platform: `Linux`
Contributor guide
Assessment
This issue has not been assessed yet.