tRPC

T

tRPC

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

Join

Serving clients in another repository?

Would it be possible for tRPC to act as a server for clients in another repository and if so how would that work? 🙂

How to access hooks while initializating react query client for nextJS?

Usually when initialing react query client this happens in the react component scope. Considering we are not using SSR is quite useful to define global queryCache to handle errors or display toastr, etc. The way trpc initialize the react query client with nextJS using the createTRPCNext doesn't give the option to access/call any hooks. There is any other way to initialize trpc on NextJS that happens in the react component lifecycle as it would happen if we'are using only react query?...

How to execute mutation outside of react context?

Hi! I'm slowly converting code over to v10 - looks great! However, I ran in to an issue when using tRPC within my xstate state machine. I need to run a mutation in one of my states, and since this runs outside of react context, Alex had instructed for me to do the following in v9: 1. set the following property on window in _app.tsx ```...

When not to use tRPC?

Is there any scenario when building a mobile and/or a web app with backend that you would not recommend people to use tRPC? (We can assume that all the FE clients will be in the same repo) Are there any limitations / cons of using tRPC over using something like Fastify / Nestjs / Nextjs (without tRPC)?...

Bi directional infinite query example with prisma

I'm working on a project that is using this pattern, but my hasPreviousPages gets blown away when I go to the next page. Anyone have an idea what might be happening?

Websockets not sending data

Hi, I have a websocket route that doesn't seem to be sending any data I added a setInterval to test it but it doesn't seem to be working Version: 10.0.0-rc.1...

Query keys

Hi! I'm super new to TRPC and based on my understanding, TRPC has a thin wrapper around react query. So, I'm wondering how to include the query keys when using trpc. Thank you! ```ts...

Possible to use tRPC proxy client inside Edge Runtime?

Hi, im trying to fetch a route from trpc inside a Vercel Edge Runtime function. Therefore im trying to create a ProxyClient from @trpc/client and importing it in the Edge function: ```ts...

v10 migration using codemod

So I've been looking at the codemod that helps with transition towards v10 and I haven't been able to get it to work, my setup (simplified): ```md // the following structure is inside /server/trpc/src...

NextJS 13 compability.

Is trpc compatible with nextJS 13? Should we use the default SSR into server components?

SSR and loading indicators - I don't get it

Guess I'm missing something here, but unfortunately I'm having a hard time with the docs: in https://trpc.io/docs/v10/nextjs the example utils/trcp.ts sets ssr: true, but the pages/index.tsx example uses ``` const hello = trpc.hello.useQuery({ text: 'client' }); if (!hello.data) {...

Prefetch forEach

Hello, I'm trying to prefetch a list of procedures like this ```ts type QueryKeys = { // how to type this?...

Making input to trpc route from Prisma generated type

Hello everyone, I want to make my TRPC update route generic and type safe. I already have all prisma setup. Would it be possible for me to reuse prisma generated type as the input and converted it to zod object automatically? I am trying not to copy myself and make it dynamic for future changes Thanks!...

NextJs middleware broken by tRPC

Hi, I have a NextJs middleware that is redirecting to the login page. Basically an Auth guard over my all pages and apis but I have a problem with tRPC api routes. Whenever NextJs middleware pickup /api/trpc call and there is no session it tries to redirect to the login page breaking the redirect and trpc itself. Is there a way to get this working so redirect would actually work as expected?

How to infer the output of a mutation? The current methods appear to be depreciated.

I am attempting to export the bellow utility function to use client side to infer an output type that I can pass to a couple components that are consuming the data. It appears the the ''mutations' is depreciated here when trying to access it off the '_dep'? I did some digging the code base and that seems to be the case. Does anyone have advice on how to infer this type so I can pass it where it is needed?...

Trouble inferring the type of a very simple structure of nested routers

A very simple router results in an inference error, causing the client to not be able to infer the router type. I am using the proxy-beta.24 version along with typescript 4.9.1 `export const app_router = t.router({...

calling trpc endpoints from vanilla nextJs api routes

I'm struggling to find what's the best way to call a trpc endpoint directly from the server. Basically, I have a nextjs api endpoint where I want to call another endpoin that lives in trpc. would I need to create a trpcProxyClient? If so, would it have access to the context?...

Multiple React providers

Good morning! Is there any workaround, how to use multiple trpc-client instances with react-query? I wanted to share react-client between multiple instances, and I ended up with trpc calls to last-provided trpc address....

Mutation type issue

I'm trying to mutate something like this with tRPC and Prisma
const updateColumn = trpc.project.update.useMutation();
updateColumn.mutate({ colId: list.id, cards: list.cards })
const updateColumn = trpc.project.update.useMutation();
updateColumn.mutate({ colId: list.id, cards: list.cards })
...