Skip to content

Commit

Permalink
feat(query): add shouldExportMutatorHooks option (#1105)
Browse files Browse the repository at this point in the history
  • Loading branch information
ezequiel committed Jan 31, 2024
1 parent 2a77a04 commit e602232
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docs/src/pages/reference/configuration/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,14 @@ Type: `Boolean`.

Use to remove the generation of the abort signal provided by <a href="https://react-query.tanstack.com/" target="_blank">query</a>

##### shouldExportMutatorHooks

Type: `Boolean`.

Default Value: `true`.

Use to stop the export of mutator hooks. Useful if you want to rely soley on useQuery, useSuspenseQuery, etc.

#### angular

Type: `Object`.
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ export type NormalizedQueryOptions = {
queryKey?: NormalizedMutator;
queryOptions?: NormalizedMutator;
mutationOptions?: NormalizedMutator;
shouldExportMutatorHooks?: boolean;
signal?: boolean;
version?: 3 | 4 | 5;
};
Expand All @@ -349,6 +350,7 @@ export type QueryOptions = {
queryKey?: Mutator;
queryOptions?: Mutator;
mutationOptions?: Mutator;
shouldExportMutatorHooks?: boolean;
signal?: boolean;
version?: 3 | 4 | 5;
};
Expand Down
4 changes: 4 additions & 0 deletions packages/orval/src/utils/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export const normalizeOptions = async (
useQuery: true,
useMutation: true,
signal: true,
shouldExportMutatorHooks: true,
...normalizeQueryOptions(outputOptions.override?.query, workspace),
},
swr: {
Expand Down Expand Up @@ -450,6 +451,9 @@ const normalizeQueryOptions = (
),
}
: {}),
...(!isUndefined(queryOptions.shouldExportMutatorHooks)
? { shouldExportMutatorHooks: queryOptions.shouldExportMutatorHooks }
: {}),
...(!isUndefined(queryOptions.signal)
? { signal: queryOptions.signal }
: {}),
Expand Down
4 changes: 3 additions & 1 deletion packages/query/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,9 @@ const generateQueryRequestFunction = (
: '';

if (mutator.isHook) {
return `export const use${pascal(operationName)}Hook = () => {
return `${
override.query.shouldExportMutatorHooks ? 'export ' : ''
}const use${pascal(operationName)}Hook = () => {
const ${operationName} = ${mutator.name}<${
response.definition.success || 'unknown'
}>();
Expand Down
3 changes: 3 additions & 0 deletions packages/query/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export const normalizeQueryOptions = (
),
}
: {}),
...(queryOptions.shouldExportMutatorHooks
? { shouldExportMutatorHooks: true }
: {}),
...(queryOptions.signal ? { signal: true } : {}),
};
};
Expand Down

0 comments on commit e602232

Please sign in to comment.