From dbfb2e51c9f4b72cb6f0b1217dbc867a7f795de5 Mon Sep 17 00:00:00 2001 From: Shodai Suzuki Date: Mon, 1 Jan 2024 10:55:07 +0900 Subject: [PATCH] fix: avoid duplicate variable name in genrated function for query clients (#1131) --- packages/query/src/index.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/query/src/index.ts b/packages/query/src/index.ts index c354097b3..fa655c88c 100644 --- a/packages/query/src/index.ts +++ b/packages/query/src/index.ts @@ -14,6 +14,7 @@ import { GeneratorOptions, GeneratorVerbOptions, GetterParams, + GetterProp, GetterProps, GetterPropType, GetterResponse, @@ -963,6 +964,11 @@ const generateQueryImplementation = ({ const queryOptionsVarName = isRequestOptions ? 'queryOptions' : 'options'; + const hasParamReservedWord = props.some( + (prop: GetterProp) => prop.name === 'query', + ); + const queryResultVarName = hasParamReservedWord ? '_query' : 'query'; + const infiniteParam = queryParams && queryParam ? `, ${queryParams?.schema.name}['${queryParam}']` @@ -1056,15 +1062,15 @@ ${doc}export const ${camel( queryProperties ? ',' : '' }${isRequestOptions ? 'options' : 'queryOptions'}) - const query = ${camel( + const ${queryResultVarName} = ${camel( `${operationPrefix}-${type}`, )}(${queryOptionsVarName}) as ${returnType}; - query.queryKey = ${queryOptionsVarName}.queryKey ${ + ${queryResultVarName}.queryKey = ${queryOptionsVarName}.queryKey ${ isVue(outputClient) ? 'as QueryKey' : '' }; - return query; + return ${queryResultVarName}; }\n ${ usePrefetch