Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid duplicate variable name in genrated function for query clients #1131

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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