@@ -18,9 +18,9 @@ const errorResponse = JSON.stringify({
1818} ) ;
1919
2020describe ( "gqlServerFetch" , ( ) => {
21- const gqlServerFetch = initServerFetcher ( "https://localhost/graphql" ) ;
2221
2322 it ( "should fetch a persisted query" , async ( ) => {
23+ const gqlServerFetch = initServerFetcher ( "https://localhost/graphql" ) ;
2424 const mockedFetch = fetchMock . mockResponse ( successResponse ) ;
2525 const gqlResponse = await gqlServerFetch (
2626 query ,
@@ -55,6 +55,7 @@ describe("gqlServerFetch", () => {
5555 } ) ;
5656
5757 it ( "should persist the query if it wasn't persisted yet" , async ( ) => {
58+ const gqlServerFetch = initServerFetcher ( "https://localhost/graphql" ) ;
5859 // Mock server saying: 'PersistedQueryNotFound'
5960 const mockedFetch = fetchMock
6061 . mockResponseOnce ( errorResponse )
@@ -96,6 +97,7 @@ describe("gqlServerFetch", () => {
9697 ) ;
9798 } ) ;
9899 it ( "should fetch a persisted query without revalidate" , async ( ) => {
100+ const gqlServerFetch = initServerFetcher ( "https://localhost/graphql" ) ;
99101 const mockedFetch = fetchMock . mockResponse ( successResponse ) ;
100102 const gqlResponse = await gqlServerFetch (
101103 query ,
@@ -127,5 +129,39 @@ describe("gqlServerFetch", () => {
127129 ) ;
128130 } ) ;
129131
132+ it ( "should disable cache when disableCache is set" , async ( ) => {
133+ const gqlServerFetch = initServerFetcher ( "https://localhost/graphql" , {
134+ disableCache : true ,
135+ } ) ;
136+ const mockedFetch = fetchMock . mockResponse ( successResponse ) ;
137+ const gqlResponse = await gqlServerFetch (
138+ query ,
139+ { myVar : "baz" } ,
140+
141+ // These don't have impact due to disableCache
142+ "force-cache" ,
143+ { revalidate : 900 }
144+ ) ;
145+
146+
147+ expect ( gqlResponse ) . toEqual ( response ) ;
148+ expect ( mockedFetch ) . toHaveBeenCalledTimes ( 1 ) ;
149+ expect ( mockedFetch ) . toHaveBeenCalledWith (
150+ "https://localhost/graphql" ,
151+ {
152+ method : "POST" , // <- Note that when persisting the query, the method is 'POST'
153+ body : JSON . stringify ( {
154+ operationName : "myQuery" ,
155+ query : query . toString ( ) ,
156+ variables : { myVar : "baz" }
157+ } ) ,
158+ headers : {
159+ "Content-Type" : "application/json" ,
160+ } ,
161+ cache : 'no-store' ,
162+ next : { revalidate : 0 } ,
163+ }
164+ ) ;
165+ } ) ;
130166
131167} ) ;
0 commit comments