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

add diagnostic for missing operationName

Changed files
+18 -1
src
+18 -1
src/index.ts
···
const lines = text.split('\n')
let startingPosition = node.pos + (tagTemplate.length + 1)
-
return getDiagnostics(text, schema.current).map(x => {
+
const graphQLDiagnostics = getDiagnostics(text, schema.current).map(x => {
const { start, end } = x.range;
// We add the start.line to account for newline characters which are
···
// We add 1 to the start because the range is exclusive of start.character
return { ...x, start: startChar + 1, length: endChar - startChar }
})
+
+
const parsed = parse(text);
+
+
if (parsed.definitions.some(x => x.kind === Kind.OPERATION_DEFINITION)) {
+
const op = parsed.definitions.find(x => x.kind === Kind.OPERATION_DEFINITION) as OperationDefinitionNode
+
if (!op.name) {
+
graphQLDiagnostics.push({
+
message: 'Operation needs a name for types to be generated.',
+
start: node.pos,
+
length: x.getText().length,
+
range: {} as any,
+
severity: 2,
+
} as any)
+
}
+
}
+
+
return graphQLDiagnostics;
}).flat().filter(Boolean) as Array<Diagnostic & { length: number; start: number }>
const newDiagnostics = diagnostics.map(diag => {