---
url: /plugins/plugin-vue-query.md
description: >-
  Generates TanStack Query composables for Vue from your OpenAPI spec, so every
  read and write is a typed useQuery, useInfiniteQuery, or useMutation.
---

# @kubb/plugin-vue-query

`@kubb/plugin-vue-query` turns each OpenAPI operation into a [TanStack Query](https://tanstack.com/query) composable for Vue. Read operations become `useFoo`, with an optional `useFooInfinite` variant, and write operations become `useFoo` mutations. Every composable is typed: query keys, input variables, response data, and error shape all come from the spec.

The composables call an HTTP client, so a client plugin must be registered: add `@kubb/plugin-ts` for the types and either `@kubb/plugin-axios` or `@kubb/plugin-fetch` for the client.

Each composable takes its parameters as a single grouped options object shaped as `{ body, path, query, headers }`, with camelCase property names. The request still sends the original parameter names from the spec, and Kubb writes that mapping for you.

## Installation

::: code-group

```shell [bun]
bun add -d @kubb/plugin-vue-query
```

```shell [pnpm]
pnpm add -D @kubb/plugin-vue-query
```

```shell [npm]
npm install --save-dev @kubb/plugin-vue-query
```

```shell [yarn]
yarn add -D @kubb/plugin-vue-query
```

:::

## Dependencies

This plugin needs these plugins in your config:

* [`@kubb/plugin-ts`](/plugins/plugin-ts/) for the types.
* A client plugin, [`@kubb/plugin-axios`](/plugins/plugin-axios/) or [`@kubb/plugin-fetch`](/plugins/plugin-fetch/), for the HTTP layer. The composables call its functions, so generation errors out when no client plugin is registered.

> \[!IMPORTANT]
> The generated composables need `@tanstack/vue-query` v5 or higher.

For runtime validation, set `validator` on the client plugin. The generated operations carry the validation, so the composables get it for free.

## Example

::: code-group

```typescript twoslash [kubb.config.ts]
import { defineConfig } from 'kubb'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginAxios } from '@kubb/plugin-axios'
import { pluginVueQuery } from '@kubb/plugin-vue-query'

export default defineConfig({
  input: './petStore.yaml',
  output: { path: './src/gen' },
  plugins: [
    pluginTs(),
    pluginAxios(),
    pluginVueQuery({
      output: { path: './hooks', mode: 'directory' },
      group: {
        type: 'tag',
        name: ({ group }) => `${group}Hooks`,
      },
      client: 'axios',
      mutation: { methods: ['POST', 'PUT', 'DELETE'] },
      infinite: {
        queryParam: 'next_page',
        initialPageParam: 0,
        nextParam: 'pagination.next.cursor',
      },
      query: {
        methods: ['GET'],
        importPath: '@tanstack/vue-query',
      },
    }),
  ],
})
```

:::

## See also

* [TanStack Query for Vue](https://tanstack.com/query/latest/docs/framework/vue/overview)
* [Changelog](https://github.com/kubb-labs/plugins/blob/main/packages/plugin-vue-query/CHANGELOG.md)
