tRPC

T

tRPC

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

Join

Right way to catch all unexpected errors before they reach the user

Hi, I was wondering, what's the right way to catch all unexpected errors (like db errors) and replace them with simple "Internal Server Error" erros, before they get to the user. Is it possible to achieve this via middleware?

tRPC sockets with react

Trying to make my React app work with socket with minimal server but getting error: "Uncaught TypeError: Cannot destructure property 'client' of 'useContext(...)' as it is null." at Object.useSubscription (createHooksInternal-9c1f8ad9.mjs:363:17) at createHooksInternal-9c1f8ad9.mjs:57:29...

Using `fetchRequestHandler` with other routes?

Hey everyone, I'm trying to use the fetchRequestHandler with a HatTip server, but all the examples seem to give tRPC entire control of all server responses. I actually want to serve other things besides tRPC routes. Anyone know how I could go about this? So far I've tried this, as well as changing the endpoint to "/" and "". Always the same result, 404s on /trpc ```...

Should useQueries be able to 'select' data?

Hi! I'm trying to use the newly implemented useQueries method to query for multiple items. I need to modify the result, so I'd like to use the select property. However, by doing so, my results aren't modified to the properties I've selected, it still just returns the whole object. Image #1 shows my select statement attempting to only grab the id and permissionId Image #2 shows the logged result in my browser displaying the full object....

Right way to structure your code when using tRPC?

I was wondering how you properly structure your tRPC ruter code? Writing all the code in the routers can become messy quickly. Do you split it up in controller and service files (MVC)?

React Native Usage

Hello, I wanted to know if trpc can be used with react native ? And is it possible on a bare react native cli project ? Thanks, have a nice day !...

How can I cache a single procedure?

I've seen the docs on caching here: https://trpc.io/docs/caching But that is caching the entire app router. my app router has many "subrouters" (Not sure what you call them) and I need different cache times for different "procedures" in those routers....

transformers, tensor.js, PyTorch and tRPC

dumb question: does anyone has experience with tensorflow.js? is there any major obstacle to use tensorflow.js rather than PyTorch and tensor? Just wondering if there could be any future difficulty using t3 stack while having transformers and embedding models to generate output at the backend

subscription

How do you guys Authenticate / Authorize Subscription ?

NextJS and createProxySSGHelpers context type error

Hi guys, do you guys know a better way of clean this typescript error? createProxySSGHelpers({ router: appRouter, ctx: await createContext({...

Validating Permissions

Hi! A common operation that I'm doing in tRPC is validating that a person has permissions to perform the action they're trying to do, i.e: ```typescript...

Any typescript chads able know if it's possible to map a type to another type w generics

Not 100% sure if this is appropriate to ask here but I figured there's a lot of good TS developers on this discord.. let me know if I should remove. Is it possible to use inference to somehow map one object type to another type generically? I know we can do it w/ strings but what about full objects? IE...

Type safety with enabled option

https://tkdodo.eu/blog/react-query-and-type-script#type-safety-with-the-enabled-option What is the best way to solve this with trpc? ```ts function useSessions(userId: number | null) {...

useQuery enabled not working???

Even setting the enabled to false --> trpc.order.get({id: "123"}, {enabled: false}) still makes the request

`QueryClientProvider` not included in `withTRPC`?

Trying to use import { useIsMutating } from "react-query" but it's throwing Error: No QueryClient set, use QueryClientProvider to set one We have the trpc.withTRPC(MyApp) with Next.js to add the tRPC provider - expected that this wouldn't also add the QueryClientProvider?...

Handle React error boundary

Seems like Im doing something wrong as I can't handle the error boundary from trpc query. I've queryClient with useErrorboundary set to true and wrapped my component that uses trpc query with the React Error Boundary but it doesn't seem to be able to catch it. When I just throw before the query it successfully intercepts the error but from trpc seems its not doing that? Am I doing something wrong ?? ```js const [queryClient] = useState(...

Any tips for Typescript slowness?

We successfully migrated from 9.x to 10 but are still seeing slow VS Code perf (10+ seconds to get any type info) are there any strategies we can use to minimize this?

Change status of useMutation from 'success' back to 'idle'

Hiya, I have a mutation for creating stuff that can run a few different ways on a page, and I want to change its 'success' status back to 'idle' after 5 seconds. Is there a programmatic way to change a mutation's status from 'success' back to 'idle'?

Is it possible to call one procedure in another?

I have multiple routers in my trpc server. For example userRouter (e.g. procedure: getUser) and postRouter (e.g. procedure: updatePost). Is it possible to call the getUser procedure from my userRouter in my updatePost procedure? Or are all procedure effectively independent....

Handling Query Errors at Root of App (v9)

I want to show an error toast on my NextJS frontend every time there is an error from useQuery in a functional component. Is there a way to add something at the root of my app that can watch for trpc errors or do I have to handle it at every use of useQuery? (note: i am on v9)