@@ -4,7 +4,10 @@ import { describe, it } from 'mocha';
4
4
import { expectJSON } from '../../__testUtils__/expectJSON.js' ;
5
5
import { resolveOnNextTick } from '../../__testUtils__/resolveOnNextTick.js' ;
6
6
7
- import { AbortController } from '../../jsutils/AbortController.js' ;
7
+ import {
8
+ AbortController ,
9
+ hasAbortControllerSupport ,
10
+ } from '../../jsutils/AbortController.js' ;
8
11
import { inspect } from '../../jsutils/inspect.js' ;
9
12
10
13
import { Kind } from '../../language/kinds.js' ;
@@ -1315,59 +1318,60 @@ describe('Execute: Handles basic execution tasks', () => {
1315
1318
expect ( possibleTypes ) . to . deep . equal ( [ fooObject ] ) ;
1316
1319
} ) ;
1317
1320
1318
- it ( 'stops execution and throws an error when signal is aborted' , async ( ) => {
1319
- /**
1320
- * This test has 3 resolvers nested in each other.
1321
- * Every resolve function waits 200ms before returning data.
1322
- *
1323
- * The test waits for the first resolver and half of the 2nd resolver execution time (200ms + 100ms)
1324
- * and then aborts the execution.
1325
- *
1326
- * 2nd resolver execution finishes, and we then expect to not execute the 3rd resolver
1327
- * and to get an error about aborted operation.
1328
- */
1329
-
1330
- const WAIT_MS_BEFORE_RESOLVING = 200 ;
1331
- const ABORT_IN_MS_AFTER_STARTING_EXECUTION =
1332
- WAIT_MS_BEFORE_RESOLVING + WAIT_MS_BEFORE_RESOLVING / 2 ;
1333
-
1334
- const schema = new GraphQLSchema ( {
1335
- query : new GraphQLObjectType ( {
1336
- name : 'Query' ,
1337
- fields : {
1338
- resolvesIn500ms : {
1339
- type : new GraphQLObjectType ( {
1340
- name : 'ResolvesIn500ms' ,
1341
- fields : {
1342
- resolvesIn400ms : {
1343
- type : new GraphQLObjectType ( {
1344
- name : 'ResolvesIn400ms' ,
1345
- fields : {
1346
- shouldNotBeResolved : {
1347
- type : GraphQLString ,
1348
- /* c8 ignore next 3 */
1349
- resolve : ( ) => {
1350
- throw new Error ( 'This should not be executed!' ) ;
1321
+ /* c8 ignore start */
1322
+ if ( hasAbortControllerSupport ) {
1323
+ 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
+ } ,
1351
1356
} ,
1352
1357
} ,
1353
- } ,
1354
- } ) ,
1355
- resolve : ( ) =>
1356
- new Promise ( ( resolve ) => {
1357
- setTimeout ( ( ) => resolve ( { } ) , WAIT_MS_BEFORE_RESOLVING ) ;
1358
1358
} ) ,
1359
+ resolve : ( ) =>
1360
+ new Promise ( ( resolve ) => {
1361
+ setTimeout ( ( ) => resolve ( { } ) , WAIT_MS_BEFORE_RESOLVING ) ;
1362
+ } ) ,
1363
+ } ,
1359
1364
} ,
1360
- } ,
1361
- } ) ,
1362
- resolve : ( ) =>
1363
- new Promise ( ( resolve ) => {
1364
- setTimeout ( ( ) => resolve ( { } ) , WAIT_MS_BEFORE_RESOLVING ) ;
1365
1365
} ) ,
1366
+ resolve : ( ) =>
1367
+ new Promise ( ( resolve ) => {
1368
+ setTimeout ( ( ) => resolve ( { } ) , WAIT_MS_BEFORE_RESOLVING ) ;
1369
+ } ) ,
1370
+ } ,
1366
1371
} ,
1367
- } ,
1368
- } ) ,
1369
- } ) ;
1370
- const document = parse ( `
1372
+ } ) ,
1373
+ } ) ;
1374
+ const document = parse ( `
1371
1375
query {
1372
1376
resolvesIn500ms {
1373
1377
resolvesIn400ms {
@@ -1377,22 +1381,24 @@ describe('Execute: Handles basic execution tasks', () => {
1377
1381
}
1378
1382
` ) ;
1379
1383
1380
- const abortController = new AbortController ( ) ;
1381
- const executionPromise = execute ( {
1382
- schema,
1383
- document,
1384
- signal : abortController . signal ,
1385
- } ) ;
1386
-
1387
- setTimeout (
1388
- ( ) => abortController . abort ( ) ,
1389
- ABORT_IN_MS_AFTER_STARTING_EXECUTION ,
1390
- ) ;
1391
-
1392
- const result = await executionPromise ;
1393
- expect ( result . errors ?. [ 0 ] . message ) . to . eq ( 'Execution aborted.' ) ;
1394
- expect ( result . data ) . to . eql ( {
1395
- resolvesIn500ms : { resolvesIn400ms : null } ,
1396
- } ) ;
1397
- } ) ;
1384
+ const abortController = new AbortController ( ) ;
1385
+ const executionPromise = execute ( {
1386
+ schema,
1387
+ document,
1388
+ signal : abortController . signal ,
1389
+ } ) ;
1390
+
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 } ,
1400
+ } ) ;
1401
+ } ) ;
1402
+ }
1403
+ /* c8 ignore stop */
1398
1404
} ) ;
0 commit comments