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.

add diagnostic for missing operationName

+18 -1
+18 -1
src/index.ts
··· 75 75 const lines = text.split('\n') 76 76 77 77 let startingPosition = node.pos + (tagTemplate.length + 1) 78 - return getDiagnostics(text, schema.current).map(x => { 78 + const graphQLDiagnostics = getDiagnostics(text, schema.current).map(x => { 79 79 const { start, end } = x.range; 80 80 81 81 // We add the start.line to account for newline characters which are ··· 95 95 // We add 1 to the start because the range is exclusive of start.character 96 96 return { ...x, start: startChar + 1, length: endChar - startChar } 97 97 }) 98 + 99 + const parsed = parse(text); 100 + 101 + if (parsed.definitions.some(x => x.kind === Kind.OPERATION_DEFINITION)) { 102 + const op = parsed.definitions.find(x => x.kind === Kind.OPERATION_DEFINITION) as OperationDefinitionNode 103 + if (!op.name) { 104 + graphQLDiagnostics.push({ 105 + message: 'Operation needs a name for types to be generated.', 106 + start: node.pos, 107 + length: x.getText().length, 108 + range: {} as any, 109 + severity: 2, 110 + } as any) 111 + } 112 + } 113 + 114 + return graphQLDiagnostics; 98 115 }).flat().filter(Boolean) as Array<Diagnostic & { length: number; start: number }> 99 116 100 117 const newDiagnostics = diagnostics.map(diag => {