offset pagination support for relay connection
See original GitHub issueHi all, I have a use case to paginate results based on an offset. I figured I would be able to add “offset” into my graphQL query to achieve this. (source: https://graphql.org/learn/pagination/)
Specifically, I want to implement fetching page 3 results of a list, where each page has a size of 20. Doing this query throws “unknown argument “offset” on field allEntityA”
query {
allEntityA(first: 20, offset: 40) {
edges {
node {
}
}
}
}
I have already trasnformed my Django model into a type relay.Node
)
class entityANode(DjangoObjectType):
class Meta:
model = models.EntityA
interfaces = (relay.Node,)
How can I achieve jumping from page 1 to 3 without using cursor navigation?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:7
Top Results From Across the Web
9. Relay Support & Pagination - Join Monster
This approach is based of the OFFSET keyword in SQL – often used to get numbered pages. It uses a predictable, position-based integer...
Read more >GraphQL Pagination Primer: Offset vs. Cursor vs. Relay-Style ...
Offset -based pagination is useful when you need to know the total number of pages available. It can also easily support bi-directional ...
Read more >GraphQL Cursor Connections Specification - Relay
This specification aims to provide an option for GraphQL clients to consistently handle pagination best practices with support for related metadata via a ......
Read more >Understanding pagination: REST, GraphQL, and Relay
A connection is a paginated field on an object — for example, the friends field on a user or the comments field on...
Read more >Effortless Pagination with GraphQL and Relay? Really!
You start to realize that the cursor-based setup of a connection, along with a Relay pagination container, does not lend itself to this...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Not stale! This is a very common requirement and @NateScarlet’s PR provides it.
This is actually very easy to implement considering the underlying pagination in Graphene Django is an offset pagination. Indeed the cursor contains simply an offset already so you can rely on that. Here is a simple implementation that can be used in case it does not get incorporated in the project (it could be incorporated in the
DjangoFilterConnectionField
class as described here):and you just need to use
OffsetConnectionField
instead to define your query. For example in the cookbook example of the documentation:** Note ** @HenryKuria Your solution is not completely true. The combination of first and last does not completely cover the offset because of the
RELAY_CONNECTION_MAX_LIMIT
setting. Indeed you can’t setfirst: 310, last: 10
as it would raise an error. While with the implementation that I proposed we use a cursor so we do not get this error when doingfirst: 10, offset: 300
.