33 */
44
55import {
6+ GraphQLError ,
67 parse ,
78 TypeInfo ,
89 ValidationContext ,
@@ -154,7 +155,7 @@ describe('QueryComplexity analysis', () => {
154155 }
155156 ` ) ;
156157
157- const context = new ValidationContext ( schema , ast , typeInfo ) ;
158+ const context = new ValidationContext ( schema , ast , typeInfo , ( ) => null ) ;
158159 const visitor = new ComplexityVisitor ( context , {
159160 maximumComplexity : 100 ,
160161 estimators : [
@@ -173,7 +174,8 @@ describe('QueryComplexity analysis', () => {
173174 }
174175 ` ) ;
175176
176- const context = new ValidationContext ( schema , ast , typeInfo ) ;
177+ const validationErrors : GraphQLError [ ] = [ ] ;
178+ const context = new ValidationContext ( schema , ast , typeInfo , err => validationErrors . push ( err ) ) ;
177179 const visitor = new ComplexityVisitor ( context , {
178180 maximumComplexity : 100 ,
179181 estimators : [
@@ -186,8 +188,8 @@ describe('QueryComplexity analysis', () => {
186188
187189 visit ( ast , visitWithTypeInfo ( typeInfo , visitor ) ) ;
188190 expect ( visitor . complexity ) . to . equal ( 1000 ) ;
189- expect ( context . getErrors ( ) . length ) . to . equal ( 1 ) ;
190- expect ( context . getErrors ( ) [ 0 ] . message ) . to . equal (
191+ expect ( validationErrors . length ) . to . equal ( 1 ) ;
192+ expect ( validationErrors [ 0 ] . message ) . to . equal (
191193 'The query exceeds the maximum complexity of 100. Actual complexity is 1000'
192194 ) ;
193195 } ) ;
@@ -203,7 +205,7 @@ describe('QueryComplexity analysis', () => {
203205 }
204206 ` ) ;
205207
206- const context = new ValidationContext ( schema , ast , typeInfo ) ;
208+ const context = new ValidationContext ( schema , ast , typeInfo , ( ) => null ) ;
207209 const visitor = new ComplexityVisitor ( context , {
208210 maximumComplexity : 100 ,
209211 estimators : [
@@ -230,7 +232,7 @@ describe('QueryComplexity analysis', () => {
230232 }
231233 ` ) ;
232234
233- const context = new ValidationContext ( schema , ast , typeInfo ) ;
235+ const context = new ValidationContext ( schema , ast , typeInfo , ( ) => null ) ;
234236 const visitor = new ComplexityVisitor ( context , {
235237 maximumComplexity : 100 ,
236238 estimators : [
@@ -257,7 +259,7 @@ describe('QueryComplexity analysis', () => {
257259 }
258260 ` ) ;
259261
260- const context = new ValidationContext ( schema , ast , typeInfo ) ;
262+ const context = new ValidationContext ( schema , ast , typeInfo , ( ) => null ) ;
261263 const visitor = new ComplexityVisitor ( context , {
262264 maximumComplexity : 100 ,
263265 estimators : [
@@ -284,7 +286,7 @@ describe('QueryComplexity analysis', () => {
284286 }
285287 ` ) ;
286288
287- const context = new ValidationContext ( schema , ast , typeInfo ) ;
289+ const context = new ValidationContext ( schema , ast , typeInfo , ( ) => null ) ;
288290 const visitor = new ComplexityVisitor ( context , {
289291 maximumComplexity : 100 ,
290292 estimators : [
@@ -310,7 +312,7 @@ describe('QueryComplexity analysis', () => {
310312 }
311313 ` ) ;
312314
313- const context = new ValidationContext ( schema , ast , typeInfo ) ;
315+ const context = new ValidationContext ( schema , ast , typeInfo , ( ) => null ) ;
314316 const visitor = new ComplexityVisitor ( context , {
315317 maximumComplexity : 100 ,
316318 estimators : [
@@ -332,7 +334,7 @@ describe('QueryComplexity analysis', () => {
332334 }
333335 ` ) ;
334336
335- const context = new ValidationContext ( schema , ast , typeInfo ) ;
337+ const context = new ValidationContext ( schema , ast , typeInfo , ( ) => null ) ;
336338 const visitor = new ComplexityVisitor ( context , {
337339 maximumComplexity : 100 ,
338340 estimators : [
@@ -353,7 +355,8 @@ describe('QueryComplexity analysis', () => {
353355 requiredArgs
354356 }
355357 ` ) ;
356- const context = new ValidationContext ( schema , ast , typeInfo ) ;
358+ const validationErrors : GraphQLError [ ] = [ ] ;
359+ const context = new ValidationContext ( schema , ast , typeInfo , err => validationErrors . push ( err ) ) ;
357360 const visitor = new ComplexityVisitor ( context , {
358361 maximumComplexity : 100 ,
359362 estimators : [
@@ -364,8 +367,8 @@ describe('QueryComplexity analysis', () => {
364367 ]
365368 } ) ;
366369 visit ( ast , visitWithTypeInfo ( typeInfo , visitor ) ) ;
367- expect ( context . getErrors ( ) . length ) . to . equal ( 1 ) ;
368- expect ( context . getErrors ( ) [ 0 ] . message ) . to . equal ( 'Argument "count" of required type "Int!" was not provided.' ) ;
370+ expect ( validationErrors . length ) . to . equal ( 1 ) ;
371+ expect ( validationErrors [ 0 ] . message ) . to . equal ( 'Argument "count" of required type "Int!" was not provided.' ) ;
369372 } ) ;
370373
371374 it ( 'should report error when no estimator is configured' , ( ) => {
@@ -374,14 +377,15 @@ describe('QueryComplexity analysis', () => {
374377 scalar
375378 }
376379 ` ) ;
377- const context = new ValidationContext ( schema , ast , typeInfo ) ;
380+ const validationErrors : GraphQLError [ ] = [ ] ;
381+ const context = new ValidationContext ( schema , ast , typeInfo , err => validationErrors . push ( err ) ) ;
378382 const visitor = new ComplexityVisitor ( context , {
379383 maximumComplexity : 100 ,
380384 estimators : [ ]
381385 } ) ;
382386 visit ( ast , visitWithTypeInfo ( typeInfo , visitor ) ) ;
383- expect ( context . getErrors ( ) . length ) . to . equal ( 1 ) ;
384- expect ( context . getErrors ( ) [ 0 ] . message ) . to . equal (
387+ expect ( validationErrors . length ) . to . equal ( 1 ) ;
388+ expect ( validationErrors [ 0 ] . message ) . to . equal (
385389 'No complexity could be calculated for field Query.scalar. ' +
386390 'At least one complexity estimator has to return a complexity score.'
387391 ) ;
@@ -393,16 +397,17 @@ describe('QueryComplexity analysis', () => {
393397 scalar
394398 }
395399 ` ) ;
396- const context = new ValidationContext ( schema , ast , typeInfo ) ;
400+ const validationErrors : GraphQLError [ ] = [ ] ;
401+ const context = new ValidationContext ( schema , ast , typeInfo , err => validationErrors . push ( err ) ) ;
397402 const visitor = new ComplexityVisitor ( context , {
398403 maximumComplexity : 100 ,
399404 estimators : [
400405 fieldConfigEstimator ( )
401406 ]
402407 } ) ;
403408 visit ( ast , visitWithTypeInfo ( typeInfo , visitor ) ) ;
404- expect ( context . getErrors ( ) . length ) . to . equal ( 1 ) ;
405- expect ( context . getErrors ( ) [ 0 ] . message ) . to . equal (
409+ expect ( validationErrors . length ) . to . equal ( 1 ) ;
410+ expect ( validationErrors [ 0 ] . message ) . to . equal (
406411 'No complexity could be calculated for field Query.scalar. ' +
407412 'At least one complexity estimator has to return a complexity score.'
408413 ) ;
0 commit comments