1 | import CodeMirror from 'codemirror';
|
2 | import { getDiagnostics } from 'graphql-language-service';
|
3 | const SEVERITY = ['error', 'warning', 'information', 'hint'];
|
4 | const TYPE = {
|
5 | 'GraphQL: Validation': 'validation',
|
6 | 'GraphQL: Deprecation': 'deprecation',
|
7 | 'GraphQL: Syntax': 'syntax',
|
8 | };
|
9 | CodeMirror.registerHelper('lint', 'graphql', (text, options) => {
|
10 | const schema = options.schema;
|
11 | const rawResults = getDiagnostics(text, schema, options.validationRules, undefined, options.externalFragments);
|
12 | const results = rawResults.map(error => ({
|
13 | message: error.message,
|
14 | severity: error.severity ? SEVERITY[error.severity - 1] : SEVERITY[0],
|
15 | type: error.source ? TYPE[error.source] : undefined,
|
16 | from: CodeMirror.Pos(error.range.start.line, error.range.start.character),
|
17 | to: CodeMirror.Pos(error.range.end.line, error.range.end.character),
|
18 | }));
|
19 | return results;
|
20 | });
|
21 |
|
\ | No newline at end of file |