@@ -4,7 +4,9 @@ import { expect } from 'chai';
44import { describe , it } from 'mocha' ;
55
66import inspect from '../../jsutils/inspect' ;
7+ import invariant from '../../jsutils/invariant' ;
78
9+ import { Kind } from '../../language/kinds' ;
810import { parse } from '../../language/parser' ;
911
1012import { GraphQLSchema } from '../../type/schema' ;
@@ -19,6 +21,7 @@ import {
1921} from '../../type/definition' ;
2022
2123import { execute } from '../execute' ;
24+ import { getVariableValues } from '../values' ;
2225
2326const TestComplexScalar = new GraphQLScalarType ( {
2427 name : 'ComplexScalar' ,
@@ -369,7 +372,7 @@ describe('Execute: Handles inputs', () => {
369372 errors : [
370373 {
371374 message :
372- 'Variable "$input" got invalid value { a: "foo", b: "bar", c: null } ; Expected non-nullable type String! not to be null at value.c .' ,
375+ 'Variable "$input" got invalid value null at "input.c" ; Expected non-nullable type String! not to be null.' ,
373376 locations : [ { line : 2 , column : 16 } ] ,
374377 } ,
375378 ] ,
@@ -397,7 +400,7 @@ describe('Execute: Handles inputs', () => {
397400 errors : [
398401 {
399402 message :
400- 'Variable "$input" got invalid value { a: "foo", b: "bar" }; Field of required type String! was not provided at value.c .' ,
403+ 'Variable "$input" got invalid value { a: "foo", b: "bar" }; Field c of required type String! was not provided.' ,
401404 locations : [ { line : 2 , column : 16 } ] ,
402405 } ,
403406 ] ,
@@ -416,12 +419,12 @@ describe('Execute: Handles inputs', () => {
416419 errors : [
417420 {
418421 message :
419- 'Variable "$input" got invalid value { na: { a: "foo" } } ; Field of required type String! was not provided at value.na.c .' ,
422+ 'Variable "$input" got invalid value { a: "foo" } at "input.na" ; Field c of required type String! was not provided.' ,
420423 locations : [ { line : 2 , column : 18 } ] ,
421424 } ,
422425 {
423426 message :
424- 'Variable "$input" got invalid value { na: { a: "foo" } }; Field of required type String! was not provided at value.nb .' ,
427+ 'Variable "$input" got invalid value { na: { a: "foo" } }; Field nb of required type String! was not provided.' ,
425428 locations : [ { line : 2 , column : 18 } ] ,
426429 } ,
427430 ] ,
@@ -830,7 +833,7 @@ describe('Execute: Handles inputs', () => {
830833 errors : [
831834 {
832835 message :
833- 'Variable "$input" got invalid value ["A", null, "B"] ; Expected non-nullable type String! not to be null at value[1] .' ,
836+ 'Variable "$input" got invalid value null at "input[1]" ; Expected non-nullable type String! not to be null.' ,
834837 locations : [ { line : 2 , column : 16 } ] ,
835838 } ,
836839 ] ,
@@ -879,7 +882,7 @@ describe('Execute: Handles inputs', () => {
879882 errors : [
880883 {
881884 message :
882- 'Variable "$input" got invalid value ["A", null, "B"] ; Expected non-nullable type String! not to be null at value[1] .' ,
885+ 'Variable "$input" got invalid value null at "input[1]" ; Expected non-nullable type String! not to be null.' ,
883886 locations : [ { line : 2 , column : 16 } ] ,
884887 } ,
885888 ] ,
@@ -986,4 +989,42 @@ describe('Execute: Handles inputs', () => {
986989 } ) ;
987990 } ) ;
988991 } ) ;
992+
993+ 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 ) ;
1002+
1003+ const result = getVariableValues (
1004+ schema ,
1005+ operation . variableDefinitions || [ ] ,
1006+ { input : [ 0 , 1 , 2 ] } ,
1007+ { maxErrors : 2 } ,
1008+ ) ;
1009+
1010+ expect ( result ) . to . deep . equal ( {
1011+ 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+ } ,
1022+ {
1023+ message :
1024+ 'Too many errors processing variables, error limit reached. Execution aborted.' ,
1025+ } ,
1026+ ] ,
1027+ } ) ;
1028+ } ) ;
1029+ } ) ;
9891030} ) ;
0 commit comments