Gathering detailed insights and metrics for @colonel-sandvich/trpc-vue-query
Gathering detailed insights and metrics for @colonel-sandvich/trpc-vue-query
Gathering detailed insights and metrics for @colonel-sandvich/trpc-vue-query
Gathering detailed insights and metrics for @colonel-sandvich/trpc-vue-query
npm install @colonel-sandvich/trpc-vue-query
Typescript
Module System
Node Version
NPM Version
55.5
Supply Chain
95.6
Quality
76.6
Maintenance
100
Vulnerability
99.6
License
@colonel-sandvich/trpc-vue-query@0.8.0
Updated on Mar 05, 2025
@colonel-sandvich/trpc-vue-query@0.7.0
Updated on Apr 26, 2024
@colonel-sandvich/trpc-vue-query@0.6.1
Updated on Mar 23, 2024
@colonel-sandvich/trpc-vue-query@0.6.0
Updated on Mar 23, 2024
@colonel-sandvich/trpc-vue-query@0.5.0
Updated on Mar 18, 2024
@colonel-sandvich/trpc-vue-query@0.4.1
Updated on Mar 16, 2024
TypeScript (100%)
Total Downloads
6,752
Last Day
4
Last Week
20
Last Month
122
Last Year
1,618
MIT License
29 Stars
78 Commits
1 Watchers
2 Branches
1 Contributors
Updated on Jul 03, 2025
Minified
Minified + Gzipped
Latest Version
0.8.0
Package Id
@colonel-sandvich/trpc-vue-query@0.8.0
Unpacked Size
49.34 kB
Size
13.39 kB
File Count
37
NPM Version
10.8.2
Node Version
20.18.3
Published on
Mar 05, 2025
Cumulative downloads
Total Downloads
Last Day
100%
4
Compared to previous day
Last Week
-67.2%
20
Compared to previous week
Last Month
-10.3%
122
Compared to previous month
Last Year
-68.5%
1,618
Compared to previous year
A simple package to bridge the gap between TRPC and TanStack Query for Vue much like how TRPC has their own in-house React Query Integration
If you're using @tanstack/vue-query then you might know that working with query keys and query functions can sometimes become cumbersome. A lead maintainer of Tanstack Query, TkDodo, has said that "Separating QueryKey from QueryFunction was a mistake".
So this package tightly couples your keys and functions leading to brilliant DX :rocket:
1const currentUserQuery = queryOptions({ 2 queryKey: ["user", "current"], 3 queryFn: () => trpc.user.current.query(), 4}); 5 6const { data } = useQuery(currentUserQuery); 7 8const { mutateAsync } = useMutation({ 9 mutationFn: (input: UnwrapRef<typeof form>) => trpc.user.signUp.mutate(input), 10 onSuccess: async () => { 11 await useQueryClient().invalidateQueries({ 12 queryKey: currentUserQuery.queryKey, 13 }); 14 await navigateTo("/onboarding"); 15 }, 16});
1const { data } = useClient().user.current.useQuery(); 2 3const { mutateAsync } = useClient().user.signUp.useMutation({ 4 onSuccess: async () => { 5 await useClient().user.current.invalidate(); 6 await navigateTo("/onboarding"); 7 }, 8});
pnpm i @colonel-sandvich/trpc-vue-query
1// main.ts 2import { TrpcVueQueryPlugin } from "@colonel-sandvich/trpc-vue-query"; 3import { VueQueryPlugin } from "@tanstack/vue-query"; 4import { httpBatchLink } from "@trpc/client"; 5import { createApp } from "vue"; 6import App from "./src/App.vue"; 7import { trpc } from "your-path-to-trpc-client"; 8// ^ See https://trpc.io/docs/client/vanilla/setup#3-initialize-the-trpc-client 9 10export const app = createApp(App); 11 12app 13 .use(VueQueryPlugin) // Make sure {@tanstack/vue-query}'s plugin goes first 14 .use(TrpcVueQueryPlugin, { 15 trpcClient: trpc, 16 }) 17 .mount("#app");
1// src/composables/useClient.ts 2import { TrpcVueClient, clientKey } from "@colonel-sandvich/trpc-vue-query"; 3import { inject } from "vue"; 4import type { AppRouter } from "your-path-to-trpc-app-router-type"; 5 6export function useClient() { 7 return inject(clientKey) as TrpcVueClient<AppRouter>; 8}
@tanstack/vue-query
for Nuxt if you haven't already1// src/plugins/01.vueQueryPlugin.ts 2 3// Important that this plugin comes before the `02.clientPlugin` since that has this plugin as a dependency 4export default defineNuxtPlugin((nuxt) => { 5 nuxt.vueApp.use(VueQueryPlugin); 6 7 // Below is for SSR. Remove if you don't need this 8 // Provided from TanStack Query docs: https://tanstack.com/query/v5/docs/vue/guides/ssr 9 const vueQueryState = useState<DehydratedState | null>("vue-query"); 10 11 if (process.server) { 12 nuxt.hooks.hook("app:rendered", () => { 13 vueQueryState.value = dehydrate(queryClient); 14 }); 15 } 16 17 if (process.client) { 18 nuxt.hooks.hook("app:created", () => { 19 hydrate(queryClient, vueQueryState.value); 20 }); 21 } 22});
1// src/plugins/02.clientPlugin.ts 2 3export default defineNuxtPlugin(() => { 4 const trpc = createTRPCProxyClient<AppRouter>({ 5 links: [ 6 httpBatchLink({ 7 url: "/api/trpc", 8 headers: useRequestHeaders(), 9 fetch: customFetchWrapper(), // Crucial for SSR 10 }), 11 ], 12 }); 13 14 const client = createTrpcVueClient(trpc, useQueryClient()); 15 16 return { 17 provide: { 18 client, 19 }, 20 }; 21});
1// src/composables/useClient.ts 2 3export const useClient = () => { 4 return useNuxtApp().$client; 5};
Go check out /examples
to see some basic uses.
examples/vue-minimal
pnpm i
Anywhere
cd examples/vue-minimal
pnpm dev
If ports 3000 (client) and 3001 (server) are available then you should up and running
Please please please absolutely make an issue or PR for any bugs or feature requests, I highly encourage it.
Big thanks to Robert Soriano for his trpc-nuxt package that inspired this package.
No vulnerabilities found.
No security vulnerabilities found.