tRPC

T

tRPC

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

Join

Get tRPC procedure latency?

Hi all, is there a supported mechanism to run common code to all procedures, say if I want to get latency metrics. I want to run the same latency math on all my procedures. I could create a helper function that I just have to remember to wrap all my procedure code in but just wondering if there's some supported tRPC way of doing this?
Solution:
What about middleware

Does or will trpc support http event stream?

Does or will trpc support http event stream?

Can't get wsLink's retryDelayMs to work

I'm trying to add some backoff for when connecting to my websocket server fails. I've got the following code, but the retryDelayMs function never seems to be called (I don't see any console messages), and the wsLink keeps trying to reconnect immediately: ```tsx const TrpcProviderInner: React.FC<{ children: React.ReactNode }> = p => {...

createTRPCNext and createTRPCProxyClient within one NextJs app

Hey, Is there any possibility to use createTRPCNext and createTRPCProxyClient clients in one NextJs app? I have a use-case where I need to use a vanilla client to fetch data in my app but I don't want to lose the possibility of using useQuery and useMutation hooks in my components.

Calling axios requests not working

If i call an API using axios in trpc query procedure It works if the url is https it dont if url is http localhost it just keeps loading...

Best practices in naming and defining procedures when they don't fit into standard buckets?

I am loving TRPC and its type safety, but I feel like I'm struggling with the naming of procedures. I'm pretty confused with why I need to fit my procedures into one of the 3 buckets: query, mutation, or subscription. For example, I have items. They can be queried, mutated and subscribed to. And maybe a few more things - items can be generated, created, pulled from a remote source, deleted, renamed, aliased, etc. But let's try to fit this into these prescribed buckets. I felt inclined to define items as a publicProcedure with all 3 verbs. But I have to choose only one, not all three. The api does not support chaining on multiple verbs. If I want to support all 3, I have to differentiate them as separate procedure definitions such as getItems, updateItems, and subscribeToItems... but then, what's the point of query/mutate/subscribe if I am already differentiating them as separate procedure names? Now the client api surface is weird: I wanted the client code to read: client.items.query(), or client.items.mutate(...)...

Separating routers into their own modules and merging them causes "any" type in client

Hi all, I've separated my router into multiple files, but when merging them I get any types for all procedures in the client. This happens with both mergeRouters and composing a parent router with multiple child routers. It seems like trpc is loosing type information... I've verified that both my client and server trpc have the same version, 10.23.0, and that my typescript configuration is correct according to the docs....

custom query function

I have a use case where I need a trpc procedure call when a specific key is not present in the local storage else I return the data in the local storage. Can this be doable without relying on the vanilla react-query hook ?

TRPC type checking during build fails

Environment: node 18.6.0, yarn Whats wrong: Type checking at build time fails. . I think this might be an issue with the Lambda Adapter These scripts are run. deploying through AWS amplify. this doesn't error locally $ yarn run typecheck...

createTRPCNext config ctx always returns undefined.

Hi Everyone. So I'm trying to use TRPC and Nextjs for auth and post query etc. I have client side createTRPCNext below. ``` export const trpc = createTRPCNext<AppRouter>({ config({ ctx }) {...

Standalone Next.js 13.3.2 error

Hi, since the 13.3.2 update of Next.js, I have the following error : ``` TypeError: Cannot read properties of null (reading 'useState') at exports.useState (/home/quentin/labs/monorepo/apps/website/.next/standalone/node_modules/next/dist/compiled/react/cjs/react.production.min.js:29:394)...

returning undefined from server gets stripped on the client

I encounter this issue when working with TRPC React under a Turborepo. But I works fine on Next I see that its been merged but still appearing on my end https://github.com/trpc/trpc/issues/4049...

TypeScript, Mono-Repositories and Internal Packages / Project References

I am getting quite frustrate with project references / internal projects and the resolving of types for TypeScript. To make it a bit smaller, let's say I have @acme/api-service which exports TRPC types and a Cloudflare Worker, I also have @acme/app which wants to consume this api service's TRPC types. In @acme/api-service I am exporting main / types fields in package.json, I am also using path aliases, and defining global types for it's environment in compilerOptions.types in tsconfig.json. When I don't use project references, and I run tsc --noEmit for type checking in the @acme/app folder I get errors about the missing global types, and the path aliases. When I use project references it seems like that kind of fixes it, but it looks like I need to continuously watch / build the declaration files of @acme/api-service while in development to not get these types out of sync....

Help to deploy my TRPC proj from a monorepo (turborepo) at Vercel

I'm trying to learn monorepo with TRPC, both are new for me and Im kind struggling to deploy it because Im super newbie in deployments. I have a turborepo with two apps, one is my react app and other one is my node server in express with TRPC. I dont know if I did correctly but I went to vercel and Ive choose the FE project. for the build options I left what had there already, seems Vercel knows what to do when its turbo repo and it went all good!!...

TRPC ratelimiting endpoints

I am currently having some problems with a race condition in my TRPC nextJS api. Essentially what is happening is I have a enforceGuildPermissions method, which basically checks if the user who is making the request has permission to get the data for that guild. The data is stored in my Redis cache for 3 seconds. This works okay sometimes, but other times because there is 3-4 different trpc requests running for a single page which are guild, role and channel. It causes the last request (channel) to get rate limited by the discord API because they are all running concurrently, this means it doesn't give my caching code chance to update it before the next one runs....

express-session for tRPC

I am using express-session for all my servers to create session authentication. Is there something for tRPC that you can recommend, to get session authentication?...

next-prisma-websockets-starter seeds twice on 'pnpm dx'

Hi, i'm using this starter template for my app. The dx script from package.json runs both prisma migrate as well as prisma seed and the former seems to run the seeder as well, causing data to exist twice in the database after running dx. Link to line in package.json: https://github.com/trpc/examples-next-prisma-websockets-starter/blob/db3a7794caa8d024f7115ce1f767d84c0172dd93/package.json#L21...

Can you return from an API endpoint before a sync operation is complete?

I'm curious, if I have an endpoint that saves something to a DB and I choose to return from the endpoint without waiting for the DB call to finish, is it possible the server will shut down before the DB call is complete? I ran into this problem in a previous project where I was using AWS Lamdas, not Next or TRPC. I didn't want to wait for sync operations to complete if I didn't need the data in my API response, but I found that the Lambda would be shut down once I returned and often my processes would not be completed. Thanks!...