File tree 4 files changed +34
-2
lines changed
4 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ async function getFact() {
6
6
params : {
7
7
query : { max_length : 500 } ,
8
8
} ,
9
+ next : {
10
+ revalidate : 10 ,
11
+ tags : [ "cat" ] ,
12
+ }
9
13
} ) ;
10
14
}
11
15
Original file line number Diff line number Diff line change @@ -108,7 +108,10 @@ export type RequestBodyOption<T> =
108
108
: { body : OperationRequestBodyContent < T > } ;
109
109
110
110
export type FetchOptions < T > = RequestOptions < T > &
111
- Omit < RequestInit , "body" | "headers" > ;
111
+ Omit < RequestInit , "body" | "headers" > & NextJsFetchOptions ;
112
+
113
+ export type NextJsFetchOptions =
114
+ { next ?: { revalidate ?: false | 0 | number , tags ?: string [ ] } } ;
112
115
113
116
/** This type helper makes the 2nd function param required if params/requestBody are required; otherwise, optional */
114
117
export type MaybeOptionalInit < P extends { } , M extends keyof P > =
Original file line number Diff line number Diff line change @@ -98,7 +98,7 @@ export default function createClient(clientOptions) {
98
98
}
99
99
100
100
// fetch!
101
- let response = await fetch ( request ) ;
101
+ let response = await fetch ( request , init . next ? { next : init . next } : undefined ) ;
102
102
103
103
// middleware (response)
104
104
// execute in reverse-array order (first priority gets last transform)
Original file line number Diff line number Diff line change @@ -952,6 +952,31 @@ describe("client", () => {
952
952
const req = fetchMocker . mock . calls [ 0 ] [ 0 ] ;
953
953
expect ( req . credentials ) . toBe ( "include" ) ;
954
954
} ) ;
955
+
956
+ it ( "passes NextJs specific options" , async ( ) => {
957
+ function createCustomFetch ( data : any ) {
958
+ const response = {
959
+ clone : ( ) => ( { ...response } ) ,
960
+ headers : new Headers ( ) ,
961
+ json : async ( ) => data ,
962
+ status : 200 ,
963
+ ok : true ,
964
+ } as Response ;
965
+ return async (
966
+ input : RequestInfo | URL ,
967
+ init ?: RequestInit | undefined ,
968
+ ) => {
969
+ expect ( init ) . toEqual ( { next : { tags : [ "tag" ] , revalidate : 10 } } ) ;
970
+ return Promise . resolve ( response ) ;
971
+ } ;
972
+ }
973
+
974
+ const customFetch = createCustomFetch ( { } ) ;
975
+ const client = createClient < paths > ( { fetch : customFetch } ) ;
976
+
977
+ mockFetchOnce ( { status : 200 , body : "{}" } ) ;
978
+ client . GET ( "/self" , { next : { tags : [ "tag" ] , revalidate : 10 } } ) ;
979
+ } ) ;
955
980
} ) ;
956
981
957
982
describe ( "responses" , ( ) => {
You can’t perform that action at this time.
0 commit comments