Skip to content

Instantly share code, notes, and snippets.

@Akryum
Created April 2, 2021 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akryum/58ca58a059123a0bccd13899c03b0ce3 to your computer and use it in GitHub Desktop.
Save Akryum/58ca58a059123a0bccd13899c03b0ce3 to your computer and use it in GitHub Desktop.
Dedupe Apollo Client 3 references in merge
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