Vue Query
Officialv5.3.2@kubb/plugin-vue-query
Options
Pass these options to pluginVueQuery(). Shared options link to Shared plugin options for details.
Options overview
| Option | Purpose | Default |
|---|---|---|
output | Where files are written: path, mode, barrel, banner, footer. | { path: 'hooks', barrel: { type: 'named' } } |
group | Split output by tag or path: type, name. | None |
client | Which registered client plugin the composables call. | Auto-detected |
infinite | Add useInfiniteQuery composables for paginated reads. | false |
query | Configure or disable query composables. | { methods: ['GET'], importPath: '@tanstack/vue-query' } |
queryKey | Build the queryKey for each query composable. | Built-in queryKeyTransformer |
mutation | Configure or disable mutation composables. | { methods: ['POST', 'PUT', 'PATCH', 'DELETE'], importPath: '@tanstack/vue-query' } |
mutationKey | Build the mutationKey for each mutation composable. | Built-in mutationKeyTransformer |
hooks | Emit use* composables on top of the factory helpers. | false |
include | Keep only operations that match. | None |
exclude | Skip operations that match. | [] |
override | Apply different options per pattern. | [] |
resolver | Customize generated names and file paths. | resolverVueQuery |
macros | Rewrite AST nodes before printing. | [] |
Option details
client
Selects which registered client plugin the composables call. A single registered client is auto-detected. Set client when several are registered.
| Type | 'axios' | 'fetch' |
| Required | false |
@kubb/plugin-fetch.@kubb/plugin-axios.infinite
Adds infiniteQueryOptions and useInfiniteQuery for operations that declare the query parameter named in infinite.queryParam. Needs hooks: true.
| Type | Partial<Infinite> | false |
| Required | false |
| Default | false |
export function getPetsInfiniteQueryOptions(/* ... */) {
return infiniteQueryOptions({ queryKey, queryFn, initialPageParam, getNextPageParam })
}
export function useGetPetsInfiniteQuery(/* ... */) {
return useInfiniteQuery(getPetsInfiniteQueryOptions(/* ... */))
}infinite.queryParam
Name of the query parameter that holds the page cursor.
| Type | string |
| Required | false |
| Default | 'id' |
infinite.initialPageParam
Initial value for pageParam on the first fetch.
| Type | unknown |
| Required | false |
| Default | 0 |
infinite.nextParam
Path to the next-page cursor on the response, as dot notation ('pagination.next.id') or array form (['pagination', 'next', 'id']).
| Type | string | Array<string> | null |
| Required | false |
| Default | null |
infinite.previousParam
Path to the previous-page cursor on the response, in the same dot or array form.
| Type | string | Array<string> | null |
| Required | false |
| Default | null |
infinite.cursorParam
Deprecated path to the cursor field, read for both getNextPageParam and getPreviousPageParam when set. Use nextParam and previousParam instead.
| Type | string | null |
| Required | false |
| Default | null |
infinite.getNextPageParam
Source code for TanStack Query's getNextPageParam, copied into the generated code as written, such as '(lastPage) => (lastPage.hasNext ? lastPage.number + 1 : undefined)'. Use it when the next page must be computed instead of read from a field. Takes precedence over nextParam and cursorParam.
| Type | string | null |
| Required | false |
| Default | null |
Without getNextPageParam, nextParam or cursorParam, the composable counts pages up from initialPageParam until a page is an empty array. This works only for array responses, so generation warns when the response is an object.
infinite.getPreviousPageParam
Source code for TanStack Query's getPreviousPageParam, copied into the generated code as written. Takes precedence over previousParam and cursorParam.
| Type | string | null |
| Required | false |
| Default | null |
query
Decides which operations are treated as queries. The plugin generates a queryOptions factory for each match by default. Pass false to skip, or set hooks to also emit useQuery.
| Type | Partial<Query> | false |
| Required | false |
| Default | { methods: ['GET'], importPath: '@tanstack/vue-query' } |
query.methods
HTTP methods treated as queries. A matching operation generates a queryOptions factory instead of a mutation.
| Type | Array<string> |
| Required | false |
| Default | ['GET'] |
query.importPath
Module specifier for the generated import { queryOptions } from '...'.
| Type | string |
| Required | false |
| Default | '@tanstack/vue-query' |
queryKey
Builds the queryKey for each query composable. The callback receives the operation node, the active casing and the variant ('query' or 'infiniteQuery') and returns the key array. Strings are copied into the generated code as written, so wrap a string literal in JSON.stringify(...). The default adds infinite: true to infinite keys so they never share a cache entry with the plain query.
| Type | (props: { node, casing, variant }) => Array<unknown> |
| Required | false |
| Default | Built-in queryKeyTransformer |
queryKey: ({ node, variant }) => [JSON.stringify({ variant, operationId: node.operationId })]export const getUserByNameQueryKey = () => [{ variant: 'query', operationId: 'getUserByName' }] as constmutation
Decides which operations are treated as mutations. The plugin generates a mutationKey helper for each match by default. Pass false to skip, or set hooks to also emit useMutation.
| Type | Partial<Mutation> | false |
| Required | false |
| Default | { methods: ['POST', 'PUT', 'PATCH', 'DELETE'], importPath: '@tanstack/vue-query' } |
mutation.methods
HTTP methods treated as mutations. A matching operation generates mutation output instead of a query.
| Type | Array<string> |
| Required | false |
| Default | ['POST', 'PUT', 'PATCH', 'DELETE'] |
mutation.importPath
Module specifier for the generated import { useMutation } from '...', emitted when hooks is set.
| Type | string |
| Required | false |
| Default | '@tanstack/vue-query' |
mutationKey
Builds the mutationKey for each mutation composable, useful for batching invalidations. It takes the same props as queryKey with variant: 'mutation' and inlines strings the same way, so wrap literals in JSON.stringify(...).
| Type | (props: { node, casing, variant }) => Array<unknown> |
| Required | false |
| Default | Built-in mutationKeyTransformer |
hooks
Controls whether use* composables are emitted. The default false writes only the queryOptions, queryKey, and mutationKey factory helpers. Set true to also generate useQuery, useInfiniteQuery, and useMutation.
| Type | boolean |
| Required | false |
| Default | false |
resolver
Overrides generated file and symbol names. Omitted members keep resolverVueQuery. The shared members (name, file, imports) and the this context are described under resolver.
| Type | ResolverPatch<ResolverVueQuery> |
| Required | false |
type ResolverVueQueryPatch = {
// plus the shared name, file, and imports members
query?: {
name?(node: OperationNode): string
optionsName?(node: OperationNode): string
keyName?(node: OperationNode): string
keyTypeName?(node: OperationNode): string
clientName?(node: OperationNode): string
}
infiniteQuery?: { /* same members as query */ }
mutation?: {
name?(node: OperationNode): string
keyName?(node: OperationNode): string
typeName?(node: OperationNode): string
}
}