@@ -1318,87 +1318,106 @@ describe('Execute: Handles basic execution tasks', () => {
1318
1318
expect ( possibleTypes ) . to . deep . equal ( [ fooObject ] ) ;
1319
1319
} ) ;
1320
1320
1321
- /* c8 ignore start */
1322
1321
if ( hasAbortControllerSupport ) {
1323
1322
it ( 'stops execution and throws an error when signal is aborted' , async ( ) => {
1324
- /**
1325
- * This test has 3 resolvers nested in each other.
1326
- * Every resolve function waits 200ms before returning data.
1327
- *
1328
- * The test waits for the first resolver and half of the 2nd resolver execution time (200ms + 100ms)
1329
- * and then aborts the execution.
1330
- *
1331
- * 2nd resolver execution finishes, and we then expect to not execute the 3rd resolver
1332
- * and to get an error about aborted operation.
1333
- */
1334
-
1335
- const WAIT_MS_BEFORE_RESOLVING = 200 ;
1336
- const ABORT_IN_MS_AFTER_STARTING_EXECUTION =
1337
- WAIT_MS_BEFORE_RESOLVING + WAIT_MS_BEFORE_RESOLVING / 2 ;
1338
-
1339
- const schema = new GraphQLSchema ( {
1340
- query : new GraphQLObjectType ( {
1341
- name : 'Query' ,
1342
- fields : {
1343
- resolvesIn500ms : {
1344
- type : new GraphQLObjectType ( {
1345
- name : 'ResolvesIn500ms' ,
1346
- fields : {
1347
- resolvesIn400ms : {
1348
- type : new GraphQLObjectType ( {
1349
- name : 'ResolvesIn400ms' ,
1350
- fields : {
1351
- shouldNotBeResolved : {
1352
- type : GraphQLString ,
1353
- resolve : ( ) => {
1354
- throw new Error ( 'This should not be executed!' ) ;
1355
- } ,
1356
- } ,
1357
- } ,
1358
- } ) ,
1359
- resolve : ( ) =>
1360
- new Promise ( ( resolve ) => {
1361
- setTimeout ( ( ) => resolve ( { } ) , WAIT_MS_BEFORE_RESOLVING ) ;
1362
- } ) ,
1363
- } ,
1364
- } ,
1365
- } ) ,
1366
- resolve : ( ) =>
1367
- new Promise ( ( resolve ) => {
1368
- setTimeout ( ( ) => resolve ( { } ) , WAIT_MS_BEFORE_RESOLVING ) ;
1369
- } ) ,
1323
+ const TestType : GraphQLObjectType = new GraphQLObjectType ( {
1324
+ name : 'TestType' ,
1325
+ fields : ( ) => ( {
1326
+ resolveOnNextTick : {
1327
+ type : TestType ,
1328
+ resolve : ( ) => resolveOnNextTick ( { } ) ,
1329
+ } ,
1330
+ string : {
1331
+ type : GraphQLString ,
1332
+ args : {
1333
+ value : { type : new GraphQLNonNull ( GraphQLString ) } ,
1370
1334
} ,
1335
+ resolve : ( _ , { value } ) => value ,
1336
+ } ,
1337
+ abortExecution : {
1338
+ type : GraphQLString ,
1339
+ resolve : ( ) => {
1340
+ abortController . abort ( ) ;
1341
+ return 'aborted' ;
1342
+ } ,
1343
+ } ,
1344
+ shouldNotBeResolved : {
1345
+ type : GraphQLString ,
1346
+ /* c8 ignore next */
1347
+ resolve : ( ) => 'This should not be executed!' ,
1371
1348
} ,
1372
1349
} ) ,
1373
1350
} ) ;
1351
+
1352
+ const schema = new GraphQLSchema ( {
1353
+ query : TestType ,
1354
+ } ) ;
1355
+
1374
1356
const document = parse ( `
1375
- query {
1376
- resolvesIn500ms {
1377
- resolvesIn400ms {
1378
- shouldNotBeResolved
1357
+ query {
1358
+ value1: string(value: "1")
1359
+ resolveOnNextTick {
1360
+ value2: string(value: "2")
1361
+ resolveOnNextTick {
1362
+ resolveOnNextTick {
1363
+ shouldNotBeResolved
1364
+ }
1365
+ abortExecution
1366
+ }
1367
+ }
1368
+ alternativeBranch: resolveOnNextTick {
1369
+ value3: string(value: "3")
1370
+ resolveOnNextTick {
1371
+ shouldNotBeResolved
1372
+ }
1379
1373
}
1380
1374
}
1381
- }
1382
- ` ) ;
1375
+ ` ) ;
1383
1376
1384
1377
const abortController = new AbortController ( ) ;
1385
- const executionPromise = execute ( {
1378
+ const result = await execute ( {
1386
1379
schema,
1387
1380
document,
1388
1381
signal : abortController . signal ,
1389
1382
} ) ;
1390
1383
1391
- setTimeout (
1392
- ( ) => abortController . abort ( ) ,
1393
- ABORT_IN_MS_AFTER_STARTING_EXECUTION ,
1394
- ) ;
1395
-
1396
- const result = await executionPromise ;
1397
- expect ( result . errors ?. [ 0 ] . message ) . to . eq ( 'Execution aborted.' ) ;
1398
- expect ( result . data ) . to . eql ( {
1399
- resolvesIn500ms : { resolvesIn400ms : null } ,
1384
+ expectJSON ( result ) . toDeepEqual ( {
1385
+ data : {
1386
+ value1 : '1' ,
1387
+ resolveOnNextTick : {
1388
+ value2 : '2' ,
1389
+ resolveOnNextTick : {
1390
+ abortExecution : null ,
1391
+ resolveOnNextTick : null ,
1392
+ } ,
1393
+ } ,
1394
+ alternativeBranch : {
1395
+ resolveOnNextTick : null ,
1396
+ value3 : '3' ,
1397
+ } ,
1398
+ } ,
1399
+ errors : [
1400
+ {
1401
+ message : 'Execution aborted.' ,
1402
+ path : [ 'resolveOnNextTick' , 'resolveOnNextTick' , 'abortExecution' ] ,
1403
+ locations : [ { line : 10 , column : 15 } ] ,
1404
+ } ,
1405
+ {
1406
+ message : 'Execution aborted.' ,
1407
+ path : [ 'alternativeBranch' , 'resolveOnNextTick' ] ,
1408
+ locations : [ { line : 15 , column : 13 } ] ,
1409
+ } ,
1410
+ {
1411
+ message : 'Execution aborted.' ,
1412
+ path : [
1413
+ 'resolveOnNextTick' ,
1414
+ 'resolveOnNextTick' ,
1415
+ 'resolveOnNextTick' ,
1416
+ ] ,
1417
+ locations : [ { line : 7 , column : 15 } ] ,
1418
+ } ,
1419
+ ] ,
1400
1420
} ) ;
1401
1421
} ) ;
1402
1422
}
1403
- /* c8 ignore stop */
1404
1423
} ) ;
0 commit comments