UNPKG

954 BJavaScriptView Raw
1import CodeMirror from 'codemirror';
2import { getDiagnostics } from 'graphql-language-service';
3const SEVERITY = ['error', 'warning', 'information', 'hint'];
4const TYPE = {
5 'GraphQL: Validation': 'validation',
6 'GraphQL: Deprecation': 'deprecation',
7 'GraphQL: Syntax': 'syntax',
8};
9CodeMirror.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//# sourceMappingURL=lint.js.map
\No newline at end of file