tRPC

T

tRPC

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

Join

Am I the only one struggling with pnpm + TypeScript monorepo + trpc?

Hello all, When using pnpm in a TypeScript monorepo without node-linker, I hit those errors: ```...

tRPC standalone server in monorepo

Hi, I'm using t3-stack monorepo as my base and I've swapped out NextJS backend for standalone HTTP server but I just can't get it work Discord wouldn't let me post the code as it was too long so I've uploaded the api.ts and client.ts along with the error to gist https://gist.github.com/neo773/7c8a314785d5e4f54c724cde7e5fa65c...

Codemod to v10 is not modifying any file

Hello 👋, I must be super dumb but running pnpm dlx trpc-v10-migrate-codemod in my project isn't applying any change. I see all the files listed as "migrated" but nothing is saved on disk?...

No overload matches this call when outputting unions

Hello there 👋, I have this simple procedure (we're not fully migrated on v10 yet, using interop): ```ts...

[help] Uncaught (in promise) TRPCClientError: Property description must be an object: u

After building on linux, I visit the site. And Chrome console shows this error. But if I build on my Mac, It is ok and no error. My site's first request ( like trpc.checklogin) is ok before loaded. But if the site loaded , and I make a request like the first image, it reproduces, and no chrome network log. So It is nothing with server....

How can I make tRPC+NextJs APIs faster? (db and functions region is already same)

Hi, I have migrated my website backend (https://clubofcoders.com) from NestJs + Prisma + Cloud Run to tRPC + Prisma + NextJs serverless functions. But I am not quite happy with the performance (screenshot is attached). The requests are taking up to five sec on first loads and 2/3 secs. afterward; I am using the same region for serverless functions and the database (planetscale). Hosted on vercel. Any ideas I can improve this?...

Superjson "undefined"

When returning a list from the db with a ton of potential undefined fields, superjson just crams a ton of undefined's in meta: Actual data: 1711 lines, Data + Meta: 3028 lines. ...

Throwing fastify errors when using fastify adapter

Hello, I'm using fastifyTRPCPlugin from @trpc/server/adapters/fastify and trying to throw errors correctly. I usually use @fastify-sensible because I find the API clear, e.g. I can write things like fastify.httpErrors.forbidden() or fastify.httpErrors.unauthorized. However if I throw one of these in a tRPC procedure it seems the error code is always 500, assuming that's because tRPC is intercepting/handling them in some way? What's the best way to "solve" this? Thanks!...

Confused about createProxySSGHelpers

If you can use this helper inside of getServerSideProps without having ssr: true what is the difference when you do enable ssr and forward headers to the server from the client?

How to check if data is being prefetched?

What is a method to check if ssg prefetching actually occurs? Through the network tab?

How can I access ctx from inside of a procedure?

``` const appRouter = t.router({ helloTab: t.procedure.input(z.object({ url: z.string().url() })).mutation(async ({ input, ctx }) => { //@ts-ignore const tab = ctx.sender.tab...

Async User Call in `createContext` (context.ts) or in `isAuthed` (in trpc.ts)

Hi all! Should I be getting the user in all requests via createContext in the following async call
const { user } = await supabaseAdmin.auth.api.getUserByCookie(opts.req)
const { user } = await supabaseAdmin.auth.api.getUserByCookie(opts.req)
Or would it be more sensible for this to only be called in certain procedures such as middleware like isAuthed? In theory, I don't want public API calls being slower because of the delay it takes to fetch the user....

'req' of undefined in onError of express middleware

I've recently noticed that I get a bunch of errors regarding req object missing in ctx for onError property in trpc express middleware. Can't figure out how req obj might be undefined at the point of onerror handler?? ```js app.use( '/trpc',...

Mutations and Queries in React Contexts causing unexpected behaviors

In my organization, we recently moved to put all of our mutations/queries into React Contexts and out of components (NextJS with React 18). I am now seeing requests and debouncing behaviors that used to work no longer work.
In some cases it appears we now have race conditions as loading/success are not necessarily being handled, but in other cases we're not getting reactivity from mutations that are in contexts Anyone else have experience or tips re: throwing tRPC stuff into React Contexts?...

Custom error management

Hey peeps! I could've sworn I created a GitHub issue about this, but I must've been dreaming, because I cannot find it. Anyway, it's support-related, so I figured it's better to ask here! I have a large application that has a traditional client/server API and I use Axios to make calls to the server. Now, I'm investigating replacing that with tRPC (because it feels like an amazing developer experience and will quicken development). I have a rather "sophisticated" error management in the application. I have my own custom ApplicationError, which has an errorCode and a custom data object with additional information about the error. Any server-side code in the application can throw this error. A middleware catches this and converts it to a 400 Bad Request with an appropriate JSON response body. In the client, I also have my custom wrapper on top of Axios, that simply catches 400 Bad Request, and converts the JSON back to an ApplicationError and simply throws it. This means that I can easily catch ApplicationError in my client side code, just as if it was originally thrown on the client....

How can I generate trpc Generic Types?

I am building a trpc library, and as part of my implementation, I need the generic types of t, t.mergeRouters, t.procedure, t.router and t.middleware. I've haven't been able to locate those generic types in the @trpc/server and since trpc has such a complex type structure, would love to see an implementation for a generic set of types for the ones listed about....

context question

Why are the context examples only showing opinionated examples with next/react auth ? Also i find it very confusing that it is not mentioned in the docs what kind of arguments the context function is called with.

async middleware

is it possible to define an async middleware? I want to do something like this but it throws errors when i start the server const dbMiddleware = middleware(async ({ path, ctx, next, input }) => { ...

errorFormatter ignored when using appRouter.createCaller

My errorFormatter works correctly in the actual application using an adapter, e.g. ``` trpcExpress.createExpressMiddleware({ router: appRouter, createContext: createTRPCContextFromExpress, }),...