Skip to content

Commit

Permalink
Fix relayStylePaginationWithNodes losing the first page of data
Browse files Browse the repository at this point in the history
  • Loading branch information
canac committed Jan 16, 2025
1 parent b3d4928 commit 143406b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib/apollo/relayStylePaginationWithNodes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ export function relayStylePaginationWithNodes<TNode = Reference>(
incoming,
{ args, isReference, readField },
) {
// `merge` can be called multiple times with the same incoming data as Apollo recursively
// merges data at various levels in the tree. If the incoming data is the same as the existing
// data, simply ignore it.
if (
incoming.pageInfo?.endCursor &&
incoming.pageInfo?.endCursor === existing.pageInfo.endCursor
) {
return existing;
}

Check warning on line 89 in src/lib/apollo/relayStylePaginationWithNodes.tsx

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (remove-limit-from-fetching-coaches)

❌ Getting worse: Complex Method

relayStylePaginationWithNodes.merge increases in cyclomatic complexity from 31 to 35, threshold = 10. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
const incomingEdges = incoming.edges
? incoming.edges.map((edge) => {
if (isReference((edge = { ...edge }))) {
Expand Down

0 comments on commit 143406b

Please sign in to comment.