Skip to content
Vue Query

Vue Query

Officialv5.3.2

@kubb/plugin-vue-query

kubb add plugin-vue-query

Options

Pass these options to pluginVueQuery(). Shared options link to Shared plugin options for details.

Options overview

OptionPurposeDefault
outputWhere files are written: path, mode, barrel, banner, footer.{ path: 'hooks', barrel: { type: 'named' } }
groupSplit output by tag or path: type, name.None
clientWhich registered client plugin the composables call.Auto-detected
infiniteAdd useInfiniteQuery composables for paginated reads.false
queryConfigure or disable query composables.{ methods: ['GET'], importPath: '@tanstack/vue-query' }
queryKeyBuild the queryKey for each query composable.Built-in queryKeyTransformer
mutationConfigure or disable mutation composables.{ methods: ['POST', 'PUT', 'PATCH', 'DELETE'], importPath: '@tanstack/vue-query' }
mutationKeyBuild the mutationKey for each mutation composable.Built-in mutationKeyTransformer
hooksEmit use* composables on top of the factory helpers.false
includeKeep only operations that match.None
excludeSkip operations that match.[]
overrideApply different options per pattern.[]
resolverCustomize generated names and file paths.resolverVueQuery
macrosRewrite 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'
Requiredfalse
'fetch'
Calls the operations generated by @kubb/plugin-fetch.
'axios'
Calls the operations generated by @kubb/plugin-axios.

infinite

Adds infiniteQueryOptions and useInfiniteQuery for operations that declare the query parameter named in infinite.queryParam. Needs hooks: true.

TypePartial<Infinite> | false
Requiredfalse
Defaultfalse
infinite: {}, hooks: true
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.

Typestring
Requiredfalse
Default'id'

infinite.initialPageParam

Initial value for pageParam on the first fetch.

Typeunknown
Requiredfalse
Default0

infinite.nextParam

Path to the next-page cursor on the response, as dot notation ('pagination.next.id') or array form (['pagination', 'next', 'id']).

Typestring | Array<string> | null
Requiredfalse
Defaultnull

infinite.previousParam

Path to the previous-page cursor on the response, in the same dot or array form.

Typestring | Array<string> | null
Requiredfalse
Defaultnull

infinite.cursorParam

Deprecated path to the cursor field, read for both getNextPageParam and getPreviousPageParam when set. Use nextParam and previousParam instead.

Typestring | null
Requiredfalse
Defaultnull

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.

Typestring | null
Requiredfalse
Defaultnull

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.

Typestring | null
Requiredfalse
Defaultnull

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.

TypePartial<Query> | false
Requiredfalse
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.

TypeArray<string>
Requiredfalse
Default['GET']

query.importPath

Module specifier for the generated import { queryOptions } from '...'.

Typestring
Requiredfalse
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>
Requiredfalse
DefaultBuilt-in queryKeyTransformer
queryKey: ({ node, variant }) => [JSON.stringify({ variant, operationId: node.operationId })]

mutation

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.

TypePartial<Mutation> | false
Requiredfalse
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.

TypeArray<string>
Requiredfalse
Default['POST', 'PUT', 'PATCH', 'DELETE']

mutation.importPath

Module specifier for the generated import { useMutation } from '...', emitted when hooks is set.

Typestring
Requiredfalse
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>
Requiredfalse
DefaultBuilt-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.

Typeboolean
Requiredfalse
Defaultfalse

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.

TypeResolverPatch<ResolverVueQuery>
Requiredfalse
Partial override
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
  }
}