tRPC

T

tRPC

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

Join

trpc openapi does not work on app router

https://github.com/jlalmes/trpc-openapi Can i just know if trpc open api for next is also applicable for app router, the repo has example for pages router but not for app router, i tried to replicate that to app router but it is failing by something like this [get-computers is just an api endpoint]...
No description

Subscription types are not inferred while queries and mutations are working fine

I am NOT working with a monorepo but while query and mutation types are being inferred out of the box on the client side, subscriptions are always inferred as any no matter how simple their types are.
No description

How are thrown (unhandled) exceptions safe to pass?

Hi, I started looking into error handling more and understand that all errors get wrapped in a TRPCError, however sometimes exceptions contain sensitive data. How does TRPC make sure that data doesnt get leaked to the client?

Canary useUtils and createTRPCQueryUtils type not callable

Trying to access utils object in my application after using useUtils or createTRPCQueryUtils and getting the following type error: ``` This expression is not callable. Not all constituents of type '(DecorateRouter & { [x: string]: (DecorateRouter & ...) | DecorateProcedure<_trpc_server_dist_core_procedure.QueryProcedure<{ input: void; output: { isAuthenticated: boolean; isAdmin: boolean; }; }>, _trpc_server_dist_core_procedure.QueryProcedure<{ input: void; output: { ...; }; }>>; }) | DecorateProcedure<...> | (...' are callable. Type 'DecorateRouter & { [x: string]: (DecorateRouter & ...) | DecorateProcedure<_trpc_server_dist_core_procedure.QueryProcedure<{ input: void; output: { isAuthenticated: boolean; isAdmin: boolean; }; }>, _trpc_server_dist_core_procedure.QueryProcedure<{ input: void; output: { ...; }; }>>; }' has no call signatures....
Solution:
Figured this out, was to do with me exporting the server types and importing them on the client. Added a path override similar to what is done in the trpc project to just grab the AppRouter type from the typescript files rather than the generated declaration.

tRPC run express under the hood?

tRPC run expressjs under the hood?

Modify mutation error messages?

We occasionally get timeouts from cloudfront which gives the user an error about how the cloudfront HTML error page isn't valid JSON, instead of what would make sense to the user, which is that the request timed out. Is there a callback or anything else anywhere we could use to intercede on error messages?...

server-side helpers doesnt work with `Hydrate` and `QueryClient`

environtment: node v20.9.0, npm Hi i tried to implement server-side helpers but somehow it just doesnt work, the fetch is successful but i think it didn't dehydrate i think the issue happened because im also using react query outside tRPC (first vanilla react query -> trying to migrate over to TRPC)...

Unable to mock unstable_batchStreamLink network response

Hi there! I have a couple API endpoints that call third party dependencies and would like to mock a network response for these calls during my playwright tests. I've been using batchHttpLink previously and mocking the following API route worked perfectly: ``` const deleteOrganization = page.route(endpointPath("authed.organization.delete"), (route) => route.fulfill({...
No description

Using trpc with fastify server and nextjs client

Hello, is it possible to use fastify for server and have a nextjs client and make use of the SSG / SSR helpers? if so, what adaptor should I use in that case? is there any example for this?

I can't mutate or query in SvelteKit

Environment: Node 20 with Yarn I'm not getting any specific errors but I don't get the "mutate" or "query" methods with trpc client in SvelteKit. Here is the situation: My API is written in Fastify. I'm using the Fastify adapter for tRPC. On the client, I get autocompletion for the routers (like user.createAccount or post.getAll) but I don't get the ability to mutate or query data. ```ts // api.ts file in lib folder...

TRPCError class, public readonly cause?: Error; this line should have override function

hey i am trying to use the TRPCError for throwing errors in my apps, but i am getting this error, changing the line from public readonly cause?: Error; to public override readonly cause?: Error; fixes the problem the problem but i am doing that in node_modules which is not how this gets resolved, how do i resolve this?...

Why do people use SplitLink? (http + websocket)

Why not just use websockets for everything? Just curious.

Force user to login

How can I redirect the user to "/login" if the user are not logged in?
No description

TRPC with middly middleware on lambda

Hello, has anyone used middly middleware on AWS lambda? Thanks!

tRPC on Vercel Serverless without Next?

I would love to be able to use tRPC in a vercel serverless context, but not in a Next app – just the /api folder. The @trpc/next adapter seems to be based on the path expansion properties of next ( /api/[trpc]), so I'm not what the best strategy is for using tRPC in a non-next project on vercel. I had a look at the vercel-edge-runtime example but that seems to be at a lower level (using the raw edge-runtime package) than what the vercel platform expects in the /api folder. If anyone has...

Errors while running mutations when deploying CT3A using SST

I'm currently migrating a NextJS project of mine from Vercel to SST. It's based of CT3A and the trpc setup is the same as in a fresh CT3A. I was also able to reproduce the error with a fresh CT3A Project. The error occurs when running mutations. TRPCClientError: Cannot read properties of undefined (reading 'resolve') The code for this, afaik runs in aws lambda....
Solution:
Solution is enabling streaming since ct3a uses the httpBatchStream link
No description

Keep suspense on SSR

I'm currently trying to perform a trpc query in Nextjs with React suspense, however, I only want the the query to be run on client-side only. Here are the options that I already tried: - Throw error while in SSR with a custom link. It works, but I will get a bunch of errors in my Sentry ☹️ ``` const ssrLink: TRPCLink<AppRouter> = () => {...

How to properly type function arguments for procedures?

I'm using tRPC 10 with trpc/react-query I'm trying to understand how to create a function that receives a procedure and it's input as arguments, so that I can then use that procedure reference to call useQuery and getQueryKey within the function: ```...

How Do I Ban Users & Invalidate Their JWT Tokens?

When a malicious user gets banned by an admin, I have to ensure he no longer can access protected routes, but that means I have to query the database every time checking a user's token, is there a more efficient method for invalidating tokens?