Skip to content

Instantly share code, notes, and snippets.

@broguinn
Created December 19, 2025 14:38
Show Gist options
  • Select an option

  • Save broguinn/bd6f45199b1fe6651359130bb6397d2a to your computer and use it in GitHub Desktop.

Select an option

Save broguinn/bd6f45199b1fe6651359130bb6397d2a to your computer and use it in GitHub Desktop.
diff --git a/packages/shared/src/utils/apollo.ts b/packages/shared/src/utils/apollo.ts
index 3f3ab69c..d6301226 100644
--- a/packages/shared/src/utils/apollo.ts
+++ b/packages/shared/src/utils/apollo.ts
@@ -1,8 +1,15 @@
export function buildGenericConnectionMerge() {
return {
- keyArgs: () => ['filters'],
- merge(existing: any, incoming: any, { readField }: any) {
- const edges = existing ? { ...existing.edges } : {};
+ keyArgs: ['filters'],
+ merge(existing: any, incoming: any, { args, readField }: any) {
+ // If no cursor (first page/fresh query), replace existing data
+ // If cursor exists (pagination), merge with existing
+ const isFirstPage = !args?.cursor;
+ let edges = {};
+ if (!isFirstPage && existing) {
+ edges = { ...existing.edges };
+ }
+
incoming.edges.forEach((edge: any) => {
edges[readField('id', edge) as string] = edge;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment