-
Notifications
You must be signed in to change notification settings - Fork 312
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
hasPreviousPage returns true incorrectly #841
Comments
Thanks for the report. Under spring-projects/spring-data-jpa#3180 you show invoking the repository with a I think with keyset scrolling, when there is a non-empty keyset, there may be more items in the overall result set that come ahead of that keyset, and there isn't an easy way to know if there are previous items because the query returns only items from the keyset forward. The only way to be certain time, with forward pagination at least, is when the keyset is empty, then we now it's the very first page, and that's how |
One more thought. The spec says this for
So for forward pagination we can always return
For backward pagination however, maybe we could do better. @mp911de any thoughts on that? It seems like for backwards pagination it would be possible to know if there are more to go which would be |
And of course the same is also true in reverse for |
My code is simple and I didn't try excluding the position: @QueryMapping
public Window<Application> applications(ScrollSubrange subrange, Sort sort) {
int count = subrange.count().orElse(20);
KeysetScrollPosition defaultPosition =
subrange.forward() ? ScrollPosition.keyset() : ScrollPosition.keyset().backward();
ScrollPosition position = subrange.position().orElse(defaultPosition);
return applicationRepository.findAllBy(Limit.of(count), position, sort);
} I have a custom implementation with support to use connections with dataloaders, what I'm trying to do is use keyset scrolling support in spring graphql for non nested connections. If for example the database has 20 records these cases should work:
Here is what I do to get a right value:
Maybe you have a better solution for |
Basically, what Rossen suggested. We should consider the scroll direction when providing has previous/has next pagination details. From forward-scrolling, you cannot know, whether there is a previous page and likewise, from backwards scrolling, you cannot know whether there is a next page because we do not have information on whether there is data before the position you've started from. For offset-based queries, we could indeed optimize and check whether the offset is zero, but that would handle only a very specific case while adding some complexity. |
I've created #843 to fix the behavior of hasNext/hasPrevious with keyset scrolling. After the change hasPrevious will always return false with forward-scroll, and likewise hasNext will always return false with backward-scroll. This is spec compliant and about as much as we can do. |
Hi, I have a problem where
hasPreviousPage
returnstrue
in the following query:The specification says:
I thought the problem was on this line:
spring-graphql/spring-graphql/src/main/java/org/springframework/graphql/data/query/WindowConnectionAdapter.java
Line 56 in 2a99c1f
and I reported the problem in spring data but the team closed my issue with an answer:
The text was updated successfully, but these errors were encountered: