Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: feat(query): add shouldExportMutatorHooks option #1105

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -727,6 +727,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 @@ -332,6 +332,7 @@ export type NormalizedQueryOptions = {
queryKey?: NormalizedMutator;
queryOptions?: NormalizedMutator;
mutationOptions?: NormalizedMutator;
shouldExportMutatorHooks?: boolean;
signal?: boolean;
version?: 3 | 4 | 5;
};
Expand All @@ -348,6 +349,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 @@ -201,6 +201,7 @@ export const normalizeOptions = async (
useQuery: true,
useMutation: true,
signal: true,
shouldExportMutatorHooks: true,
melloware marked this conversation as resolved.
Show resolved Hide resolved
...normalizeQueryOptions(outputOptions.override?.query, workspace),
},
swr: {
Expand Down Expand Up @@ -440,6 +441,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 @@ -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'
}>();
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