_codemirror2.default.registerHelper('lint', 'graphql', function (text, options, editor) {
var schema = options.schema;
if (!schema) {
return [];
}
try {
var ast = (0, _graphql.parse)(text);
var validationErrorAnnotations = mapCat((0, _graphql.validate)(schema, ast), function (error) {
return annotations(editor, error, 'error', 'validation');
});
// Note: findDeprecatedUsages was added in [email protected], but we want to
// support older versions of graphql-js.
var deprecationWarningAnnotations = !_graphql.findDeprecatedUsages ? [] : mapCat((0, _graphql.findDeprecatedUsages)(schema, ast), function (error) {
return annotations(editor, error, 'warning', 'deprecation');
});
return validationErrorAnnotations.concat(deprecationWarningAnnotations);
} catch (error) {
var location = error.locations[0];
var pos = _codemirror2.default.Pos(location.line - 1, location.column);
var token = editor.getTokenAt(pos);
return [{
message: error.message,
severity: 'error',
type: 'syntax',
from: _codemirror2.default.Pos(location.line - 1, token.start),
to: _codemirror2.default.Pos(location.line - 1, token.end)
}];
}
});
function annotations(editor, error, severity, type) {
return error.nodes.map(function (node) {
var highlightNode = node.kind !== 'Variable' && node.name ? node.name : node.variable ? node.variable : node;
return {
message: error.message,
severity: severity,
type: type,
from: editor.posFromIndex(highlightNode.loc.start),
to: editor.posFromIndex(highlightNode.loc.end)
};
});
}
// General utility for map-cating (aka flat-mapping).
function mapCat(array, mapper) {
return Array.prototype.concat.apply([], array.map(mapper));
}
CodeMirror.registerHelper('lint', 'graphql', (text, options) => {
const schema = options.schema;
const rawResults = getDiagnostics(text, schema);
const results = rawResults.map(error => ({
message: error.message,
severity: SEVERITY[error.severity],
type: error.source,
from: error.range.start,
to: error.range.end,
}));
return results;
});
I think may be it is not the latest version on the npm verion, but it's 0.6.3 same with the version on github.But the code is quite different, what happend?