@@ -48,6 +48,10 @@ function isQueryOrBody(arg: unknown): arg is Record<string, string> {
4848 return typeof arg === "object" ;
4949}
5050
51+ function makeQueryParams ( query : Record < string , string > ) {
52+ return new URLSearchParams ( Object . entries ( query ) ) ;
53+ }
54+
5155function makeUrl (
5256 [ basePath , ...callPath ] : string [ ] ,
5357 {
@@ -72,9 +76,9 @@ function makeUrl(
7276 : callPath . map ( ( str ) => str . replace ( ":" , "" ) ) . join ( "/" ) ;
7377
7478 if ( query ) {
75- url = `${ url } ?${ new URLSearchParams ( Object . entries ( query ) ) } ` ;
79+ url = `${ url } ?${ makeQueryParams ( query ) } ` ;
7680 } 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 > ) } ` ;
7882 }
7983
8084 return `${ basePath } /${ url } ` ;
@@ -173,19 +177,23 @@ function createClientProxy(
173177
174178 if ( config . extensions ) {
175179 const [ action , extensionMethod ] = callPath . slice ( - 2 ) ;
180+ const method = inferHTTPMethod ( action ) ;
176181 const path = callPath . slice ( 0 , - 2 ) ;
177182 const bodyOrQuery = isQueryOrBody ( pendingArgs [ 0 ] )
178183 ? pendingArgs [ 0 ]
179184 : undefined ;
185+ const query = method === "GET" ? bodyOrQuery : undefined ;
180186 const queryFn = ( callTimeBody ?: any ) => {
181- const method = inferHTTPMethod ( action ) ;
182187 const body = method === "GET" ? undefined : callTimeBody ;
183- const query = method === "GET" ? bodyOrQuery : undefined ;
184188
185189 return makeRequest ( config , action , path , body , query ) ;
186190 } ;
187191 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 ) } ` ] : [ ] ) ,
189197 ] ;
190198 const handler = getExtensionHandler (
191199 config . extensions ,
@@ -201,13 +209,18 @@ function createClientProxy(
201209
202210 if ( isCallingHook ( lastCall ) ) {
203211 const action = callPath . slice ( - 1 ) [ 0 ] ;
212+ const method = inferHTTPMethod ( action ) ;
204213 const path = callPath . slice ( 0 , - 1 ) ;
205214 const body = argumentsList [ 0 ] ;
206215
207216 return {
208217 queryFn : ( ) => makeRequest ( config , action , path , body ) ,
209218 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 ) } ` ] : [ ] ) ,
211224 ] ,
212225 } ;
213226 }
0 commit comments