oRPC
background

Vue Query

Simplify Vue Query usage with minimal integration using ORPC and TanStack Query

Installation

npm install @orpc/client @orpc/vue-query @tanstack/vue-query

Setup

import {  } from '@orpc/vue-query';
import {  } from '@orpc/client';
import type {  } from 'examples/server';
 
// Create an ORPC client
export const  = <typeof >({
  : 'http://localhost:3000/api',
});
 
// Create Vue Query utilities for ORPC
export const  = ();
 
..
  • infiniteOptions
  • key
  • mutationOptions
  • queryOptions

Multiple ORPC Instances

To prevent conflicts when using multiple ORPC instances, you can provide a unique base path to createORPCVueQueryUtils.

import {  } from '@orpc/vue-query'
 
// Create separate ORPC instances with unique base paths
const  = ('fake-client' as any, ['__user-api__'])
const  = ('fake-client' as any, ['__post-api__'])

This ensures that each instance manages its own set of query keys and avoids any conflicts.

Usage

Standard Queries and Mutations

import { , ,  } from '@tanstack/vue-query'
import {  } from 'examples/vue-query'
 
// Fetch data
const { :  } = (..({ : { : 'unnoq' } }))
 
// Perform mutations
const { :  } = (...())
 
// Invalidate queries
const  = ()
.({ : .() }) // Invalidate all queries
.({ : ...({ : { : 'example' } }) }) // Specific queries

Note: This library enhances TanStack Query by managing query keys and functions for you, providing a seamless developer experience.

Infinite Queries

Infinite queries require a cursor in the input field for pagination.

import {  } from '@orpc/server';
import {  } from 'zod';
import {  } from '@orpc/vue-query';
import {  } from '@tanstack/vue-query';
 
const  = {
  : {
    : 
      .(.({ : .(), : .() }))
      .(() => ({
        : . + .,
        : [], // Fetch your actual data here
      })),
  },
};
 
const  = <typeof >('fake-client' as any);
 
const  = (
  ...({
    : { : 10 },
    : () => .,
    : 0,
  })
);
 
.(..);

On this page