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