tRPC

T

tRPC

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

Join

Ability to mutate/extend `input` from middlewares

Hi I have a global middleware that should run for every route. This middleware simply coerces '' (empty string) to undefined for the whole input object. Here is my setup: ```js...

Hot to redirect in middleware when using createCallerFactory

Hello. I do have this tiny middleware: ```typescript const authMiddleware = middleware(async (opts) => { const result = await opts.next();...

Remix: How can I return headers from a query or mutation back to the action/loader?

I'm using Supabase Auth and a requirement is to return the headers back from its client creation function. Without TRPC and just using the standard actions/loaders, I can simply return json({...}, { headers }), but I can't seem to find a way of doing so with TRPC. I've looked at the TRPC docs on custom headers but it seems to be NextJS focused. Does anyone have an idea? Thanks....

Using output validator breaks query return type inference on react query

Hi! I am not sure whether this is expected and whether there is some way to fix that but here it goes. I am using trpc (up to date 11 beta) on nextjs set up according to trpc website guide and use react-query integration as presented on screens. When I skip .output([some validator here]) on procedure definition, return types are correctly inferred and data is as presented on screen. However when I add output validation (see other screen), the returned data type is set to unknown. Am I mi...
Solution:
Ok I resolved my issue myself, it's that I did not have strict null checks turned on on my component directory since I haven't managed to turn it on everywhere yet. When I turn it on, types are inferred correct. Case closed.
No description

How to pass headers from serverActions in Next.js App router.

I'm using tRPC with Clerk auth provider in Next.js App directory. I created a serverClient to use tRPC on server-side but the context is complaining about not having request headers, it throws this even on building my application. Attached error and my file structure....
Solution:
Resolved it by moving clerk auth() to tRPC middleware with that server don't need to pass or the inner context doesn't need to have Clerk auth() as it doesn't depend on req or res objects.
No description

Need Guidance Optimizing Multi-Select Typeahead

What your environment is: Node 18? Bun? pnpm / yarn / npm? - Bun v1.0.23 - Next.js v14.1.0 (app router) - tRPC v^10.45.0 - React Query v4...

Private API, public clients

Hey everyone, we're about to OSS some good stuff at my company and I'm wondering what's the best approach to ship public libraries (like a CLI) which are communicating with a private tRPC powered API. It seems like today, trpc-openapi would be my best option? Like generating an openapi spec and using a typesafe openapi client generated with this spec?...

How to get the type of context after middleware context extension?

I have a middleware where I validate and set a userId. My router knows that userId is no longer undefined, but I need to pass the route context to another function. How do I set the input type for that function such that userId is no longer undefined?

what am i doing wrong?

My turbo repo containing expo-clerk-trpc does NOT work. and I've tried everything I have no idea what to do. Here's the repository: https://github.com/ShubhamPatilsd/location-locket-app Here are the issues I'm facing:...
No description

Reusable Component to take router as props / dependency injection. How to type?

for example: ```ts export const Content = async ({ api }) => { const items = await api.getAll.query({ watched: true }) ...

tRPC mutate call firing two requests with custom link

Node: 18.16 tRPC: 10.38.0 pnpm What's wrong with this custom link that's causing it's addition to a tRPC client to make two requests?...
No description

Issue with Fastify / tRPC / Angular

We are trying to setup Angular project with tRPC. In Angular we get following error: ``` Error: node_modules/fastify-plugin/plugin.d.ts:19:114 - error TS2344: Type 'Options' does not satisfy the constraint 'FastifyPluginOptions'. ...

Drizzle query not working only inside trpc

My drizzle query works inside a regular nextjs api route. The same query running inside trpc throws an error: ``` TRPCClientError: Cannot read properties of undefined (reading 'prepare') at TRPCClientError.from ...

Server freezes when doing mutations...

I have the exact same issue as mentioned in this post: https://discord-questions.trpc.io/m/1176971701075058690 It doesn't seem to be solved and is a very recent bug, any news regarding this? My entire application is breaking because of this......

Create Wrapper only for Procedures that support Infinite Query

Greetings, I'm attempting to create a help that will handle some generic logic I desire for a series of infinite queries. I found this stackoverflow post, https://stackoverflow.com/questions/77096846/wrap-usequery-of-trpc-in-a-custom-hook-with-correct-typescript-types, which is essentially what I want. The only difference is that I only want to accept procedures that implement the inputs required for the useInifiniteQuery method to be available. The implementation above will not expose that function. I noticed that the main difference is that the inputs params for an infinite query procedure must have { cursor?: any }. There's no built in Procedure for infiniteQuery, but I thought I could make one by doing something like this....

Why am I getting 'Argument type is not assignable to parameter type ProcedureResolver<unknown>'?

I have this warning in my editor (jetbrains InteliJ):
Argument type () => any[] is not assignable to parameter type ProcedureResolver<unknown, unknown, unknown, unknown, unknown, unknown>
Argument type () => any[] is not assignable to parameter type ProcedureResolver<unknown, unknown, unknown, unknown, unknown, unknown>
...
No description

Efficient way to use tRPC client with auth headers from secure storage

Wondering if anyone has a recommended pattern on caching the deviceId / authHeader using a React Context instead of fetching it async on each request. Thanks! ```ts...

Using tRPC with Expo API Routes feature?

Is there a possibility to merge "tRPC Express Adapter" with "Expo API Route Express Deployment"? tRPC Express Adapter: https://trpc.io/docs/server/adapters/express Expo API Route Express Deployment: https://docs.expo.dev/router/reference/api-routes/#express ...

TRPC not working on multi tenant app

Everything works on localhost. When I deploy it on the vercel None of the mutations work. ...
No description

TRPCClientError: Unable to transform response from server

Hi 🙂 I've just started - so nothing more than boiler plate code but for some reason it doesn't work. As you can see in attached pic, browser is ok with serwer response I am using neflify funcs as my backend ...
No description