Mirror: TypeScript LSP plugin that finds GraphQL documents in your code and provides diagnostics, auto-complete and hover-information.

fix: deduplicate fragments when generating persisted document hash (#342)

authored by

Fela Maslen and committed by
GitHub
84e53e4b 83ca7f67

+13 -5
+5
.changeset/stale-plums-prove.md
··· 1 + --- 2 + '@0no-co/graphqlsp': patch 3 + --- 4 + 5 + Fixed duplicate fragments in persisted document hash generator
+8 -5
packages/graphqlsp/src/persisted.ts
··· 183 183 foundFilename, 184 184 info 185 185 ).combinedText; 186 - fragments.forEach(fragmentDefinition => { 187 - text = `${text}\n\n${print(fragmentDefinition)}`; 186 + const deduplicatedFragments = fragments 187 + .map(fragment => print(fragment)) 188 + .filter((fragment, index, array) => array.indexOf(fragment) === index); 189 + 190 + deduplicatedFragments.forEach(fragmentDefinition => { 191 + text = `${text}\n\n${fragmentDefinition}`; 188 192 }); 189 - return createHash('sha256') 190 - .update(print(parse(text))) 191 - .digest('hex'); 193 + const fullText = print(parse(text)); 194 + return createHash('sha256').update(fullText).digest('hex'); 192 195 } else { 193 196 const externalSource = getSource(info, foundFilename)!; 194 197 const { fragments } = findAllCallExpressions(externalSource, info);