tRPC

T

tRPC

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

Join

WebSocket connection hangs after significant amount of data passed through the connection.

Hey! I've been really enjoying using tRPC on my latest project, but have gotten stuck getting websockets to work properly these last few days. I'm able to establish a connection and successfully pass data back and forth between the client and server, but after a certain amount of data has been passed over the connection, the server stops responding without any error (the connection remains alive)....

Trpc Vanilla client producing ts errors

Creating a vanilla trpc client to hopefully use in my Plasmo Extension and it gives me this error With i believe this being a key factor: "Type 'AbortSignalEsque' is missing the following properties from type 'AbortSignal': onabort, reason, throwIfAborted, removeEventListener, dispatchEvent"...

Cannot read properties of undefined (reading 'data') of res.error.data, when trpc errors out

Hello everyone, I am using @trpc/react-query alongside trpc for express, and I am experiencing a crash when I have an error ``` debug: Server listening on port: 3000 at development mode error: ERROR OCCURED: '[\n' +...

Is there an example of a real world non trivial app?

Something that includes type inference, nested fields, calculated fields, nested React components that use data coming from the backend as prop? The only example app I've found is this: https://todomvc.trpc.io/ But it doesn't have any of the things I mentioned above 😢 ...

How to organise output types?

I'm having a hard time trying to figure out what the best way to organise output types and I was wondering if you guys/gals have any tips. Things I'm having a hard time with: - Some output objects that may be returned in multiple places (e.g. users.get, users.getAll, posts.get (as Post.author), etc.) all need the same extra fields that can't come directly from Prisma (e.g. "the last post from the user" or "whether one can delete this user"); what's the best way to extract and reuse the logic for these fields? - How to mask output types (e.g. make sure that I don't return User.passwordHash ever)...

Calling a trpc endpoint inside of a trpc endpoint

Hey all. I'm wondering how I am able to call these endpoints from within themselves? For example, I'd like to call getBotGuilds and getUserGuilds from within getAllGuilds....

Frozen input param

Is it possible to define a parameter on input schema (zod) that will have a hardcoded/frozen value wich should not be changed? So the value is like predefined in the schema but should be like not accessible via the client to modify? Or shall I add it in the procedure or something...

type mismatch between tRPC return (in sveltekit) and defined type

i've got this piece of code: ```ts read: async () => { const res = await trpc($page).getCards.query(); if (!res) return;...

pre fetch serveral prodecures dynamically

Hello!. I'm developing a React Native app which needs an offline mode for some assets that the user wants (like spotify albums or playlists). I have an endpoint that tells me which assets to download and for which procedures, so I can rehydrate those react query procedures in Offline Mode. The feature is working but I had to @ts-ignore, I'm trying to annotate this feature correctly. ...

procedure input context

Is it possible to accesss context in trpc procedure input validation? I have an aray of values in the trpc context and would like to make a procedure input schema to transform on those values to allow these as the input. Im using zod for input schema...

Is it normal to separate resolvers from routers?

Wondering if it's common and/or whether it's a good idea to attempt to separate procedures from the routers... I know there' a lot of extra explicit typing required with separation and wasn't sure what other people are doing

i have an infinite loop within my hook but apps works as expected.

when i console log inside this hook, it repeats non-stop every few seconds, but my app is working as expected there is no infinite loop per say. i'm really confused with this one. ```js import zustand from ... ...

trpc query running twice

Hey guys. I have a trpc endpoint which makes a request to the discord api to fetch a list of the users guilds. ```ts getGuilds: publicProcedure .input(z.object({ accessToken: z.string().nullish() })) .query(async (ctx) => {...

tRPC Call To Server

On the mobile version of my app, in NextJS, the build has to be static so I have to use my hosted web version ass the server url, but when it makes requests it says stuff like no query procedure found, whereas in the web version the request works just fine, I think it's because the static version of the app doesn't request with any cookies. How can I solve this?

Get count of stages assigned to user with stage name?

Need help in writing prisma query to get stages assigned to user with stage name? this is the scheme eg model User { id ...

TRPC global loading page

Hey. With trpc/nextjs I'm wondering if its possible to have a global loading context/state which is used across my whole app, whenever a TRPC endpoint .isFetched property is false, it will display a "loading" symbol. Currently I have to do something like this on every page: ```tsx...

Multiple Clients/Services In tRPC Context

I know it's typical to pass around the prisma client in the trpc context, is the same true for other services/clients as well? IE a twilio or sendgrid client

Use middleware to send response

Hello, how can I send a response from the middleware without executing the input, such as making a cache middleware?

dynamic router creation

has anyone been able to create a dynamic router? e.g. i pass in the schema and some metadata and it produces the same routes but they are selected down to the metadata? my use case is i want to have crud against a set of tables... so i create a zod schema for each entity and want to create a router that does list, get, create, update, and delete, but for that one table, then i create one of each of these one per table... with what i've written, i'm getting the dreaded ts(2742) error.... The inferred type of 'routerForTable' cannot be named without a reference to '../../node_modules/@trpc/server/dist/core/parser.js'. This is likely not portable. A type annotation is necessary...