Beta You're reading the docs for Kubb v5, which is currently in beta. View the stable v4 docs
Skip to content
Official v5.0.0-beta.85 MIT kubb >=5.0.0 node >=22

@kubb/plugin-vue-query

Generates TanStack Query composables for Vue from your OpenAPI spec, so every read and write is a typed useQuery, useInfiniteQuery, or useMutation.

vue-querytanstack-queryvuecomposablesdata-fetchingcodegenopenapi
Downloads
30.8k / mo
Stars
3
Bundle size
426.0 kB
Updated
2d ago

@kubb/plugin-vue-query

@kubb/plugin-vue-query turns each OpenAPI operation into a TanStack Query composable for Vue. Read operations become useFoo, with an optional useFooInfinite variant. 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. Generation errors out when no client plugin is present.

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

shell
bun add -d @kubb/plugin-vue-query@beta
shell
pnpm add -D @kubb/plugin-vue-query@beta
shell
npm install --save-dev @kubb/plugin-vue-query@beta
shell
yarn add -D @kubb/plugin-vue-query@beta

Dependencies

This plugin needs these plugins in your config:

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

Example

typescript
import {  } from 'kubb'
import {  } from '@kubb/plugin-ts'
import {  } from '@kubb/plugin-axios'
import {  } from '@kubb/plugin-vue-query'

export default ({
  : { : './petStore.yaml' },
  : { : './src/gen' },
  : [
    (),
    (),
    ({
      : { : './hooks' },
      : {
        : 'tag',
        : ({  }) => `${}Hooks`,
      },
      : 'axios',
      : { : ['POST', 'PUT', 'DELETE'] },
      : {
        : 'next_page',
        : 0,
        : 'pagination.next.cursor',
      },
      : {
        : ['GET'],
        : '@tanstack/vue-query',
      },
    }),
  ],
})

See also