Skip to content

Commit

Permalink
fix: create start and end cursors even if edges are null
Browse files Browse the repository at this point in the history
  • Loading branch information
hayes committed Jul 29, 2021
1 parent a38003b commit 64b9d2f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 18 deletions.
8 changes: 4 additions & 4 deletions packages/deno/packages/plugin-relay/utils/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export async function resolveOffsetConnection<T>(options: ResolveOffsetConnectio
return {
edges: trimmed,
pageInfo: {
startCursor: trimmed[0]?.cursor ?? null,
endCursor: trimmed[trimmed.length - 1]?.cursor ?? null,
startCursor: offsetToCursor(offset),
endCursor: offsetToCursor(offset + trimmed.length - 1),
hasPreviousPage,
hasNextPage: hasNextPage(nodes.length),
},
Expand Down Expand Up @@ -102,8 +102,8 @@ export function resolveArrayConnection<T>(options: ResolveArrayConnectionOptions
return {
edges: trimmed,
pageInfo: {
startCursor: trimmed[0]?.cursor ?? null,
endCursor: trimmed[trimmed.length - 1]?.cursor ?? null,
startCursor: offsetToCursor(offset),
endCursor: offsetToCursor(offset + trimmed.length - 1),
hasPreviousPage,
hasNextPage: hasNextPage(nodes.length),
},
Expand Down
8 changes: 4 additions & 4 deletions packages/plugin-relay/src/utils/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ export async function resolveOffsetConnection<T>(
return {
edges: trimmed,
pageInfo: {
startCursor: trimmed[0]?.cursor ?? null,
endCursor: trimmed[trimmed.length - 1]?.cursor ?? null,
startCursor: offsetToCursor(offset),
endCursor: offsetToCursor(offset + trimmed.length - 1),
hasPreviousPage,
hasNextPage: hasNextPage(nodes.length),
},
Expand Down Expand Up @@ -138,8 +138,8 @@ export function resolveArrayConnection<T>(
return {
edges: trimmed,
pageInfo: {
startCursor: trimmed[0]?.cursor ?? null,
endCursor: trimmed[trimmed.length - 1]?.cursor ?? null,
startCursor: offsetToCursor(offset),
endCursor: offsetToCursor(offset + trimmed.length - 1),
hasPreviousPage,
hasNextPage: hasNextPage(nodes.length),
},
Expand Down
36 changes: 27 additions & 9 deletions packages/plugin-relay/tests/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,29 @@ Object {
"startCursor": "T2Zmc2V0Q29ubmVjdGlvbjo3",
},
},
"moreOddNumbers": Object {
"edges": Array [
Object {
"cursor": "T2Zmc2V0Q29ubmVjdGlvbjox",
"node": Object {
"number": 1,
},
},
null,
Object {
"cursor": "T2Zmc2V0Q29ubmVjdGlvbjoz",
"node": Object {
"number": 3,
},
},
],
"pageInfo": Object {
"endCursor": "T2Zmc2V0Q29ubmVjdGlvbjoz",
"hasNextPage": true,
"hasPreviousPage": true,
"startCursor": "T2Zmc2V0Q29ubmVjdGlvbjox",
},
},
"numbers": Object {
"edges": Array [
Object {
Expand Down Expand Up @@ -769,25 +792,20 @@ Object {
},
"oddNumbers": Object {
"edges": Array [
null,
Object {
"cursor": "T2Zmc2V0Q29ubmVjdGlvbjox",
"node": Object {
"number": 1,
},
},
null,
Object {
"cursor": "T2Zmc2V0Q29ubmVjdGlvbjoz",
"node": Object {
"number": 3,
},
},
],
"pageInfo": Object {
"endCursor": "T2Zmc2V0Q29ubmVjdGlvbjoz",
"endCursor": "T2Zmc2V0Q29ubmVjdGlvbjoy",
"hasNextPage": true,
"hasPreviousPage": true,
"startCursor": "T2Zmc2V0Q29ubmVjdGlvbjox",
"hasPreviousPage": false,
"startCursor": "T2Zmc2V0Q29ubmVjdGlvbjow",
},
},
"sharedConnection": Object {
Expand Down
16 changes: 15 additions & 1 deletion packages/plugin-relay/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,21 @@ describe('relay example schema', () => {
}
}
}
oddNumbers(first: 3, after: "T2Zmc2V0Q29ubmVjdGlvbjow") {
oddNumbers(first: 3) {
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
edges {
cursor
node {
number
}
}
}
moreOddNumbers: oddNumbers(first: 3, after: "T2Zmc2V0Q29ubmVjdGlvbjow") {
pageInfo {
hasNextPage
hasPreviousPage
Expand Down

0 comments on commit 64b9d2f

Please sign in to comment.