Skip to content

Commit

Permalink
Fix hasPreviousPage in resolveCursorConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
hayes committed Aug 11, 2023
1 parent cd9ffb5 commit b7954d4
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-rules-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@pothos/plugin-relay': patch
---

Fix hasPreviousPage in resolveCursorConnection
4 changes: 2 additions & 2 deletions packages/plugin-relay/src/utils/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ function parseCurserArgs(options: ResolveOffsetConnectionOptions) {
limit,
expectedSize: limit - 1,
inverted,
hasPreviousPage: (resultSize: number) => !!after || (resultSize >= limit && !first),
hasNextPage: (resultSize: number) => !!before || (!last && resultSize >= limit),
hasPreviousPage: (resultSize: number) => (inverted ? resultSize >= limit : !!after),
hasNextPage: (resultSize: number) => (inverted ? !!before : resultSize >= limit),
};
}

Expand Down
35 changes: 35 additions & 0 deletions packages/plugin-relay/tests/__snapshots__/cursors.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,41 @@ exports[`cursor based connection > queries 1`] = `
"startCursor": "38",
},
},
"noArgs": {
"edges": [
{
"node": {
"id": "1",
},
},
{
"node": {
"id": "2",
},
},
{
"node": {
"id": "3",
},
},
{
"node": {
"id": "4",
},
},
{
"node": {
"id": "5",
},
},
],
"pageInfo": {
"endCursor": "5",
"hasNextPage": true,
"hasPreviousPage": false,
"startCursor": "1",
},
},
},
}
`;
13 changes: 13 additions & 0 deletions packages/plugin-relay/tests/cursors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ describe('cursor based connection', () => {
it('queries', async () => {
const query = gql`
query {
noArgs: cursorConnection {
pageInfo {
startCursor
endCursor
hasNextPage
hasPreviousPage
}
edges {
node {
id
}
}
}
after: cursorConnection(after: 98) {
pageInfo {
startCursor
Expand Down

1 comment on commit b7954d4

@vercel
Copy link

@vercel vercel bot commented on b7954d4 Aug 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.