Options#
Options for pluginReactQuery.
| Option | Type | Default | Description |
|---|---|---|---|
output | Output | { path: 'hooks', barrel: { type: 'named' } } | Where the generated hooks are written and exported |
group | Group | — | Split output into per-tag or per-path folders |
client | 'axios' | 'fetch' | — | Which registered client plugin the hooks call |
infinite | Partial<Infinite> | false | false | Generate useInfiniteQuery hooks for pagination |
suspense | Partial<object> | false | false | Generate useSuspenseQuery hooks |
query | Partial<Query> | false | { methods: ['GET'], … } | Configure the query hooks |
queryKey | (props) => unknown[] | built-in | Build the queryKey for each query hook |
mutation | Partial<Mutation> | false | { methods: ['POST', 'PUT', 'PATCH', 'DELETE'], … } | Configure the mutation hooks |
mutationKey | (props) => unknown[] | built-in | Build the mutationKey for each mutation hook |
customOptions | CustomOptions | — | Route every hook through your own options function |
hooks | boolean | false | Emit use* hook functions on top of the factories |
include | Array<Include> | — | Keep only operations that match |
exclude | Array<Exclude> | [] | Skip operations that match |
override | Array<Override> | [] | Apply different options per pattern |
resolver | ResolverPatch<ResolverReactQuery> | — | Customize generated names and file paths |
macros | Array<Macro> | — | Rewrite AST nodes before printing |
output#
Where the generated hooks are written and exported.
output.path#
Folder for the plugin's files, resolved against the global output.path and defaulting to 'hooks'. With output.mode: 'file', use a filename like 'hooks.ts'.
output.mode#
'file' writes a single file whose output.path includes the extension, and cannot be combined with group. 'directory' writes one file per operation. Leave it unset and Kubb reads output.path: a name with an extension means one file, anything else a directory.
output.barrel#
output.banner#
output.footer#
group#
group.name#
Turns a group key into a folder name, defaulting to the camelCased tag, or the first URL segment for path groups.
client#
Which registered client plugin the hooks call, 'axios' or 'fetch'. When omitted, a single registered client plugin is auto-detected, so it is only needed to disambiguate several.
Note
The hooks call a client plugin's functions, so register @kubb/plugin-axios or @kubb/plugin-fetch alongside this one.
infinite#
Adds infinite-query output for pagination. Pass an object to configure the cursor, or false (the default) to skip. Emitted only for operations with a query parameter matching infinite.queryParam.
With hooks at its default of false, setting infinite produces no file at all, not even the infiniteQueryOptions factory. Set hooks: true alongside infinite to generate the file and its useInfiniteQuery hook.
infinite.queryParam#
Query parameter that carries the page cursor, defaulting to 'id'.
infinite.initialPageParam#
Initial value for pageParam on the first fetch, defaulting to 0.
infinite.nextParam#
Path to the next-page cursor, as dot notation ('pagination.next.id') or array form. Defaults to null.
infinite.previousParam#
Path to the previous-page cursor, in the same forms. Defaults to null.
suspense#
Adds a suspense variant alongside the regular query output. Pass an empty object ({}) to enable, or leave it as false (the default) to skip it. TanStack Query v5+ only.
With hooks at its default of false, enabling suspense produces no file at all, not even the suspenseQueryOptions factory. Set hooks: true alongside suspense to generate the file and its useSuspenseQuery hook.
query#
Which operations become queries, emitting a queryOptions factory by default. Pass false to skip, or hooks to also emit useQuery.
query.methods#
HTTP methods treated as queries, defaulting to ['GET'].
query.importPath#
Module for the queryOptions import, defaulting to '@tanstack/react-query'.
queryKey#
Builds the queryKey for each hook from the operation node and casing, defaulting to the built-in queryKeyTransformer. String values are inlined verbatim, so wrap literals in JSON.stringify(...).
mutation#
Which operations become mutations, emitting a mutationOptions factory by default. Set false to skip, or hooks to also emit useMutation.
mutation.methods#
HTTP methods treated as mutations, defaulting to ['POST', 'PUT', 'PATCH', 'DELETE'].
mutation.importPath#
Module for the mutationOptions import, defaulting to '@tanstack/react-query'.
mutationKey#
Builds the mutationKey for each mutation hook, for batched invalidations or useMutationState. Same props and string-inlining caveat as queryKey, defaulting to the built-in mutationKeyTransformer.
customOptions#
Routes every hook through your own function that returns extra options such as onSuccess or select. Also emits a HookOptions type so your wrapper stays in sync.
customOptions.importPath#
Module of your custom-options hook, imported as a named import. Required when customOptions is set.
customOptions.name#
Exported name of your custom-options hook, defaulting to 'useCustomHookOptions'.
hooks#
When false (the default), only the query and mutation factory helpers are written. Set true to also generate useQuery, useSuspenseQuery, useInfiniteQuery, useSuspenseInfiniteQuery, and useMutation.
suspense and infinite are gated on hooks too: with hooks: false, enabling either one writes nothing at all, not even the suspenseQueryOptions or infiniteQueryOptions factories.
include#
exclude#
override#
resolver#
Changes how the plugin names generated files and symbols. Pass a partial patch. Override only the members you want, and anything you omit keeps resolverReactQuery. See Override a resolver for the this context and how a patch layers over the default.
Tip
Inside a method this is the full resolver, so this.default.name(name) reuses the built-in casing.
type ResolverReactQueryPatch = {
name?(name: string): string
file?: {
baseName?(params: { name: string; extname: string }): string
path?(params: { baseName: string; output: Output }): string
}
query?: {
name?(node: OperationNode): string // → 'useGetPetById'
optionsName?(node: OperationNode): string // → 'getPetByIdQueryOptions'
keyName?(node: OperationNode): string // → 'getPetByIdQueryKey'
keyTypeName?(node: OperationNode): string // → 'GetPetByIdQueryKey'
clientName?(node: OperationNode): string // → 'getPetById'
}
suspenseQuery?: { /* same members as query */ }
infiniteQuery?: { /* same members as query */ }
suspenseInfiniteQuery?: { /* same members as query */ }
mutation?: {
name?(node: OperationNode): string // → 'useUpdatePet'
optionsName?(node: OperationNode): string
keyName?(node: OperationNode): string
typeName?(node: OperationNode): string // → 'UpdatePet'
}
hook?: {
optionsName?(): string
customOptionsName?(): string
}
}