@@ -254,21 +254,28 @@ describe('QueryComplexity analysis', () => {
254254 expect ( visitor . complexity ) . to . equal ( 0 ) ;
255255 } ) ;
256256
257- it ( 'should ignore unused variables' , ( ) => {
257+ it ( 'should report errors for unused variables' , ( ) => {
258258 const ast = parse ( `
259259 query ($unusedVar: ID!) {
260260 variableScalar(count: 100)
261261 }
262262 ` ) ;
263263
264- const context = new CompatibleValidationContext ( schema , ast , typeInfo ) ;
265- const visitor = new ComplexityVisitor ( context , {
266- maximumComplexity : 100 ,
267- estimators : [ simpleEstimator ( { defaultComplexity : 10 } ) ] ,
268- } ) ;
269-
270- visit ( ast , visitWithTypeInfo ( typeInfo , visitor ) ) ;
271- expect ( visitor . complexity ) . to . equal ( 10 ) ;
264+ const errors = validate ( schema , ast , [
265+ createComplexityRule ( {
266+ maximumComplexity : 1000 ,
267+ estimators : [
268+ simpleEstimator ( {
269+ defaultComplexity : 1 ,
270+ } ) ,
271+ ] ,
272+ variables : {
273+ unusedVar : 'someID' ,
274+ } ,
275+ } ) ,
276+ ] ) ;
277+ expect ( errors ) . to . have . length ( 1 ) ;
278+ expect ( errors [ 0 ] . message ) . to . contain ( '$unusedVar' ) ;
272279 } ) ;
273280
274281 it ( 'should ignore unknown field' , ( ) => {
@@ -860,4 +867,28 @@ describe('QueryComplexity analysis', () => {
860867 // query.scalar(5) + query.requiredArgs(5) * requiredArgs.scalar(5)
861868 expect ( complexity ) . to . equal ( 30 ) ;
862869 } ) ;
870+
871+ it ( 'reports variable coercion errors' , ( ) => {
872+ const ast = parse ( `
873+ query ($input: RGB!){
874+ enumInputArg(enum: $input)
875+ }
876+ ` ) ;
877+
878+ const errors = validate ( schema , ast , [
879+ createComplexityRule ( {
880+ maximumComplexity : 1000 ,
881+ estimators : [
882+ simpleEstimator ( {
883+ defaultComplexity : 1 ,
884+ } ) ,
885+ ] ,
886+ variables : {
887+ input : 'INVALIDVALUE' ,
888+ } ,
889+ } ) ,
890+ ] ) ;
891+ expect ( errors ) . to . have . length ( 1 ) ;
892+ expect ( errors [ 0 ] . message ) . to . contain ( 'INVALIDVALUE' ) ;
893+ } ) ;
863894} ) ;
0 commit comments