From 84e53e4b570d10e6f57877cb979f29a397063b9b Mon Sep 17 00:00:00 2001 From: Fela Maslen Date: Fri, 5 Jul 2024 11:34:51 +0100 Subject: [PATCH] fix: deduplicate fragments when generating persisted document hash (#342) --- .changeset/stale-plums-prove.md | 5 +++++ packages/graphqlsp/src/persisted.ts | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 .changeset/stale-plums-prove.md diff --git a/.changeset/stale-plums-prove.md b/.changeset/stale-plums-prove.md new file mode 100644 index 00000000..c4a94f1f --- /dev/null +++ b/.changeset/stale-plums-prove.md @@ -0,0 +1,5 @@ +--- +'@0no-co/graphqlsp': patch +--- + +Fixed duplicate fragments in persisted document hash generator diff --git a/packages/graphqlsp/src/persisted.ts b/packages/graphqlsp/src/persisted.ts index c9ba706f..e2629185 100644 --- a/packages/graphqlsp/src/persisted.ts +++ b/packages/graphqlsp/src/persisted.ts @@ -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);