Skip to content
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

pageInfo.hasPreviousPage always false when forward-paginating #22

Open
aloker opened this issue Jul 9, 2018 · 6 comments
Open

pageInfo.hasPreviousPage always false when forward-paginating #22

aloker opened this issue Jul 9, 2018 · 6 comments
Labels
bug Something isn't working

Comments

@aloker
Copy link
Contributor

aloker commented Jul 9, 2018

When using forward pagination (first+after), pageInfo.hasPreviousPage always returns false.

The logic for calculating hasNextPage/hasPreviousPage is found in

public ArraySliceMetrics(
IList<TSource> slice,
ResolveConnectionContext<TParent> context,
int sliceStartIndex,
int totalCount
) {
_items = slice;
SliceSize = slice.Count;
StartIndex = sliceStartIndex;
var beforeOffset = ConnectionUtils.OffsetOrDefault(context.Before, totalCount);
var afterOffset = ConnectionUtils.OffsetOrDefault(context.After, defaultOffset: -1);
StartOffset = new[] {sliceStartIndex - 1, afterOffset, -1}.Max() + 1;
EndOffset = new[] {EndIndex - 1, beforeOffset, totalCount}.Max();
if (context.First.HasValue)
EndOffset = Math.Min(EndOffset, StartOffset + context.First.Value);
if (context.Last.HasValue)
StartOffset = Math.Min(StartOffset, EndOffset - context.Last.Value);
var lowerBound = context.After != null ? afterOffset + 1 : 0;
var upperBound = context.Before != null ? beforeOffset : totalCount;
HasPrevious = context.Last.HasValue && StartOffset > lowerBound;
HasNext = context.First.HasValue && EndOffset < upperBound;
}

Is this behavior intentional? Consider this query:

query {
  something(first:10 after:'SOMECURSOR') {
    pageInfo {
      startCursor
      hasPreviousPage      
    }
  }
} 

I would expect hasPreviousPage to be true IFF something(last:X before:startCursor) returns any results. However, it's always false.

The same goes for hasNextPage during backwards pagination, of course.

@jquense
Copy link
Collaborator

jquense commented Jul 9, 2018

That does look like a bug! Care to investigate a bit closer and send a PR?

@aloker
Copy link
Contributor Author

aloker commented Jul 9, 2018

Sure, I'll have a look at it this evening

@aloker
Copy link
Contributor Author

aloker commented Jul 15, 2018

It has taken a bit longer, but hopefully the result is worth the wait.

jquense added a commit that referenced this issue Jul 18, 2018
@eddyjl077
Copy link

Hi,

In the version 0.5.0 the bug is still there, has this been fixed in the 0.6.0?

image

image

@CyrilleFormont
Copy link

Up

@sungam3r sungam3r added the bug Something isn't working label Oct 3, 2019
@nbarbettini
Copy link

The official package GraphQL.Relay hasn't been published since #24 was merged, so it looks to me like it's been fixed but not released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants