diff --git a/README.md b/README.md index 03e9bde..54ef5e4 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,43 @@ const { }) ``` +## Options + +trpc-nuxt accepts the following options exposed under `~/server/trpc.index.ts`: + +```ts +import * as trpc from '@trpc/server' +import type { inferAsyncReturnType } from '@trpc/server' +import type { CompatibilityEvent } from 'h3' +import type { OnErrorPayload } from 'trpc-nuxt/api' + +export const router = trpc.router>() + +// Optional +// https://trpc.io/docs/context +export const createContext = (event: CompatibilityEvent) => { + // ... + return { + /** context data */ + } +} + +// Optional +// https://trpc.io/docs/caching#using-responsemeta--to-cache-responses +export const responseMeta = () => { + // ... + return { + // { headers: ... } + } +} + +// Optional +// https://trpc.io/docs/error-handling#handling-errors +export const onError = (payload: OnErrorPayload) => { + // Do whatever here like send to bug reporting and stuff +} +``` + ## Recipes - [Validation](/recipes/validation.md) diff --git a/src/runtime/client.ts b/src/runtime/client.ts index 742e680..d7f5551 100644 --- a/src/runtime/client.ts +++ b/src/runtime/client.ts @@ -49,6 +49,7 @@ export async function useAsyncQuery< options, ) + // @ts-expect-error: Resolved by Nuxt if (process.server && error.value && !serverError.value) serverError.value = error.value as any