@@ -20,11 +20,11 @@ type Options = {
2020 dangerouslyDisableCache ?: boolean ;
2121
2222 /**
23- * Sets the timeout duration in ms after which a request will throw a timeout error
23+ * Sets the default timeout duration in ms after which a request will throw a timeout error
2424 *
2525 * @default 30000
2626 */
27- timeout ?: number ;
27+ defaultTimeout ?: number ;
2828} ;
2929
3030type CacheOptions = {
@@ -40,13 +40,13 @@ const tracer = trace.getTracer(
4040export const initServerFetcher =
4141 (
4242 url : string ,
43- { dangerouslyDisableCache = false , timeout = 30000 } : Options = { }
43+ { dangerouslyDisableCache = false , defaultTimeout = 30000 } : Options = { }
4444 ) =>
4545 async < TResponse , TVariables > (
4646 astNode : DocumentTypeDecoration < TResponse , TVariables > ,
4747 variables : TVariables ,
4848 { cache, next = { } } : CacheOptions ,
49- signal : AbortSignal = AbortSignal . timeout ( timeout )
49+ signal : AbortSignal = AbortSignal . timeout ( defaultTimeout )
5050 ) : Promise < GqlResponse < TResponse > > => {
5151 const query = astNode . toString ( ) ;
5252 const operationName = extractOperationName ( query ) || "(GraphQL)" ;
@@ -93,15 +93,17 @@ export const initServerFetcher =
9393 let response = await gqlPersistedQuery (
9494 url ,
9595 getQueryString ( operationName , variables , extensions ) ,
96- { cache, next }
96+ { cache, next } ,
97+ signal
9798 ) ;
9899
99100 if ( response . errors ?. [ 0 ] ?. message === "PersistedQueryNotFound" ) {
100101 // If the cached query doesn't exist, fall back to POST request and let the server cache it.
101102 response = await gqlPost (
102103 url ,
103104 JSON . stringify ( { operationName, query, variables, extensions } ) ,
104- { cache, next }
105+ { cache, next } ,
106+ signal
105107 ) ;
106108 }
107109
@@ -138,13 +140,15 @@ const gqlPost = async (
138140const gqlPersistedQuery = async (
139141 url : string ,
140142 queryString : URLSearchParams ,
141- { cache, next } : CacheOptions
143+ { cache, next } : CacheOptions ,
144+ signal : AbortSignal = AbortSignal . timeout ( 30000 )
142145) => {
143146 const response = await fetch ( `${ url } ?${ queryString } ` , {
144147 method : "GET" ,
145148 headers : defaultHeaders ,
146149 cache,
147150 next,
151+ signal,
148152 } ) ;
149153
150154 return parseResponse ( response ) ;
0 commit comments