tRPC

T

tRPC

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

Join

Best practices on trpc and Sentry

We are currently migrating to trpc from Apollo server/graphql. We don't use next. What are the best practices for using error reporting tools like Sentry to get end to end (client to server) error handling or if that is challenging informative errors to sentry from trpc-server. Would love to hear your experiences. Thanks in advance.

How to do dependecy injection?

My routes are grouped by using the router object. i'd like to be able to inject a service to each route group. is this possible and how can i do this?...

input needs to be an object when doing a batch call?

Hey folks, just setup tRPC and running into the above error when trying to run mutations. Queries, even with inputs, work fine. Am I doing something wrong? ```ts // Router export default router({...

dynamic query and mutation

Hello. I have an edit form component like this: ```tsx const router = useRouter() const { t } = useTranslation(["admin/common"])...

A lot of WHY

Great post from @cje on Twitter but also got a lot of questions 1. If the data flow starts from server/api/routers/examples.ts , why is the create-t3-app documentation starts from pages/api/trpc/[trpc].ts? Is there specific reason for that? Or is it just a big massive loop that has no starts and ends? 2. When you say Next.js hands the request to tRPC, shouldn't it be from pages/[somepage]/*.tsx -> page/api/[someapi] ->server/trpc.ts -> server/trpc/*.tsor some server/db/*.ts? ...

It is possible to define a middleware for all routes?

Instead of creating a public/protected procedure and using it for every procedure I was wondering if TRPC has any option to define it in the route definition itself:

How are they defined separately?

I am using monorepo for my project design and I want to separate the definition of trpc completely independently. I have @app/api to take care of implementing the trpc api definitions in @app/api-define. I want to define all trpc api content ( type define ) in @app/api-define as a separate package....

how can i get procedure name?

is it possible to get procedure name? i would like to append a service to ctx based on procedure name? is this possible in trpc?

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