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

Configure Feed

Select the types of activity you want to include in your feed.

Fix invalid doc warns (#119)

* Fix invalid documents during fragment aggregation step

* changeset

authored by

Jovi De Croock and committed by
GitHub
0041ac99 55b09ff4

+23 -23
+5
.changeset/wicked-ties-lie.md
··· 1 + --- 2 + '@0no-co/graphqlsp': patch 3 + --- 4 + 5 + Fix crash during fragment aggregation step
+3 -2
.vscode/settings.json
··· 1 1 { 2 - "typescript.tsdk": "node_modules/typescript/lib" 3 - } 2 + "typescript.tsdk": "node_modules/typescript/lib", 3 + "typescript.enablePromptUseWorkspaceTsdk": true 4 + }
+2 -10
packages/example/src/index.generated.ts
··· 11 11 id: string; 12 12 name: string; 13 13 fleeRate?: number | null; 14 + classification?: string | null; 14 15 weaknesses?: Array<Types.PokemonType | null> | null; 15 16 attacks?: { 16 17 __typename: 'AttacksConnection'; ··· 45 46 export type PoQueryVariables = Types.Exact<{ 46 47 id: Types.Scalars['ID']['input']; 47 48 }>; 48 - 49 - export type PoQuery = { 50 - __typename: 'Query'; 51 - pokemon?: { 52 - __typename: 'Pokemon'; 53 - id: string; 54 - fleeRate?: number | null; 55 - } | null; 56 - }; 57 49 58 50 export const PokemonFieldsFragmentDoc = { 59 51 kind: 'Document', ··· 274 266 }, 275 267 }, 276 268 ], 277 - } as unknown as DocumentNode<PoQuery, PoQueryVariables>; 269 + } as unknown as DocumentNode<PokQuery, PoQueryVariables>;
+13 -11
packages/graphqlsp/src/diagnostics.ts
··· 152 152 153 153 let docFragments = [...fragments]; 154 154 if (isCallExpression) { 155 - const documentFragments = parse(text, { 156 - noLocation: true, 157 - }).definitions.filter(x => x.kind === Kind.FRAGMENT_DEFINITION); 158 - docFragments = docFragments.filter( 159 - x => 160 - !documentFragments.some( 161 - y => 162 - y.kind === Kind.FRAGMENT_DEFINITION && 163 - y.name.value === x.name.value 164 - ) 165 - ); 155 + try { 156 + const documentFragments = parse(text, { 157 + noLocation: true, 158 + }).definitions.filter(x => x.kind === Kind.FRAGMENT_DEFINITION); 159 + docFragments = docFragments.filter( 160 + x => 161 + !documentFragments.some( 162 + y => 163 + y.kind === Kind.FRAGMENT_DEFINITION && 164 + y.name.value === x.name.value 165 + ) 166 + ); 167 + } catch (e) {} 166 168 } 167 169 168 170 const graphQLDiagnostics = getDiagnostics(