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

fix: Strip the unmask directive (#354)

Changed files
+44 -1
.changeset
packages
graphqlsp
+5
.changeset/fluffy-rabbits-shake.md
···
+
---
+
'@0no-co/graphqlsp': patch
+
---
+
+
Strip our internal `@_unmask` directive from fragment-definitions when creating hashes for persisted-operations
+39 -1
packages/graphqlsp/src/persisted.ts
···
import { resolveTemplate } from './ast/resolve';
import {
FragmentDefinitionNode,
+
Kind,
parse,
print,
visit,
···
foundFilename,
info
).combinedText;
+
const parsed = parse(text);
+
const seen = new Set<unknown>();
+
for (const definition of parsed.definitions) {
+
if (
+
definition.kind === Kind.FRAGMENT_DEFINITION &&
+
!seen.has(definition)
+
) {
+
stripUnmaskDirectivesFromDefinition(definition);
+
}
+
}
+
const deduplicatedFragments = fragments
-
.map(fragment => print(fragment))
+
.map(fragment => {
+
stripUnmaskDirectivesFromDefinition(fragment);
+
return print(fragment)
+
})
.filter((fragment, index, array) => array.indexOf(fragment) === index);
deduplicatedFragments.forEach(fragmentDefinition => {
···
).combinedText;
const parsed = parse(text);
+
const seen = new Set<unknown>();
+
for (const definition of parsed.definitions) {
+
if (
+
definition.kind === Kind.FRAGMENT_DEFINITION &&
+
!seen.has(definition)
+
) {
+
stripUnmaskDirectivesFromDefinition(definition);
+
}
+
}
+
const spreads = new Set<string>();
visit(parsed, {
FragmentSpread: node => {
···
);
return;
}
+
+
stripUnmaskDirectivesFromDefinition(fragmentDefinition);
visit(fragmentDefinition, {
FragmentSpread: node => {
···
return { node: documentNodeArgument, filename };
}
};
+
+
type writable<T> = { -readonly [K in keyof T]: T[K] };
+
+
const stripUnmaskDirectivesFromDefinition = (
+
definition: FragmentDefinitionNode
+
) => {
+
(definition as writable<FragmentDefinitionNode>).directives =
+
definition.directives?.filter(
+
directive => directive.name.value !== '_unmask'
+
);
+
};