tRPC

T

tRPC

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

Join

Is there any way to temporarily disable mutations?

My goal is to move into a read-only mode temporarily. I'm thinking anything could be fine as a short term solution. 1. Throw an explicit error when mutations try to be called 2. Procedure not found error...

After upgrading to 11.0.0-next-beta.300, every request throws zod error

I didn't do anything but upgrading the trpc, and the error throws:
{"issues":[{"code":"invalid_type","expected":"object","received":"undefined","path":[],"message":"Required"}],"name":"ZodError"}
{"issues":[{"code":"invalid_type","expected":"object","received":"undefined","path":[],"message":"Required"}],"name":"ZodError"}
...
No description

Setting up tRPC for next.js with edge AND serverless functions

tldr: I am trying to build an app that uses both edge AND serverless functions by creating separate endpoints. Has anyone ever done this successfully? I am building an app that runs openai-API-requests and is connected to a Planetscale mySQL-DB with a prisma-layer (t3-setup). All functions are serverless. I am facing timeout issues on the openai-requests, since they are taking quite long. I am trying to switch all openai-functionalities to run on the edge. This means longer timeout-limits on vercel and the ability to stream the response. All the other functions need to remain serverless, since they use prisma, which isn't available on the edge. What I have tried so far:...

Hello i am using trpc open api but there is an issue regarding using z.optional() however in the lib

Hello i am using trpc open api but there is an issue regarding using z.optional() however in the lib it is used optional

CreateCaller with React-query

Hey guys. Is it possible to combine createCaller approach with React-query? I figured out that react-query needs HTTP/WS link to work at all. Do you have any idea how to combine them?

Zod.enum makes my tRPC explode

I'm having an issue with what appears to be circular dependencies. My problem is that I'm not sure what is being parsed that is causing the issue. I don't see a circular dependency. I think that the error message is not indicating the problem line correctly, as I just added more debug to the file and the error message didn't change. Is there a way to switch on more debug logging in v10 on the server side, so that I can see what's happening more? The error message:...

React type errors because of backend

Hello, I'm using tRPC in React and it's working fine generally. However, WebPack always finds something to complain about that is in my backend where I import AppRouter from and I haven't found a clean way yet to fix this. As you see in the screenshot, it complains about some fastify types. Those errors aren't present on the backend side and I could just install the types in my react repo too, but that does feel really dirty. Is there a nice way to handle this? Thanks in advance. And generally spoken, tRPC is the best API layer I have ever used. I come from ApolloGraphQL which is kind of nice, but also always a pain to set up....
No description

Value attached to all queries

Is it possible to add a value the all queries so its preset within every procedure call on the client?? Lets say I have a cookie which Is determied on the server and I want it to be added to every response or the trpc query calls. Is it possible to add it in a single place rather adding it in every procedure I make making it very prone to error because I can forget it ?

Invalidating query cache irrespective of query params

Hey is it possible to invalidate a query cache without providing parameters? I have a query for example with filter parameters and each filter produces a different cache, but from elsewhere I want to invalidate all of the caches involved in that query. I'm using tRPC 10.38.2 (can't upgrade right now)...

Sentry integration

Hello. I'm using trpc + fastify approach. I need a proper error loggin so I added fastify sentry, which works fine and logs the errors, however i'm missing some context- trpc data sent for the query/mutation, user information and etc. I would like to add that. Anyone had to deal with this before? So far can't find a decent solution for this, especially for retrieving the input.

In my NEXTJS app can read value next-auth session in localhost ,but not when deployed to Vercel

I have several procedures in my TRPC router (https://github.com/Teodorant1/nighthawk_repair/blob/master/server/index.ts), it seems to be bricking in the ones where I am awaiting the session const session = (await getServerSession(authOptions)) as Session; seems to be the line of code that is bricking it on Vercel...

WebSocket Authentication: Cookie missing

Hi community 👋 I'm currently trying to integrate the wsLink, and I've noticed that cookies are not automatically sent during initialization (first request). What could be the reason for this? My website runs under the URL http://localhost:3000, and the web server under http://localhost:3001. Does it have something to do with CORS? ...

Client request headers with createTRPCProxyClient

Simple proxy client, following the documentation ```ts import { createTRPCProxyClient, httpBatchLink } from '@trpc/client' import SuperJSON from 'superjson' // .. other imports...

Get auth token from context when defining httpBatchLink

Im setting up an ApiProvider for react query and I want to get the authorization token for the Authorization header from trpc context since my session is stored there. My api is defined here ```typescript ...

Infinite query get direction info

Hello everyone, I'm implementing a bidirectional infinite query and i would need to access the direction param into my trpc endpoint: https://tanstack.com/query/v5/docs/framework/react/guides/query-functions#queryfunctioncontext. Is it possible to get this param passed in trpc procedure input with useInfiniteQuery? (for info i'm using trpc v11)...

Subscription for a specific user

How can I create a TRPC subscription that takes a userId? When updates occur elsewhere in my app, I want to broadcast them to relevant users. Trying to avoid a full Socket.io rooms implementation...

Procedure specific custom headers

I'm using recaptcha to protect some of the procedures, and I'm used to sending challenge tokens as headers - this way the don't dangle in actual request data. It's and Astro + trpc fetch project and the server part gives me no issues, but I can't figure out how to run recaptcha and set that header only on some of the procedures. The example shown in the docs would add headers or run function for all of them, and I don't need that
Solution:
So first you add a flag to request context like this: ```typescript api.store.checkout.mutate({ lang, person_name: {...

Unable to use caller, in frontend bcz i dont have access to req and res objects

i was trying to use trpc callers, for ssr the queries, but i was not able to create one since i have req and res objects in my context, where my context looks like ```js interface CreateInnerContextOptions extends Partial<trpcNext.CreateNextContextOptions> { session: Session | null;...

Reduce `isPending` time for prefetched Queries?

I'm looking for ideas on how to reduce the isPending time for prefetched getStaticProps queries. Google search console is upset with the LCP render times on mobile, and the LCP is completing roughly one second after the the loading state starts? This is despite the initial data being included in the page load/root....
No description

Beginner Client Problems

Node 21, npm 10.2.4, tRPC 10, from a create-t3-app run yesterday. I've got a zod validator create by drizzle-zod, for inserting into a table. There is a .omit() call to remove fields not allowed to be set by my user. I'm using this in a publicProcedure as the argument to .input(TableValidator), and there's a .mutation() that inserts the data into the database. I have also used a z.infer<typeof TableValidator> to get a type for this data, which I'm using on the client to coerce the single data structure I'm using as test data to that type, to use as an argument to the .useMutation() call....
Solution:
Our docs also will have examples