Skip to content

Commit

Permalink
fix: avoid duplicate variable name in genrated function for query cli…
Browse files Browse the repository at this point in the history
…ents (#1131)
  • Loading branch information
soartec-lab committed Jan 1, 2024
1 parent ca0b8f6 commit dbfb2e5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/query/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
GeneratorOptions,
GeneratorVerbOptions,
GetterParams,
GetterProp,
GetterProps,
GetterPropType,
GetterResponse,
Expand Down Expand Up @@ -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}']`
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dbfb2e5

Please sign in to comment.