tRPC

T

tRPC

Move Fast & Break Nothing. End-to-end typesafe APIs made easy.

Join

how to persist the query client?

I want to persist the trpc query client cache, but don't want to create a new query client, I want to use the one trpc already creates. Is this doable?...

How to infer type of a nested object from app router output?

I have a tRPC router than returns a nested object through a db query. It looks like this: ```ts ILessonCommentProps.comments: ({ _count: {...

What's the type of errorFormatter parameter

I wanna know how could i get the type of the errorFormatter parameter, so i can move the errorFormatter logic to another file. Environment: Node v18.15.0...

tRPC works only for monoliths environment?

How can I works if typesafe in real time with a remote server? 🤔

How to use createCaller() with lambda for testing?

Has anyone successfully mocked a trpc caller that uses the AWS Lambda integration? trying to write some unit tests

is there a way to call useQuery() from a callback and get the return value within that callback?

I have a generic component that is effectively an autocomplete that fills in options from a web request. The component takes a callback which takes in the newest search string and should perform a web request to get the autocomplete options and return them. Is there a way I can call a trpc useQuery() and get the return value within this async callback? Thanks.

Using Response with the Next App Router

The route handlers in the App Router, only receive the Request object, requiring you to use a Response to set stuff onto the response like status, cookies, etc. Previously, we were able to pipe the req and res into the context. My question is: what's the new practice for returning data AND setting the status (or cookies) when within a tRPC router (that's nested using the fetch adapter) in the new Next App Router?...

The only way to access useQuery options without input is passing undefined to it?

Is there any other way? seems strange pass undefined to the input query

How can I access the trpc context in zod's refine function?

To do something like ```ts create: myProcedure .input(myInputSchema.refine(async ({ slug }, ctx) => slugDoesNotAlreadyExist(ctx.db, slug),...

Set Request Headers for individual requests?

Hello everyone, I have a simple question, can you somehow add headers to the individual requests instead of doing it once during setup of the tRPC? I would like to have custom per request header that I cannot know ahead of time.

Get undefined when the refetch function has successfully worked

In my use case, I first disabled the useQuery function because I want it only fetch when I want to. And by triggering the refetch, I can see in the browser console showing that my request succeeded by when I want to use the returned data which destructured from the useQuery , it shows undefined. I don't know why this happened. ```javascript await refetchDocument(); if (fetchDocumentError) throw fetchDocumentError; console.log("existingDocument");...
Solution:
I think the proper way of doing my expectation is to use useMutation

Having trouble to import my AppRouter in my react client

Environment: Node v18.15.0 I created my TRPC router in my express app and exported it how -documentation says, but when i try to import it from my react client, i get this ...
Solution:
forget it it was the @trpc/server version 💀

Argument of Type not assignable

Seeing the following error while trying to establish a connection with the trpc server from the client: Does anyone know the reason behind this...

Can't I create multiple TRPC React using same Router?

Im using monorepo and have 2 client projects on that. I have 2 files that does the same, create the instance of the trpc using the same router from the server. I dont know why but in one file Im getting error...

Types with enabled: false

How do types work with enabled: false? Do I need to cast my arguments in the cases where enabled is false, or is there some intelligence here from the types?

Error: No QueryClient set, use QueryClientProvider to set one

Hello! I have wrapped my _app.tsx properly and I have made useQuery functionality possible, however on this specific component it just won't work. pages/room/[slug].tsx: ```...

You're trying to use @trpc/server in a non-server environment

Environment: Node v18.15.0, yarn, Next 13.2.4 What's wrong: When using createServerSideHelpers, i got this error: ```...
No description

TRPC Middleware w/ Input

Hello! I was wondering if there is a way to add input fields onto a TRPC middleware. Essentially I would like a token field to be required on any inputs through the procedure that uses this middleware. How would I go about this? Thanks!...

Server side headers are not applied

Hi guys I have the following trpc client initialized ``` import { createTRPCProxyClient, httpBatchLink } from '@trpc/client'; import type { AppRouter } from '../../../api/src/trpc'; import { get } from 'js-cookie';...

Get tRPC procedure latency?

Hi all, is there a supported mechanism to run common code to all procedures, say if I want to get latency metrics. I want to run the same latency math on all my procedures. I could create a helper function that I just have to remember to wrap all my procedure code in but just wondering if there's some supported tRPC way of doing this?
Solution:
What about middleware