@@ -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' ;
@@ -1277,59 +1280,60 @@ describe('Execute: Handles basic execution tasks', () => {
1277
1280
expect ( possibleTypes ) . to . deep . equal ( [ fooObject ] ) ;
1278
1281
} ) ;
1279
1282
1280
- it ( 'stops execution and throws an error when signal is aborted' , async ( ) => {
1281
- /**
1282
- * This test has 3 resolvers nested in each other.
1283
- * Every resolve function waits 200ms before returning data.
1284
- *
1285
- * The test waits for the first resolver and half of the 2nd resolver execution time (200ms + 100ms)
1286
- * and then aborts the execution.
1287
- *
1288
- * 2nd resolver execution finishes, and we then expect to not execute the 3rd resolver
1289
- * and to get an error about aborted operation.
1290
- */
1291
-
1292
- const WAIT_MS_BEFORE_RESOLVING = 200 ;
1293
- const ABORT_IN_MS_AFTER_STARTING_EXECUTION =
1294
- WAIT_MS_BEFORE_RESOLVING + WAIT_MS_BEFORE_RESOLVING / 2 ;
1295
-
1296
- const schema = new GraphQLSchema ( {
1297
- query : new GraphQLObjectType ( {
1298
- name : 'Query' ,
1299
- fields : {
1300
- resolvesIn500ms : {
1301
- type : new GraphQLObjectType ( {
1302
- name : 'ResolvesIn500ms' ,
1303
- fields : {
1304
- resolvesIn400ms : {
1305
- type : new GraphQLObjectType ( {
1306
- name : 'ResolvesIn400ms' ,
1307
- fields : {
1308
- shouldNotBeResolved : {
1309
- type : GraphQLString ,
1310
- /* c8 ignore next 3 */
1311
- resolve : ( ) => {
1312
- throw new Error ( 'This should not be executed!' ) ;
1283
+ if ( hasAbortControllerSupport ) {
1284
+ it ( 'stops execution and throws an error when signal is aborted' , async ( ) => {
1285
+ /**
1286
+ * This test has 3 resolvers nested in each other.
1287
+ * Every resolve function waits 200ms before returning data.
1288
+ *
1289
+ * The test waits for the first resolver and half of the 2nd resolver execution time (200ms + 100ms)
1290
+ * and then aborts the execution.
1291
+ *
1292
+ * 2nd resolver execution finishes, and we then expect to not execute the 3rd resolver
1293
+ * and to get an error about aborted operation.
1294
+ */
1295
+
1296
+ const WAIT_MS_BEFORE_RESOLVING = 200 ;
1297
+ const ABORT_IN_MS_AFTER_STARTING_EXECUTION =
1298
+ WAIT_MS_BEFORE_RESOLVING + WAIT_MS_BEFORE_RESOLVING / 2 ;
1299
+
1300
+ const schema = new GraphQLSchema ( {
1301
+ query : new GraphQLObjectType ( {
1302
+ name : 'Query' ,
1303
+ fields : {
1304
+ resolvesIn500ms : {
1305
+ type : new GraphQLObjectType ( {
1306
+ name : 'ResolvesIn500ms' ,
1307
+ fields : {
1308
+ resolvesIn400ms : {
1309
+ type : new GraphQLObjectType ( {
1310
+ name : 'ResolvesIn400ms' ,
1311
+ fields : {
1312
+ shouldNotBeResolved : {
1313
+ type : GraphQLString ,
1314
+ /* c8 ignore next 3 */
1315
+ resolve : ( ) => {
1316
+ throw new Error ( 'This should not be executed!' ) ;
1317
+ } ,
1313
1318
} ,
1314
1319
} ,
1315
- } ,
1316
- } ) ,
1317
- resolve : ( ) =>
1318
- new Promise ( ( resolve ) => {
1319
- setTimeout ( ( ) => resolve ( { } ) , WAIT_MS_BEFORE_RESOLVING ) ;
1320
1320
} ) ,
1321
+ resolve : ( ) =>
1322
+ new Promise ( ( resolve ) => {
1323
+ setTimeout ( ( ) => resolve ( { } ) , WAIT_MS_BEFORE_RESOLVING ) ;
1324
+ } ) ,
1325
+ } ,
1321
1326
} ,
1322
- } ,
1323
- } ) ,
1324
- resolve : ( ) =>
1325
- new Promise ( ( resolve ) => {
1326
- setTimeout ( ( ) => resolve ( { } ) , WAIT_MS_BEFORE_RESOLVING ) ;
1327
1327
} ) ,
1328
+ resolve : ( ) =>
1329
+ new Promise ( ( resolve ) => {
1330
+ setTimeout ( ( ) => resolve ( { } ) , WAIT_MS_BEFORE_RESOLVING ) ;
1331
+ } ) ,
1332
+ } ,
1328
1333
} ,
1329
- } ,
1330
- } ) ,
1331
- } ) ;
1332
- const document = parse ( `
1334
+ } ) ,
1335
+ } ) ;
1336
+ const document = parse ( `
1333
1337
query {
1334
1338
resolvesIn500ms {
1335
1339
resolvesIn400ms {
@@ -1339,22 +1343,23 @@ describe('Execute: Handles basic execution tasks', () => {
1339
1343
}
1340
1344
` ) ;
1341
1345
1342
- const abortController = new AbortController ( ) ;
1343
- const executionPromise = execute ( {
1344
- schema,
1345
- document,
1346
- signal : abortController . signal ,
1347
- } ) ;
1348
-
1349
- setTimeout (
1350
- ( ) => abortController . abort ( ) ,
1351
- ABORT_IN_MS_AFTER_STARTING_EXECUTION ,
1352
- ) ;
1353
-
1354
- const result = await executionPromise ;
1355
- expect ( result . errors ?. [ 0 ] . message ) . to . eq ( 'Execution aborted.' ) ;
1356
- expect ( result . data ) . to . eql ( {
1357
- resolvesIn500ms : { resolvesIn400ms : null } ,
1358
- } ) ;
1359
- } ) ;
1346
+ const abortController = new AbortController ( ) ;
1347
+ const executionPromise = execute ( {
1348
+ schema,
1349
+ document,
1350
+ signal : abortController . signal ,
1351
+ } ) ;
1352
+
1353
+ setTimeout (
1354
+ ( ) => abortController . abort ( ) ,
1355
+ ABORT_IN_MS_AFTER_STARTING_EXECUTION ,
1356
+ ) ;
1357
+
1358
+ const result = await executionPromise ;
1359
+ expect ( result . errors ?. [ 0 ] . message ) . to . eq ( 'Execution aborted.' ) ;
1360
+ expect ( result . data ) . to . eql ( {
1361
+ resolvesIn500ms : { resolvesIn400ms : null } ,
1362
+ } ) ;
1363
+ } ) ;
1364
+ }
1360
1365
} ) ;
0 commit comments