@@ -32,10 +32,15 @@ export abstract class FetcherRenderer {
3232
3333 public abstract generateFetcherImplementation ( ) : string ;
3434 public abstract generateFetcherFetch ( config : GenerateConfig ) : string ;
35- protected abstract generateQueryHook ( config : GenerateConfig , isSuspense ?: boolean ) : string ;
35+ protected abstract generateQueryHook (
36+ config : GenerateConfig ,
37+ isSuspense : boolean ,
38+ uniqueSuspenseQueryKeys : boolean ,
39+ ) : string ;
3640 protected abstract generateInfiniteQueryHook (
3741 config : GenerateConfig ,
38- isSuspense ?: boolean ,
42+ isSuspense : boolean ,
43+ uniqueSuspenseQueryKeys : boolean ,
3944 ) : string ;
4045 protected abstract generateMutationHook ( config : GenerateConfig ) : string ;
4146
@@ -60,7 +65,11 @@ export abstract class FetcherRenderer {
6065 return queryMethodMap ;
6166 }
6267
63- protected generateInfiniteQueryHelper ( config : GenerateConfig , isSuspense : boolean ) {
68+ protected generateInfiniteQueryHelper (
69+ config : GenerateConfig ,
70+ isSuspense : boolean ,
71+ uniqueSuspenseQueryKeys : boolean ,
72+ ) {
6473 const { operationResultType, operationName } = config ;
6574
6675 const { infiniteQuery } = this . createQueryMethodMap ( isSuspense ) ;
@@ -99,7 +108,7 @@ export abstract class FetcherRenderer {
99108 ${ implHookOuter }
100109 return ${ infiniteQuery . getHook ( ) } <${ operationResultType } , TError, TData>(
101110 ${ this . generateInfiniteQueryFormattedParameters (
102- this . generateInfiniteQueryKey ( config , isSuspense ) ,
111+ this . generateInfiniteQueryKey ( config , isSuspense , uniqueSuspenseQueryKeys ) ,
103112 implFetcher ,
104113 ) }
105114 )};` ;
@@ -108,7 +117,11 @@ export abstract class FetcherRenderer {
108117 return { generateBaseInfiniteQueryHook, variables, options } ;
109118 }
110119
111- protected generateQueryHelper ( config : GenerateConfig , isSuspense : boolean ) {
120+ protected generateQueryHelper (
121+ config : GenerateConfig ,
122+ isSuspense : boolean ,
123+ uniqueSuspenseQueryKeys : boolean ,
124+ ) {
112125 const { operationName, operationResultType } = config ;
113126
114127 const { query } = this . createQueryMethodMap ( isSuspense ) ;
@@ -136,7 +149,7 @@ export abstract class FetcherRenderer {
136149 ${ implHookOuter }
137150 return ${ query . getHook ( ) } <${ operationResultType } , TError, TData>(
138151 ${ this . generateQueryFormattedParameters (
139- this . generateQueryKey ( config , isSuspense ) ,
152+ this . generateQueryKey ( config , isSuspense , uniqueSuspenseQueryKeys ) ,
140153 implFetcher ,
141154 ) }
142155 )};` ;
@@ -222,42 +235,63 @@ export abstract class FetcherRenderer {
222235 return `options: Omit<${ infiniteQuery . getOptions ( ) } <${ operationResultType } , TError, TData>, 'queryKey'> & { queryKey?: ${ infiniteQuery . getOptions ( ) } <${ operationResultType } , TError, TData>['queryKey'] }` ;
223236 }
224237
225- public generateInfiniteQueryKey ( config : GenerateConfig , isSuspense : boolean ) : string {
226- const identifier = isSuspense ? 'infiniteSuspense' : 'infinite' ;
238+ public generateInfiniteQueryKey (
239+ config : GenerateConfig ,
240+ isSuspense : boolean ,
241+ uniqueSuspenseQueryKeys : boolean ,
242+ ) : string {
243+ const identifier = isSuspense
244+ ? `infinite${ uniqueSuspenseQueryKeys ? 'Suspense' : '' } `
245+ : 'infinite' ;
227246 if ( config . hasRequiredVariables )
228247 return `['${ config . node . name . value } .${ identifier } ', variables]` ;
229248 return `variables === undefined ? ['${ config . node . name . value } .${ identifier } '] : ['${ config . node . name . value } .${ identifier } ', variables]` ;
230249 }
231250
232- public generateInfiniteQueryOutput ( config : GenerateConfig , isSuspense = false ) {
251+ public generateInfiniteQueryOutput (
252+ config : GenerateConfig ,
253+ isSuspense = false ,
254+ uniqueSuspenseQueryKeys : boolean ,
255+ ) {
233256 const { infiniteQuery } = this . createQueryMethodMap ( isSuspense ) ;
234257 const signature = this . generateQueryVariablesSignature ( config ) ;
235258 const { operationName, node } = config ;
236259 return {
237- hook : this . generateInfiniteQueryHook ( config , isSuspense ) ,
260+ hook : this . generateInfiniteQueryHook ( config , isSuspense , uniqueSuspenseQueryKeys ) ,
238261 getKey : `${ infiniteQuery . getHook (
239262 operationName ,
240- ) } .getKey = (${ signature } ) => ${ this . generateInfiniteQueryKey ( config , isSuspense ) } ;`,
263+ ) } .getKey = (${ signature } ) => ${ this . generateInfiniteQueryKey ( config , isSuspense , uniqueSuspenseQueryKeys ) } ;`,
241264 rootKey : `${ infiniteQuery . getHook ( operationName ) } .rootKey = '${ node . name . value } .infinite';` ,
242265 } ;
243266 }
244267
245- public generateQueryKey ( config : GenerateConfig , isSuspense : boolean ) : string {
246- const identifier = isSuspense ? `${ config . node . name . value } Suspense` : config . node . name . value ;
268+ public generateQueryKey (
269+ config : GenerateConfig ,
270+ isSuspense : boolean ,
271+ uniqueSuspenseQueryKeys : boolean ,
272+ ) : string {
273+ const identifier = isSuspense
274+ ? `${ config . node . name . value } ${ uniqueSuspenseQueryKeys ? 'Suspense' : '' } `
275+ : config . node . name . value ;
247276 if ( config . hasRequiredVariables ) return `['${ identifier } ', variables]` ;
248277 return `variables === undefined ? ['${ identifier } '] : ['${ identifier } ', variables]` ;
249278 }
250279
251- public generateQueryOutput ( config : GenerateConfig , isSuspense = false ) {
280+ public generateQueryOutput (
281+ config : GenerateConfig ,
282+ isSuspense = false ,
283+ uniqueSuspenseQueryKeys : boolean ,
284+ ) {
252285 const { query } = this . createQueryMethodMap ( isSuspense ) ;
253286 const signature = this . generateQueryVariablesSignature ( config ) ;
254287 const { operationName, node, documentVariableName } = config ;
255288 return {
256- hook : this . generateQueryHook ( config , isSuspense ) ,
289+ hook : this . generateQueryHook ( config , isSuspense , uniqueSuspenseQueryKeys ) ,
257290 document : `${ query . getHook ( operationName ) } .document = ${ documentVariableName } ;` ,
258291 getKey : `${ query . getHook ( operationName ) } .getKey = (${ signature } ) => ${ this . generateQueryKey (
259292 config ,
260293 isSuspense ,
294+ uniqueSuspenseQueryKeys ,
261295 ) } ;`,
262296 rootKey : `${ query . getHook ( operationName ) } .rootKey = '${ node . name . value } ';` ,
263297 } ;
0 commit comments