Open mattflorence opened 1 year ago
For curiosity, what would be an use case for an offset
parameter?
I mean, after
exists because of that, and even in the graphene link you shared has a # Remove the offset parameter and convert it to an after cursor.
comment, meaning they actually want to remove it at some point.
It would reduce some complexity using the GraphQL API in frontend for pagination, we wouldn't need to store the cursor returned by a previous query and use it as after
argument in the next. If we know we have 5 items per page for example, than offset is always a multiple of 5, we can easily jump to any page we want. Given this it would be more convenient to use offset
rather than after
.
I think what they meant by this : # Remove the offset parameter and convert it to an after cursor
is to take the argument offset
and evaluate what after
would be in that case inside the resolve_connection
method and not remove it from the library.
It would reduce some complexity using the GraphQL API in frontend for pagination, we wouldn't need to store the cursor returned by a previous query and use it as
after
argument in the next. If we know we have 5 items per page for example, than offset is always a multiple of 5, we can easily jump to any page we want. Given this it would be more convenient to useoffset
rather thanafter
.
Hrm, I see.
Actually, it is already possible for you to do that without needing an offset
argument. As long as you are using the ListConnection
, you can pass any cursor you want to it. I described that solution in this comment
Regarding changing the API, that would need to be done on strawberry core itself because the replay implementation is there. I'll move this issue to that repo so we can properly discuss this with other people.
It would be very useful to add an
offset
argument to relay connection. It's a feature that is implemented in graphene. See https://github.com/graphql-python/graphene-django/blob/v3.1.5/graphene_django/fields.py#L139-L145Feature Request Type
Description
When using this library's
limit/offset
pagination,pageInfo
doesn't updatehasPreviousPage
andhasNextPage
, they are always false. Currently, I am using a custom connection as a workaround:But that means a custom resolver would have to look like this:
Upvote & Fund