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

Add special case for first+last during inwards merge #102

Merged
merged 1 commit into from
Sep 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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