Skip to content

Commit

Permalink
fix: deduplicate fragments when generating persisted document hash (#342
Browse files Browse the repository at this point in the history
)
  • Loading branch information
felamaslen authored Jul 5, 2024
1 parent 83ca7f6 commit 84e53e4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-plums-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@0no-co/graphqlsp': patch
---

Fixed duplicate fragments in persisted document hash generator
13 changes: 8 additions & 5 deletions packages/graphqlsp/src/persisted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,15 @@ export const generateHashForDocument = (
foundFilename,
info
).combinedText;
fragments.forEach(fragmentDefinition => {
text = `${text}\n\n${print(fragmentDefinition)}`;
const deduplicatedFragments = fragments
.map(fragment => print(fragment))
.filter((fragment, index, array) => array.indexOf(fragment) === index);

deduplicatedFragments.forEach(fragmentDefinition => {
text = `${text}\n\n${fragmentDefinition}`;
});
return createHash('sha256')
.update(print(parse(text)))
.digest('hex');
const fullText = print(parse(text));
return createHash('sha256').update(fullText).digest('hex');
} else {
const externalSource = getSource(info, foundFilename)!;
const { fragments } = findAllCallExpressions(externalSource, info);
Expand Down

0 comments on commit 84e53e4

Please sign in to comment.