Skip to content

Commit

Permalink
fix(query): export QueryError type for muation query
Browse files Browse the repository at this point in the history
  • Loading branch information
CPatchane committed Mar 9, 2022
1 parent 25341f1 commit ba57eb1
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/core/generators/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,16 @@ const generateQueryHook = (
: response.definition.errors || 'unknown';
}

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

return `
export type ${pascal(
operationName,
)}QueryData = NonNullable<AsyncReturnType<${dataType}>>
export type ${pascal(operationName)}QueryError = ${errorType}
export const ${camel(`use-${operationName}`)} = <TError = ${errorType},
${!definitions ? `TVariables = void,` : ''}
TContext = unknown>(${generateQueryArguments({
Expand Down Expand Up @@ -580,13 +589,9 @@ const generateQueryHook = (
}
const mutationFn: MutationFunction<AsyncReturnType<${
mutator?.isHook
? `ReturnType<typeof use${pascal(operationName)}Hook>`
: `typeof ${operationName}`
}>, ${definitions ? `{${definitions}}` : 'TVariables'}> = (${
properties ? 'props' : ''
}) => {
const mutationFn: MutationFunction<AsyncReturnType<${dataType}>, ${
definitions ? `{${definitions}}` : 'TVariables'
}> = (${properties ? 'props' : ''}) => {
${properties ? `const {${properties}} = props || {}` : ''};
return ${operationName}(${properties}${properties ? ',' : ''}${
Expand Down

0 comments on commit ba57eb1

Please sign in to comment.