Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
? node.name
: 'variable' in node
? node.variable
: node;
invariant(error.locations, 'GraphQL validation error requires locations.');
// @ts-ignore
// https://github.com/microsoft/TypeScript/pull/32695
const loc = error.locations[0];
const highlightLoc = getLocation(highlightNode);
const end = loc.column + (highlightLoc.end - highlightLoc.start);
return {
source: `GraphQL: ${type}`,
message: error.message,
severity,
range: new Range(
new Position(loc.line - 1, loc.column - 1),
new Position(loc.line - 1, end),
),
};
});
}
const style = parser.token(stream, state);
if (style === 'invalidchar') {
break;
}
}
}
invariant(stream, 'Expected Parser stream to be available.');
const line = location.line - 1;
// @ts-ignore
// https://github.com/microsoft/TypeScript/pull/32695
const start = stream.getStartOfToken();
// @ts-ignore
// https://github.com/microsoft/TypeScript/pull/32695
const end = stream.getCurrentPosition();
return new Range(new Position(line, start), new Position(line, end));
}
if (
text.indexOf('graphql`') === -1 &&
text.indexOf('graphql.experimental`') === -1 &&
text.indexOf('gql`') === -1
) {
return [];
}
const templates = findGraphQLTags(text);
return templates.map(({ template, range }) => ({ query: template, range }));
} else {
const query = text;
if (!query && query !== '') {
return [];
}
const lines = query.split('\n');
const range = new Range(
new Position(0, 0),
new Position(lines.length - 1, lines[lines.length - 1].length - 1)
);
return [{ query, range }];
}
}
if (style === 'invalidchar') {
break;
}
}
}
invariant(
stream,
'Expected Parser stream to be available.',
);
const line = location.line - 1;
const start = stream.getStartOfToken();
const end = stream.getCurrentPosition();
return new Range(new Position(line, start), new Position(line, end));
}
return error.nodes.map(node => {
const highlightNode: ASTNode =
node.kind !== 'Variable' && node.name ? node.name :
node.variable ? node.variable :
node;
invariant(error.locations, 'GraphQL validation error requires locations.');
const loc = error.locations[0];
const end = loc.column + (highlightNode.loc.end - highlightNode.loc.start);
return {
source: 'GraphQL: Validation',
message: error.message,
severity: SEVERITY.ERROR,
range: new Range(
new Position(loc.line - 1, loc.column - 1),
new Position(loc.line - 1, end),
),
};
});
}