@@ -11,6 +11,7 @@ import { Kind } from '../../language/kinds';
11
11
import { parse } from '../../language/parser' ;
12
12
13
13
import {
14
+ GraphQLInputObjectType ,
14
15
GraphQLInterfaceType ,
15
16
GraphQLList ,
16
17
GraphQLNonNull ,
@@ -1320,4 +1321,69 @@ describe('Execute: Handles basic execution tasks', () => {
1320
1321
expect ( result ) . to . deep . equal ( { data : { foo : { bar : 'bar' } } } ) ;
1321
1322
expect ( possibleTypes ) . to . deep . equal ( [ fooObject ] ) ;
1322
1323
} ) ;
1324
+
1325
+ it ( 'uses a different number of max coercion errors' , ( ) => {
1326
+ const schema = new GraphQLSchema ( {
1327
+ query : new GraphQLObjectType ( {
1328
+ name : 'Query' ,
1329
+ fields : {
1330
+ dummy : { type : GraphQLString } ,
1331
+ } ,
1332
+ } ) ,
1333
+ mutation : new GraphQLObjectType ( {
1334
+ name : 'Mutation' ,
1335
+ fields : {
1336
+ updateUser : {
1337
+ type : GraphQLString ,
1338
+ args : {
1339
+ data : {
1340
+ type : new GraphQLInputObjectType ( {
1341
+ name : 'User' ,
1342
+ fields : {
1343
+ email : { type : new GraphQLNonNull ( GraphQLString ) } ,
1344
+ } ,
1345
+ } ) ,
1346
+ } ,
1347
+ } ,
1348
+ } ,
1349
+ } ,
1350
+ } ) ,
1351
+ } ) ;
1352
+
1353
+ const document = parse ( `
1354
+ mutation ($data: User) {
1355
+ updateUser(data: $data)
1356
+ }
1357
+ ` ) ;
1358
+
1359
+ const executionOptions = {
1360
+ maxCoercionErrors : 1 ,
1361
+ } ;
1362
+
1363
+ const result = executeSync ( {
1364
+ schema,
1365
+ document,
1366
+ variableValues : {
1367
+ data : {
1368
+ email : '' ,
1369
+ wrongArg : 'wrong' ,
1370
+ wrongArg2 : 'wrong' ,
1371
+ wrongArg3 : 'wrong' ,
1372
+ } ,
1373
+ } ,
1374
+ executionOptions,
1375
+ } ) ;
1376
+
1377
+ // Returns at least 2 errors, one for the first 'wrongArg', and one for coercion limit
1378
+ expect ( result . errors ) . to . have . lengthOf (
1379
+ executionOptions . maxCoercionErrors + 1 ,
1380
+ ) ;
1381
+ expect (
1382
+ result . errors && result . errors . length > 0
1383
+ ? result . errors [ result . errors . length - 1 ] . message
1384
+ : undefined ,
1385
+ ) . to . equal (
1386
+ 'Too many errors processing variables, error limit reached. Execution aborted.' ,
1387
+ ) ;
1388
+ } ) ;
1323
1389
} ) ;
0 commit comments