-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pagination with "after" cursor results in ScrollPosition
that skips one extra item
#925
Comments
I've noticed the same issue. Also, the last and before includes the cursor provided as the "before", so |
It seems to be a regression from #916. |
@tata-dr-dk, thanks for the sample. Indeed #916 was a breaking change, but it was necessary to fix a problem that had been there from the start, and reverse another that was introduced in 1.2.4. That's pretty confusing I'll admit, but I believe the current behavior is correct. In the sample, there are 3 customers. Cursor If I use cursor
If I use |
Thanks @rstoyanchev for your response I am totally new to GraphQL, but for me there still seems to be a incompatible behavior. I would expect the cursor X returned for any document to be usable in the after clause, which then would result in the next page starting from the document that exactly follows it, e.g. with cursor Y. I updated the example unit tests with two cases, one using the first returned document.cursor, the other using the pageInfo.endCursor to query the next page. Both seem to show that there is a missing document, and an extra erroneous skip indeed is happening. It would surprise me if that is indeed the correct behavior. In that case, requesting the next page would require the client to use the cursor with index "pageSize - 1", and the endCursor would not be of any value The first document cursor returned is T18x and not T18w |
That helps better to demonstrate the issue, thanks. It looks like OffsetScrollPosition adds 1 to its offset, so when we render cursors starting from 1. However, when the cursor is sent back and used, the repository seems to treat the offset as zero based. I'm not sure if this is expected behavior for Spring Data or not, but I will investigate. |
ScrollPosition
that skips one extra item
After some discussions with the Spring Data team, there is now a change planned on their side, see spring-projects/spring-data-commons#3070. After that we will see if we need any follow-up changes here. |
We've decided to apply a temporary fix in spring-graphql, which allows us to release a fix for this regression without delay, and gives Spring Data a bit more time to work out how to proceed. Once there is a clear direction under spring-projects/spring-data-commons#3070, we'll adapt here as needed. @tata-dr-dk, @JIngrahamTG, @pax95, if you are able to confirm the fix that's in 1.2.6-SNAPSHOT via https://repo.spring.io/snapshot that would be much appreciated. |
@rstoyanchev The fix works - thanks a lot! |
Thanks for the confirmation. For the upcoming 1.3 (RC1 released today, GA on May 21), there are underlying changes in Spring Data 2024 where offset positions start from 0 (rather than 1), and data stores treat offset positions as exclusive. We have adapted accordingly in #946. |
Using Graphql Query 'after' option with a cursor of position N, yields a result-set starting from position N+2 upwards, skipping the document right after the cursor that should have been included (N+1).
Using the latest graphql and mongodb starters
Using graphql @QueryMapping annotation and ScrollSubrange on a controller
and a query:
where 'T18x' is the cursor of the first document, results in subrange.position() of 2.
Using that position in a mongodb Query:
would actually skip 2 documents, and not start from document of position 2 (thus not inclusive).
Seems to be related to #916
A project reproducing the bug can be found here: graphql-bug
The text was updated successfully, but these errors were encountered: