Skip to content

Commit ebcdfd2

Browse files
getVariableValues: improve coverage of 'maxErrors' (#2078)
1 parent d4ccf67 commit ebcdfd2

File tree

1 file changed

+41
-20
lines changed

1 file changed

+41
-20
lines changed

src/execution/__tests__/variables-test.js

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -991,34 +991,55 @@ describe('Execute: Handles inputs', () => {
991991
});
992992

993993
describe('getVariableValues: limit maximum number of coercion errors', () => {
994-
it('when values are invalid', () => {
995-
const doc = parse(`
996-
query ($input: [String!]) {
997-
listNN(input: $input)
998-
}
999-
`);
1000-
const operation = doc.definitions[0];
1001-
invariant(operation.kind === Kind.OPERATION_DEFINITION);
994+
const doc = parse(`
995+
query ($input: [String!]) {
996+
listNN(input: $input)
997+
}
998+
`);
999+
1000+
const operation = doc.definitions[0];
1001+
invariant(operation.kind === Kind.OPERATION_DEFINITION);
1002+
const { variableDefinitions } = operation;
1003+
invariant(variableDefinitions != null);
1004+
1005+
const inputValue = { input: [0, 1, 2] };
10021006

1007+
function invalidValueError(value, index) {
1008+
return {
1009+
message: `Variable "$input" got invalid value ${value} at "input[${index}]"; Expected type String. String cannot represent a non string value: ${value}`,
1010+
locations: [{ line: 2, column: 14 }],
1011+
};
1012+
}
1013+
1014+
it('when maxErrors is equal to number of errors', () => {
10031015
const result = getVariableValues(
10041016
schema,
1005-
operation.variableDefinitions || [],
1006-
{ input: [0, 1, 2] },
1017+
variableDefinitions,
1018+
inputValue,
1019+
{ maxErrors: 3 },
1020+
);
1021+
1022+
expect(result).to.deep.equal({
1023+
errors: [
1024+
invalidValueError(0, 0),
1025+
invalidValueError(1, 1),
1026+
invalidValueError(2, 2),
1027+
],
1028+
});
1029+
});
1030+
1031+
it('when maxErrors is less than number of errors', () => {
1032+
const result = getVariableValues(
1033+
schema,
1034+
variableDefinitions,
1035+
inputValue,
10071036
{ maxErrors: 2 },
10081037
);
10091038

10101039
expect(result).to.deep.equal({
10111040
errors: [
1012-
{
1013-
message:
1014-
'Variable "$input" got invalid value 0 at "input[0]"; Expected type String. String cannot represent a non string value: 0',
1015-
locations: [{ line: 2, column: 16 }],
1016-
},
1017-
{
1018-
message:
1019-
'Variable "$input" got invalid value 1 at "input[1]"; Expected type String. String cannot represent a non string value: 1',
1020-
locations: [{ line: 2, column: 16 }],
1021-
},
1041+
invalidValueError(0, 0),
1042+
invalidValueError(1, 1),
10221043
{
10231044
message:
10241045
'Too many errors processing variables, error limit reached. Execution aborted.',

0 commit comments

Comments
 (0)