Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reproduction of a bug in validation of undefined variables #2913

Merged
merged 2 commits into from
Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,39 @@ describe('getDiagnostics', () => {
expect(error.source).toEqual('GraphQL: Validation');
});

it('catches with multiple highlighted nodes', () => {
const errors = validateQuery(
parse('{ hero(episode: $ep) { name } }'),
schema,
);
expect(errors).toMatchObject([
{
range: {
end: {
character: 20,
line: 0,
},
start: {
character: 16,
line: 0,
},
},
},
{
range: {
end: {
character: 32,
line: 0,
},
start: {
character: 0,
line: 0,
},
},
},
]);
});

it('catches multi root validation errors without breaking (with a custom validation function that always throws errors)', () => {
const error = validateQuery(parse('{ hero { name } } { seq }'), schema, [
validationContext => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function annotations(
return [];
}
const highlightedNodes: Diagnostic[] = [];
error.nodes.forEach(node => {
error.nodes.forEach((node, i) => {
const highlightNode =
node.kind !== 'Variable' && 'name' in node && node.name !== undefined
? node.name
Expand All @@ -154,7 +154,7 @@ function annotations(

// @ts-ignore
// https://github.com/microsoft/TypeScript/pull/32695
const loc = error.locations[0];
const loc = error.locations[i];
const highlightLoc = getLocation(highlightNode);
const end = loc.column + (highlightLoc.end - highlightLoc.start);
highlightedNodes.push({
Expand Down