diff --git a/docs/src/pages/reference/configuration/output.md b/docs/src/pages/reference/configuration/output.md index cb07f03ff..48467a4bd 100644 --- a/docs/src/pages/reference/configuration/output.md +++ b/docs/src/pages/reference/configuration/output.md @@ -727,6 +727,14 @@ Type: `Boolean`. Use to remove the generation of the abort signal provided by query +##### 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`. diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 933b62687..419316b63 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -332,6 +332,7 @@ export type NormalizedQueryOptions = { queryKey?: NormalizedMutator; queryOptions?: NormalizedMutator; mutationOptions?: NormalizedMutator; + shouldExportMutatorHooks?: boolean; signal?: boolean; version?: 3 | 4 | 5; }; @@ -348,6 +349,7 @@ export type QueryOptions = { queryKey?: Mutator; queryOptions?: Mutator; mutationOptions?: Mutator; + shouldExportMutatorHooks?: boolean; signal?: boolean; version?: 3 | 4 | 5; }; diff --git a/packages/orval/src/utils/options.ts b/packages/orval/src/utils/options.ts index 10ce3380c..ade18eb60 100644 --- a/packages/orval/src/utils/options.ts +++ b/packages/orval/src/utils/options.ts @@ -201,6 +201,7 @@ export const normalizeOptions = async ( useQuery: true, useMutation: true, signal: true, + shouldExportMutatorHooks: true, ...normalizeQueryOptions(outputOptions.override?.query, workspace), }, swr: { @@ -440,6 +441,9 @@ const normalizeQueryOptions = ( ), } : {}), + ...(!isUndefined(queryOptions.shouldExportMutatorHooks) + ? { shouldExportMutatorHooks: queryOptions.shouldExportMutatorHooks } + : {}), ...(!isUndefined(queryOptions.signal) ? { signal: queryOptions.signal } : {}), diff --git a/packages/query/src/index.ts b/packages/query/src/index.ts index c354097b3..f8398c193 100644 --- a/packages/query/src/index.ts +++ b/packages/query/src/index.ts @@ -437,7 +437,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' }>(); diff --git a/packages/query/src/utils.ts b/packages/query/src/utils.ts index cf668925e..e0d6fbfda 100644 --- a/packages/query/src/utils.ts +++ b/packages/query/src/utils.ts @@ -47,6 +47,9 @@ export const normalizeQueryOptions = ( ), } : {}), + ...(queryOptions.shouldExportMutatorHooks + ? { shouldExportMutatorHooks: true } + : {}), ...(queryOptions.signal ? { signal: true } : {}), }; };