Skip to content

Commit 5f659fc

Browse files
alumbomc-zoi
andauthored
fix: Query keys should be shared between suspense and not suspense (#973)
* fix: Query keys should be shared between suspense and not suspense * npm * Revert "npm" This reverts commit 81adae6. --------- Co-authored-by: Matthieu Chavigny <[email protected]>
1 parent 2e18352 commit 5f659fc

2 files changed

Lines changed: 16 additions & 22 deletions

File tree

packages/plugins/typescript/react-query/src/fetcher.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export abstract class FetcherRenderer {
9999
${implHookOuter}
100100
return ${infiniteQuery.getHook()}<${operationResultType}, TError, TData>(
101101
${this.generateInfiniteQueryFormattedParameters(
102-
this.generateInfiniteQueryKey(config, isSuspense),
102+
this.generateInfiniteQueryKey(config),
103103
implFetcher,
104104
)}
105105
)};`;
@@ -136,7 +136,7 @@ export abstract class FetcherRenderer {
136136
${implHookOuter}
137137
return ${query.getHook()}<${operationResultType}, TError, TData>(
138138
${this.generateQueryFormattedParameters(
139-
this.generateQueryKey(config, isSuspense),
139+
this.generateQueryKey(config),
140140
implFetcher,
141141
)}
142142
)};`;
@@ -222,8 +222,8 @@ export abstract class FetcherRenderer {
222222
return `options: Omit<${infiniteQuery.getOptions()}<${operationResultType}, TError, TData>, 'queryKey'> & { queryKey?: ${infiniteQuery.getOptions()}<${operationResultType}, TError, TData>['queryKey'] }`;
223223
}
224224

225-
public generateInfiniteQueryKey(config: GenerateConfig, isSuspense: boolean): string {
226-
const identifier = isSuspense ? 'infiniteSuspense' : 'infinite';
225+
public generateInfiniteQueryKey(config: GenerateConfig): string {
226+
const identifier = 'infinite';
227227
if (config.hasRequiredVariables)
228228
return `['${config.node.name.value}.${identifier}', variables]`;
229229
return `variables === undefined ? ['${config.node.name.value}.${identifier}'] : ['${config.node.name.value}.${identifier}', variables]`;
@@ -237,13 +237,13 @@ export abstract class FetcherRenderer {
237237
hook: this.generateInfiniteQueryHook(config, isSuspense),
238238
getKey: `${infiniteQuery.getHook(
239239
operationName,
240-
)}.getKey = (${signature}) => ${this.generateInfiniteQueryKey(config, isSuspense)};`,
240+
)}.getKey = (${signature}) => ${this.generateInfiniteQueryKey(config)};`,
241241
rootKey: `${infiniteQuery.getHook(operationName)}.rootKey = '${node.name.value}.infinite';`,
242242
};
243243
}
244244

245-
public generateQueryKey(config: GenerateConfig, isSuspense: boolean): string {
246-
const identifier = isSuspense ? `${config.node.name.value}Suspense` : config.node.name.value;
245+
public generateQueryKey(config: GenerateConfig): string {
246+
const identifier = config.node.name.value;
247247
if (config.hasRequiredVariables) return `['${identifier}', variables]`;
248248
return `variables === undefined ? ['${identifier}'] : ['${identifier}', variables]`;
249249
}
@@ -255,10 +255,7 @@ export abstract class FetcherRenderer {
255255
return {
256256
hook: this.generateQueryHook(config, isSuspense),
257257
document: `${query.getHook(operationName)}.document = ${documentVariableName};`,
258-
getKey: `${query.getHook(operationName)}.getKey = (${signature}) => ${this.generateQueryKey(
259-
config,
260-
isSuspense,
261-
)};`,
258+
getKey: `${query.getHook(operationName)}.getKey = (${signature}) => ${this.generateQueryKey(config)};`,
262259
rootKey: `${query.getHook(operationName)}.rootKey = '${node.name.value}';`,
263260
};
264261
}

packages/plugins/typescript/solid-query/src/fetcher.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export abstract class FetcherRenderer {
8989
${implHookOuter}
9090
return ${infiniteQuery.getHook()}<${operationResultType}, TError, TData>(
9191
${this.generateInfiniteQueryFormattedParameters(
92-
this.generateInfiniteQueryKey(config, isSuspense),
92+
this.generateInfiniteQueryKey(config),
9393
implFetcher,
9494
)}
9595
)};`;
@@ -126,7 +126,7 @@ export abstract class FetcherRenderer {
126126
${implHookOuter}
127127
return ${query.getHook()}<${operationResultType}, TError, TData>(
128128
${this.generateQueryFormattedParameters(
129-
this.generateQueryKey(config, isSuspense),
129+
this.generateQueryKey(config),
130130
implFetcher,
131131
)}
132132
)};`;
@@ -201,8 +201,8 @@ export abstract class FetcherRenderer {
201201
return `options: Omit<${infiniteQuery.getOptions()}<${operationResultType}, TError, TData>, 'queryKey'> & { queryKey?: ${infiniteQuery.getOptions()}<${operationResultType}, TError, TData>['queryKey'] }`;
202202
}
203203

204-
public generateInfiniteQueryKey(config: GenerateConfig, isSuspense: boolean): string {
205-
const identifier = isSuspense ? 'infiniteSuspense' : 'infinite';
204+
public generateInfiniteQueryKey(config: GenerateConfig): string {
205+
const identifier = 'infinite';
206206
if (config.hasRequiredVariables)
207207
return `['${config.node.name.value}.${identifier}', variables]`;
208208
return `variables === undefined ? ['${config.node.name.value}.${identifier}'] : ['${config.node.name.value}.${identifier}', variables]`;
@@ -216,13 +216,13 @@ export abstract class FetcherRenderer {
216216
hook: this.generateInfiniteQueryHook(config, isSuspense),
217217
getKey: `${infiniteQuery.getHook(
218218
operationName,
219-
)}.getKey = (${signature}) => ${this.generateInfiniteQueryKey(config, isSuspense)};`,
219+
)}.getKey = (${signature}) => ${this.generateInfiniteQueryKey(config)};`,
220220
rootKey: `${infiniteQuery.getHook(operationName)}.rootKey = '${node.name.value}.infinite';`,
221221
};
222222
}
223223

224-
public generateQueryKey(config: GenerateConfig, isSuspense: boolean): string {
225-
const identifier = isSuspense ? `${config.node.name.value}Suspense` : config.node.name.value;
224+
public generateQueryKey(config: GenerateConfig): string {
225+
const identifier = config.node.name.value;
226226
if (config.hasRequiredVariables) return `['${identifier}', variables]`;
227227
return `variables === undefined ? ['${identifier}'] : ['${identifier}', variables]`;
228228
}
@@ -234,10 +234,7 @@ export abstract class FetcherRenderer {
234234
return {
235235
hook: this.generateQueryHook(config, isSuspense),
236236
document: `${query.getHook(operationName)}.document = ${documentVariableName};`,
237-
getKey: `${query.getHook(operationName)}.getKey = (${signature}) => ${this.generateQueryKey(
238-
config,
239-
isSuspense,
240-
)};`,
237+
getKey: `${query.getHook(operationName)}.getKey = (${signature}) => ${this.generateQueryKey(config)};`,
241238
rootKey: `${query.getHook(operationName)}.rootKey = '${node.name.value}';`,
242239
};
243240
}

0 commit comments

Comments
 (0)