File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -230,6 +230,31 @@ describe("Codex", () => {
230230 } ) ;
231231 } ) ;
232232
233+ describe ( "fetch override" , ( ) => {
234+ it ( "should use the fetch override" , async ( ) => {
235+ const fetchMock = jest . fn ( ( input , init ) => {
236+ console . log ( "fetchMock" , input , init ) ;
237+ return Promise . resolve (
238+ new Response (
239+ JSON . stringify ( {
240+ data : { getNetworks : [ ] } ,
241+ } ) ,
242+ {
243+ status : 200 ,
244+ headers : new Headers ( {
245+ "Content-Type" : "application/json" ,
246+ } ) ,
247+ } ,
248+ ) ,
249+ ) ;
250+ } ) ;
251+
252+ const sdkWithFetch = new Codex ( "test-key" , { fetch : fetchMock } ) ;
253+ await sdkWithFetch . query ( getNetworksDocument , { } ) ;
254+ expect ( fetchMock ) . toHaveBeenCalled ( ) ;
255+ } ) ;
256+ } ) ;
257+
233258 describe ( "dispose" , ( ) => {
234259 it ( "should dispose websocket client when it exists" , async ( ) => {
235260 const mockDispose = jest . fn ( ) ;
Original file line number Diff line number Diff line change @@ -33,6 +33,9 @@ export type ApiConfig = {
3333
3434 // Use this to apply dynamic headers to the requests
3535 applyHeaders ?: ( ) => Promise < Record < string , string > > ;
36+
37+ // Use this to override the default fetch implementation.
38+ fetch ?: ( input : RequestInfo | URL , init ?: RequestInit ) => Promise < Response > ;
3639} ;
3740
3841const defaultConfig : ApiConfig = {
@@ -83,6 +86,7 @@ export class Codex {
8386 "X-Apollo-Operation-Name" : "query" ,
8487 ...config . headers ,
8588 } ) ,
89+ fetch : config . fetch ,
8690 } ) ;
8791 }
8892
You can’t perform that action at this time.
0 commit comments