Skip to content
This repository has been archived by the owner on Jul 6, 2020. It is now read-only.

Commit

Permalink
Add special case for first+last during inwards merge (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten authored and JoviDeCroock committed Sep 30, 2019
1 parent ef6783b commit 9ffb9b6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/extras/relayPagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,27 @@ export const relayPagination = (params: PaginationParams = {}): Resolver => {
const page = getPage(cache, linkKey);
if (page === null) {
continue;
} else if (
mergeMode === 'inwards' &&
typeof args.last === 'number' &&
typeof args.first === 'number'
) {
// This is a special but rare case for simultaneously merging first and last edges
if (page.edges.length < args.first + args.last) {
startEdges = concatEdges(cache, startEdges, page.edges);
pageInfo.hasNextPage = false;
pageInfo.hasPreviousPage = false;
pageInfo.startCursor = null;
pageInfo.endCursor = null;
break;
} else {
const firstEdges = page.edges.slice(0, args.first);
const lastEdges = page.edges.slice(-args.last);
startEdges = concatEdges(cache, startEdges, firstEdges);
endEdges = concatEdges(cache, lastEdges, endEdges);
}

pageInfo = page.pageInfo;
} else if (args.after) {
startEdges = concatEdges(cache, startEdges, page.edges);
pageInfo.endCursor = page.pageInfo.endCursor;
Expand Down

0 comments on commit 9ffb9b6

Please sign in to comment.