tRPC

T

tRPC

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

Join

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 })
...

Can I redirect the user from inside my router?

I have a query protectedProcedure, which returns an object from my prisma planetscale db What's the best way to redirect the user to a 404 page if the item doesn't exist on the db? I wanted something like res.redirect("/404") but can't seem to find a way to do it Should I just handle it in the front-end with a useEffect?...

Which http library trpc uses in the frontend?

I was wondering iftrpc uses the Fetch API or uses something like Axios to do API calls from the frontend. I recently added supertokens to an app and I need to add a middleware for session refreshment depending on the tool I'd be using

useQueryClient is not working as expected

So before v10 I was simply using useQueryClient and had my queryClient strongly typed. Now I moved to v10 and for some reason, the documentation says that the queryClient was removed from the context so I should use the useQueryClient hook directly from @tanstack but if I do so then the queryClient returned by that hook is not the queryClient trpc is using, it's just empty. I made it work by using the trpc.useContext hook coming from my client utils but I definitely think that the docs a...

Infer the type of ctx for a specific procedure

Let's say I had a helper function that I wanted to pass the context to, I can't use the default Context type, because this helper is only used for procedures that add things to the context. Is it possible to infer the type of the context after a specific procedure runs?

CORS in standalone server

Hi, I'm trying to get CORS working in standalone server. Attempted this solution but unfortunately it no longer works with v10 https://github.com/trpc/trpc/issues/623...

Test example for react-testing-library

Does trpc has any example of doing tests with react-testing-library? We need to wrap the app using trpc.withTRPC. The docs doesn't have a section refering to test, just an example of using context inner, but that also doesn't work in case we actually need to have the req or the res in the context (in NextJS context), for example, to set cookies, etc. Would be welcome to add a section about testing and how to wrap components with react testing library and actually run tests where we actually need the next req, res in the context? (It might not be necessary to have the entire req,res in the context but utility to set cookies in the response to handle auth, for example, etc)...

Queries break when in production on Vercel; work on localhost

The query is called like this: ```javascript const { data } = api.useQuery(["user.!getCount"], { refetchInterval: interval * 1000, onSuccess: () => ......

Can't get client to work

Hi, I can't get my client to work I'm using Next.js but I have also tried the React method from the docs. mutations and query property is missing....