Skip to content

Pinia Colada Integration

Pinia Colada is the data fetching layer for Pinia and Vue. oRPC's integration with Pinia Colada is lightweight and straightforward - there's no extra overhead.

WARNING

This documentation assumes you are already familiar with Pinia Colada. If you need a refresher, please review the official Pinia Colada documentation before proceeding.

WARNING

Pinia Colada is still in an unstable stage. As a result, this integration may introduce breaking changes in the future to keep up with its ongoing development.

Installation

sh
npm install @orpc/vue-colada@latest @pinia/colada@latest
sh
yarn add @orpc/vue-colada@latest @pinia/colada@latest
sh
pnpm add @orpc/vue-colada@latest @pinia/colada@latest
sh
bun add @orpc/vue-colada@latest @pinia/colada@latest
sh
deno add npm:@orpc/vue-colada@latest npm:@pinia/colada@latest

Setup

Before you begin, ensure you have already configured a server-side client or a client-side client.

ts
import {  } from '@orpc/vue-colada'

export const  = ()

...({ : { : 123 } })

//

Avoiding Query/Mutation Key Conflicts

Prevent key conflicts by passing a unique base key when creating your utils:

ts
const userORPC = createORPCVueColadaUtils(userClient, {
  path: ['user']
})
const postORPC = createORPCVueColadaUtils(postClient, {
  path: ['post']
})

Query Options Utility

Use .queryOptions to configure queries. Use it with hooks like useQuery, useSuspenseQuery, or prefetchQuery.

ts
const  = (...({
  : { : 123 }, // Specify input if needed
  : { : true }, // Provide client context if needed
  // additional options...
}))

Mutation Options

Use .mutationOptions to create options for mutations. Use it with hooks like useMutation.

ts
const  = (...({
  : { : true }, // Provide client context if needed
  // additional options...
}))

.({ : 'Earth' })

Query/Mutation Key

Use .key to generate a QueryKey or MutationKey. This is useful for tasks such as revalidating queries, checking mutation status, etc.

ts
const  = ()

// Invalidate all planet queries
.({
  : ..(),
})

// Invalidate the planet find query with id 123
.({
  : ...({ : { : 123 } })
})

Calling Procedure Clients

Use .call to call a procedure client directly. It's an alias for corresponding procedure client.

ts
const result = orpc.planet.find.call({ id: 123 })

Error Handling

Easily manage type-safe errors using our built-in isDefinedError helper.

ts
import { isDefinedError } from '@orpc/client'

const mutation = useMutation(orpc.planet.create.mutationOptions({
  onError: (error) => {
    if (isDefinedError(error)) {
      // Handle the error here
    }
  },
}))

mutation.mutate({ name: 'Earth' })

if (mutation.error.value && isDefinedError(mutation.error.value)) {
  // Handle the error here
}

For more details, see our type-safe error handling guide.

Released under the MIT License.