Skip to content

Commit

Permalink
fix(client-query): return type can be undefined when config request o…
Browse files Browse the repository at this point in the history
…ptions is set to false (#1578)
  • Loading branch information
anymaniax authored Aug 14, 2024
1 parent d5627c5 commit a51064a
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions packages/query/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,9 @@ const getQueryOptionsDefinition = ({
? `, ${funcReturnType}, QueryKey, ${queryParams?.schema.name}['${queryParam}']`
: ''
}>`;
return `${partialOptions ? 'Partial<' : ''}${optionType}${partialOptions ? '>' : ''}${optionTypeInitialDataPostfix}`;
return `${partialOptions ? 'Partial<' : ''}${optionType}${
partialOptions ? '>' : ''
}${optionTypeInitialDataPostfix}`;
}

return `${prefix}MutationOptions<Awaited<ReturnType<${
Expand Down Expand Up @@ -542,7 +544,9 @@ const generateQueryArguments = ({
});

if (!isRequestOptions) {
return `${type ? 'queryOptions' : 'mutationOptions'}?: ${definition}`;
return `${type ? 'queryOptions' : 'mutationOptions'}${
initialData !== 'defined' ? '?' : ''
}: ${definition}`;
}

const requestType = getQueryArgumentsRequestType(httpClient, mutator);
Expand Down Expand Up @@ -599,9 +603,9 @@ const generateQueryReturnType = ({
}
case OutputClient.REACT_QUERY:
default: {
return ` ${isInitialDataDefined && !isSuspenseQuery(type) ? 'Defined' : ''}Use${pascal(
type,
)}Result<TData, TError> & { queryKey: QueryKey }`;
return ` ${
isInitialDataDefined && !isSuspenseQuery(type) ? 'Defined' : ''
}Use${pascal(type)}Result<TData, TError> & { queryKey: QueryKey }`;
}
}
};
Expand Down Expand Up @@ -751,7 +755,9 @@ const generateQueryImplementation = ({
)
return param.destructured;
return param.name === 'params'
? `{...${isVue(outputClient) ? `unref(params)` : 'params'}, ${queryParam}: pageParam || ${
? `{...${
isVue(outputClient) ? `unref(params)` : 'params'
}, ${queryParam}: pageParam || ${
isVue(outputClient)
? `unref(params)?.['${queryParam}']`
: `params?.['${queryParam}']`
Expand Down Expand Up @@ -1181,7 +1187,9 @@ const generateQueryHook = async (
: `\`${route}\``;

// Note: do not unref() params in Vue - this will make key lose reactivity
const queryKeyFn = `${override.query.shouldExportQueryKey ? 'export ' : ''}const ${queryKeyFnName} = (${queryKeyProps}) => {
const queryKeyFn = `${
override.query.shouldExportQueryKey ? 'export ' : ''
}const ${queryKeyFnName} = (${queryKeyProps}) => {
return [${routeString}${queryParams ? ', ...(params ? [params]: [])' : ''}${
body.implementation ? `, ${body.implementation}` : ''
}] as const;
Expand Down Expand Up @@ -1321,11 +1329,9 @@ ${hooksOptionImplementation}
}> = (${properties ? 'props' : ''}) => {
${properties ? `const {${properties}} = props ?? {};` : ''}
return ${operationName}(${properties}${properties ? ',' : ''}${getMutationRequestArgs(
isRequestOptions,
httpClient,
mutator,
)})
return ${operationName}(${properties}${
properties ? ',' : ''
}${getMutationRequestArgs(isRequestOptions, httpClient, mutator)})
}
${
Expand Down

0 comments on commit a51064a

Please sign in to comment.