Created
April 2, 2021 15:31
-
-
Save Akryum/58ca58a059123a0bccd13899c03b0ce3 to your computer and use it in GitHub Desktop.
Dedupe Apollo Client 3 references in merge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dedupeReferences (existing, incoming) { | |
// Dedupe items | |
const idMap = {} | |
for (const item of existing) { | |
idMap[item.__ref] = true | |
} | |
const validated = [] | |
for (const item of incoming) { | |
if (!idMap[item.__ref]) { | |
validated.push(item) | |
} | |
} | |
return [...existing, ...validated] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment