@@ -8,14 +8,14 @@ import {
88 SyncExecutor ,
99} from '@graphql-tools/utils' ;
1010import { GraphQLResolveInfo , print } from 'graphql' ;
11- import { cancelNeeded } from './addCancelToResponseStream.js' ;
1211import { isLiveQueryOperationDefinitionNode } from './isLiveQueryOperationDefinitionNode.js' ;
1312import { prepareGETUrl } from './prepareGETUrl.js' ;
1413import { ValueOrPromise } from 'value-or-promise' ;
1514import { createFormDataFromVariables } from './createFormDataFromVariables.js' ;
1615import { handleEventStreamResponse } from './handleEventStreamResponse.js' ;
1716import { handleMultipartMixedResponse } from './handleMultipartMixedResponse.js' ;
1817import { fetch as defaultFetch , AbortController } from '@whatwg-node/fetch' ;
18+ import { cancelNeeded } from './addCancelToResponseStream.js' ;
1919
2020export type SyncFetchFn = ( url : string , init ?: RequestInit , context ?: any , info ?: GraphQLResolveInfo ) => SyncResponse ;
2121export type SyncResponse = Omit < Response , 'json' | 'text' > & {
@@ -78,7 +78,7 @@ export function buildHTTPExecutor(
7878export function buildHTTPExecutor ( options ?: HTTPExecutorOptions ) : Executor < any , HTTPExecutorOptions > {
7979 const executor = ( request : ExecutionRequest < any , any , any , HTTPExecutorOptions > ) => {
8080 const fetchFn = request . extensions ?. fetch ?? options ?. fetch ?? defaultFetch ;
81- const controller = cancelNeeded ( ) ? new AbortController ( ) : undefined ;
81+ let controller : AbortController | undefined ;
8282 let method = request . extensions ?. method || options ?. method || 'POST' ;
8383
8484 const operationAst = getOperationASTFromRequest ( request ) ;
@@ -113,13 +113,18 @@ export function buildHTTPExecutor(options?: HTTPExecutorOptions): Executor<any,
113113
114114 let timeoutId : any ;
115115 if ( options ?. timeout ) {
116+ controller = new AbortController ( ) ;
116117 timeoutId = setTimeout ( ( ) => {
117118 if ( ! controller ?. signal . aborted ) {
118119 controller ?. abort ( ) ;
119120 }
120121 } , options . timeout ) ;
121122 }
122123
124+ if ( ! controller && cancelNeeded ( ) ) {
125+ controller = new AbortController ( ) ;
126+ }
127+
123128 return new ValueOrPromise ( ( ) => {
124129 switch ( method ) {
125130 case 'GET' : {
0 commit comments