@@ -48,6 +48,10 @@ function isQueryOrBody(arg: unknown): arg is Record<string, string> {
48
48
return typeof arg === "object" ;
49
49
}
50
50
51
+ function makeQueryParams ( query : Record < string , string > ) {
52
+ return new URLSearchParams ( Object . entries ( query ) ) ;
53
+ }
54
+
51
55
function makeUrl (
52
56
[ basePath , ...callPath ] : string [ ] ,
53
57
{
@@ -72,9 +76,9 @@ function makeUrl(
72
76
: callPath . map ( ( str ) => str . replace ( ":" , "" ) ) . join ( "/" ) ;
73
77
74
78
if ( query ) {
75
- url = `${ url } ?${ new URLSearchParams ( Object . entries ( query ) ) } ` ;
79
+ url = `${ url } ?${ makeQueryParams ( query ) } ` ;
76
80
} else if ( method === "GET" && body !== undefined && body !== null ) {
77
- url = `${ url } ?${ new URLSearchParams ( Object . entries ( body ) ) } ` ;
81
+ url = `${ url } ?${ makeQueryParams ( body as Record < string , string > ) } ` ;
78
82
}
79
83
80
84
return `${ basePath } /${ url } ` ;
@@ -173,19 +177,23 @@ function createClientProxy(
173
177
174
178
if ( config . extensions ) {
175
179
const [ action , extensionMethod ] = callPath . slice ( - 2 ) ;
180
+ const method = inferHTTPMethod ( action ) ;
176
181
const path = callPath . slice ( 0 , - 2 ) ;
177
182
const bodyOrQuery = isQueryOrBody ( pendingArgs [ 0 ] )
178
183
? pendingArgs [ 0 ]
179
184
: undefined ;
185
+ const query = method === "GET" ? bodyOrQuery : undefined ;
180
186
const queryFn = ( callTimeBody ?: any ) => {
181
- const method = inferHTTPMethod ( action ) ;
182
187
const body = method === "GET" ? undefined : callTimeBody ;
183
- const query = method === "GET" ? bodyOrQuery : undefined ;
184
188
185
189
return makeRequest ( config , action , path , body , query ) ;
186
190
} ;
187
191
const queryKey = [
188
- makeUrl ( path , { outputCase : config . urlCase , method : "GET" } ) ,
192
+ makeUrl ( path , {
193
+ outputCase : config . urlCase ,
194
+ method : "GET" ,
195
+ } ) ,
196
+ ...( query ? [ `${ makeQueryParams ( query ) } ` ] : [ ] ) ,
189
197
] ;
190
198
const handler = getExtensionHandler (
191
199
config . extensions ,
@@ -201,13 +209,18 @@ function createClientProxy(
201
209
202
210
if ( isCallingHook ( lastCall ) ) {
203
211
const action = callPath . slice ( - 1 ) [ 0 ] ;
212
+ const method = inferHTTPMethod ( action ) ;
204
213
const path = callPath . slice ( 0 , - 1 ) ;
205
214
const body = argumentsList [ 0 ] ;
206
215
207
216
return {
208
217
queryFn : ( ) => makeRequest ( config , action , path , body ) ,
209
218
queryKey : [
210
- makeUrl ( path , { outputCase : config . urlCase , method : "GET" } ) ,
219
+ makeUrl ( path , {
220
+ outputCase : config . urlCase ,
221
+ method : "GET" ,
222
+ } ) ,
223
+ ...( method === "GET" && body ? [ `${ makeQueryParams ( body ) } ` ] : [ ] ) ,
211
224
] ,
212
225
} ;
213
226
}
0 commit comments