Skip to content
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
22 changes: 22 additions & 0 deletions src/validation/__tests__/VariablesInAllowedPositionRule-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,28 @@ describe('Validate: Variables are in allowed positions', () => {
});

describe('Fragment arguments are validated', () => {
it('validates fragment variables defined before the operation', () => {
expectErrors(`
fragment A($intVar: Int) on ComplicatedArgs {
nonNullIntArgField(nonNullIntArg: $intVar)
}
query Query($intVar: Int!) {
complicatedArgs {
...A(i: $intVar)
}
}
`).toDeepEqual([
{
message:
'Variable "$intVar" of type "Int" used in position expecting type "Int!".',
locations: [
{ line: 2, column: 20 },
{ line: 3, column: 45 },
],
},
]);
});

it('Boolean => Boolean', () => {
expectValid(`
query Query($booleanArg: Boolean)
Expand Down
10 changes: 6 additions & 4 deletions src/validation/rules/VariablesInAllowedPositionRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ export function VariablesInAllowedPositionRule(

return {
OperationDefinition: {
enter() {
enter(operation) {
varDefMap = new Map();
if (operation.variableDefinitions) {
for (const varDef of operation.variableDefinitions) {
varDefMap.set(varDef.variable.name.value, varDef);
}
}
},
leave(operation) {
const usages = context.getRecursiveVariableUsages(operation);
Expand Down Expand Up @@ -125,9 +130,6 @@ export function VariablesInAllowedPositionRule(
}
},
},
VariableDefinition(node) {
varDefMap.set(node.variable.name.value, node);
},
};
}

Expand Down
Loading