graphql / graphql/graphql-relay-js
connectionFromArray incorrectly calculates hasPreviousPage when paginating with first/after
- Dominant language
- TypeScript
- Stars
- 1.5k
- Forks
- 177
- Avg merge
- 10m
- Merged PRs (30d)
- 1
Description
## Summary
Using forward pagination (first/after) with `connectionFromArray` results in incorrect `pageInfo`.
## Description
From the relay [spec](https://relay.dev/graphql/connections.htm#HasPreviousPage()) `hasPreviousPage` states:
> If the client is paginating with first/after, then the client may return true if edges prior to after exist, if it can do so efficiently, otherwise may return false
However, `hasPreviousPage` is always [false](https://github.com/graphql/graphql-relay-js/blob/master/src/connection/arrayconnection.js#L99) when using `first`/`after`:
```javascript
return {
edges,
pageInfo: {
startCursor: firstEdge ? firstEdge.cursor : null,
endCursor: lastEdge ? lastEdge.cursor : null,
hasPreviousPage:
typeof last === 'number' ? startOffset > lowerBound : false,
hasNextPage: typeof first === 'number' ? endOffset < upperBound : false,
},
};
```
The [tests](https://github.com/graphql/graphql-relay-js/blob/master/src/connection/__tests__/arrayconnection.js#L162-L186) also seem to be incorrect as well.
## Expectation
`hasPreviousPage` should be `true` when forward pagination arguments are used. There is enough information to calculate if edges prior to after exist.
Contributor guide
Assessment
This issue has not been assessed yet.