Skip to content

Migration: @kubb/plugin-swr

Part of the v4 → v5 migration guide. For the full option reference, see @kubb/plugin-swr.

@kubb/plugin-swr follows the same conventions as the React Query and Vue Query plugins. resolver.name replaces transformers.name. The v4 transformers object held only name, so that is the whole rename. To rewrite generated nodes before printing, use the new macros option. The generators option is gone.

SWR has no enabled option. v5 drops the param-presence guard, so the hook keys off shouldFetch alone (useSWR(shouldFetch ? queryKey : null, ...)). Set shouldFetch to false to disable the request.

client is a selector, not an object

In v4 client was an object that carried the whole client config (dataReturnType, clientType, baseURL, bundle, importPath). In v5 it is a string that names a registered client plugin, and the hooks call that plugin instead of emitting their own. See Query and MCP plugins select a client for the shared rules, then register @kubb/plugin-axios or @kubb/plugin-fetch and point client at it.

typescript
import { defineConfig } from '@kubb/core'
import { pluginSwr } from '@kubb/plugin-swr'

export default defineConfig({
  plugins: [
    pluginSwr({
      client: { client: 'axios', dataReturnType: 'data', baseURL: 'https://api.example.com' },
    }),
  ],
})
typescript
import { defineConfig } from 'kubb/config'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginAxios } from '@kubb/plugin-axios'
import { pluginSwr } from '@kubb/plugin-swr'

export default defineConfig({
  plugins: [
    pluginTs(),
    pluginAxios({ baseURL: 'https://api.example.com' }),
    pluginSwr({ client: 'axios' }),
  ],
})

Removed: parser

As on React Query, the parser option is gone; set validator: 'zod' on the client plugin (pluginAxios/pluginFetch) instead.

Removed: mutation.paramsToTrigger

v4 gated the trigger-based mutation shape behind mutation.paramsToTrigger, off by default. v5 removes the flag and makes that shape the default, so mutation parameters always pass through trigger().

Diff
diff
  pluginSwr({
   mutation: { paramsToTrigger: true },
  })

Removed: paramsType, pathParamsType, paramsCasing

Same grouped-options change as React Query: each hook takes one { path, query, body, headers } object (property names from the @kubb/plugin-ts *Options type). The mutation form passes it through trigger():

v5 call site
typescript
useFindPets({ query: { status: 'available' } })
useGetPet({ path: { petId } })
useUpdatePet().trigger({ path: { petId }, body: pet })