Skip to content

Commit

Permalink
feat(query): generate query return type for along with hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
CPatchane committed Mar 9, 2022
1 parent 8e99ff9 commit e4c1dd9
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/core/generators/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,18 +376,25 @@ const generateQueryImplementation = ({
: response.definition.errors || 'unknown';
}

const dataType = mutator?.isHook
? `ReturnType<typeof use${pascal(operationName)}Hook>`
: `typeof ${operationName}`;

return `
export const ${camel(`use-${name}`)} = <TData = AsyncReturnType<${
mutator?.isHook
? `ReturnType<typeof use${pascal(operationName)}Hook>`
: `typeof ${operationName}`
}>, TError = ${errorType}>(\n ${queryProps} ${generateQueryArguments({
operationName,
definitions: '',
mutator,
isRequestOptions,
type,
})}\n ): ${returnType} & { queryKey: QueryKey } => {
export type ${pascal(name)}QueryData = AsyncReturnType<${dataType}>
export type ${pascal(name)}QueryError = ${errorType}
export const ${camel(
`use-${name}`,
)} = <TData = AsyncReturnType<${dataType}>, TError = ${errorType}>(\n ${queryProps} ${generateQueryArguments(
{
operationName,
definitions: '',
mutator,
isRequestOptions,
type,
},
)}\n ): ${returnType} & { queryKey: QueryKey } => {
${
isRequestOptions
Expand Down

0 comments on commit e4c1dd9

Please sign in to comment.