diff --git a/src/extras/relayPagination.ts b/src/extras/relayPagination.ts index 032dc2a..53a3b61 100644 --- a/src/extras/relayPagination.ts +++ b/src/extras/relayPagination.ts @@ -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;