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

Fix invalid doc warns (#119)

* Fix invalid documents during fragment aggregation step

* changeset

Changed files
+23 -23
.changeset
.vscode
packages
example
graphqlsp
+5
.changeset/wicked-ties-lie.md
···
+
---
+
'@0no-co/graphqlsp': patch
+
---
+
+
Fix crash during fragment aggregation step
+3 -2
.vscode/settings.json
···
{
-
"typescript.tsdk": "node_modules/typescript/lib"
-
}
+
"typescript.tsdk": "node_modules/typescript/lib",
+
"typescript.enablePromptUseWorkspaceTsdk": true
+
}
+2 -10
packages/example/src/index.generated.ts
···
id: string;
name: string;
fleeRate?: number | null;
+
classification?: string | null;
weaknesses?: Array<Types.PokemonType | null> | null;
attacks?: {
__typename: 'AttacksConnection';
···
export type PoQueryVariables = Types.Exact<{
id: Types.Scalars['ID']['input'];
}>;
-
-
export type PoQuery = {
-
__typename: 'Query';
-
pokemon?: {
-
__typename: 'Pokemon';
-
id: string;
-
fleeRate?: number | null;
-
} | null;
-
};
export const PokemonFieldsFragmentDoc = {
kind: 'Document',
···
},
},
],
-
} as unknown as DocumentNode<PoQuery, PoQueryVariables>;
+
} as unknown as DocumentNode<PokQuery, PoQueryVariables>;
+13 -11
packages/graphqlsp/src/diagnostics.ts
···
let docFragments = [...fragments];
if (isCallExpression) {
-
const documentFragments = parse(text, {
-
noLocation: true,
-
}).definitions.filter(x => x.kind === Kind.FRAGMENT_DEFINITION);
-
docFragments = docFragments.filter(
-
x =>
-
!documentFragments.some(
-
y =>
-
y.kind === Kind.FRAGMENT_DEFINITION &&
-
y.name.value === x.name.value
-
)
-
);
+
try {
+
const documentFragments = parse(text, {
+
noLocation: true,
+
}).definitions.filter(x => x.kind === Kind.FRAGMENT_DEFINITION);
+
docFragments = docFragments.filter(
+
x =>
+
!documentFragments.some(
+
y =>
+
y.kind === Kind.FRAGMENT_DEFINITION &&
+
y.name.value === x.name.value
+
)
+
);
+
} catch (e) {}
}
const graphQLDiagnostics = getDiagnostics(