Thin TanStack Vue Query helpers built on openapi-fetch. Fully type-safe queries and mutations derived from your OpenAPI schema.
pnpm add @koyori-app/openapi-vue-query openapi-fetch @tanstack/vue-queryvue, @tanstack/vue-query, openapi-fetch, and openapi-typescript-helpers are peer dependencies. Generate your paths types with openapi-typescript.
Create a typed fetch client, wrap it once, and reuse the returned client anywhere:
// api.ts
import createFetchClient from "openapi-fetch";
import { createClient } from "@koyori-app/openapi-vue-query";
import type { paths } from "./my-openapi"; // generated by openapi-typescript
const fetchClient = createFetchClient<paths>({ baseUrl: "https://api.example.com" });
export const $api = createClient(fetchClient);<script setup lang="ts">
import { $api } from "./api";
// Query — path/method/params are all type-checked against the schema.
const { data, isLoading, error } = $api.useQuery("get", "/pets/{petId}", {
params: { path: { petId: 1 } },
});
// Mutation
const createPet = $api.useMutation("post", "/pets");
</script>createClient(fetchClient)— wrap anopenapi-fetchclient and return the helpers below.queryOptions(method, path, init?, options?)— build options foruseQuery/prefetchQuery.useQuery(method, path, init?, options?, queryClient?)useSuspenseQuery(method, path, init?, options?, queryClient?)— alias foruseQuery; wrap the component in<Suspense>(Vue Query v5 has no dedicated suspense query).useInfiniteQuery(method, path, init, options, pageParamName?, queryClient?)useMutation(method, path, options?, queryClient?)createQueryKey(method, path, init?)— produce the[method, path, init]query key directly.OpenApiVueQueryError— error thrown when anopenapi-fetchrequest fails.
- Query keys follow
[method, path, init], matching the documentedopenapi-react-queryshape. - Errors from
openapi-fetchare re-thrown asOpenApiVueQueryError, so Vue Query callers can rely on thrown errors. - The package is intentionally a thin wrapper and keeps
openapi-fetchas the source of request typing.
A clean-room implementation modeled on the public API shape of the following projects (no source code was copied). Thanks for the excellent design.
openapi-react-query— © Martin Paucot, MIT License. The source of the[method, path, init]query key and hooks API shape.openapi-fetch/openapi-typescript— © Drew Powers and contributors, MIT License. The request-typing foundation.