tRPC

T

tRPC

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

Join

trpc optimistic updates causing data flicker

I'm trying to add optimistic updates to a calendar component but when the mutate function is called there's a flicker in the existing events

> Error: Invariant: headers() expects to have requestAsyncStorage, none available

Hi, I use trpc v1045.1 in next 14.1 app router. I call it server side and have the following. ```js export async function createContext(opts: CreateNextContextOptions) { const { session, user } = await getUserAuth(); ...

How do I exclude properties while returning data?

I basically need to create a dto's that would exclude properties like access keys etc. while returning the data to the client - so basically just striping the object on return. How can that be achieved?

Does anyone have an example of subscriptions implemented in CloudFlare Workers?

I'm trying to use subscriptions via WebSocket in CloudFlare Workers, but it's been a real pain so far. Looking for any advice, thanks in advance!

TRPCClientError: Unable to transform response from server

I am currently encountering this error occasionally in my apps. I am using a Monorepo, which includes a mobile app and two web apps, all connected to a single database using Prisma and using TRPC in all apps. I have been trying to determine the cause of the error, but I still have no idea. I would appreciate it if anyone has any ideas or has experienced this issue before. Thank you

Unexpected token

Works fine locally, doesn't work when deployed to AWS via sst.dev. Was working last night. Redeployed the app today with no changes, started failing. Please help

Context is not being passed correctly

I will include my setup at the end. My problem is that I am using nextauth with database sessions and passing the session as context into the procedures; however, everything that I have added myself isn't being included in the context for some reason (user.id and user.role) This is my session type I declared, ```ts declare module "next-auth" {...

How to get the Request Body data of QStash

Hello everyone. I'm currently working on a client project that involves using trpc with Next.js. We're using Qstash as our message queue service, and I'm trying to publish a message to updateSubscription procedure. However, Qstash only supports POST requests. So, I created a mutation procedure in the trpc server. My question is, how can I receive the body data in the trpc procedure? I tried using input, but it seems like Qstash can't send the request. Could anyone please guide me on how to tackl...
No description

Preventing uncaught error propagation from server to client

Hello guys, is there any way to create default error handler? I want to avoid leaking internal information to the client. Example scenario: My database is down. ...

Throwing something other than `Unexpected token '<', "<!DOCTYPE "... is not valid JSON`

I'm trying to do custom error handling but whatever I throw just ends up being `Unexpected token '<', "<!DOCTYPE "... is not valid JSON`` Am I doing something weird here?...
Solution:
I solved it through returning the error locally instead of throwing it
No description

Create client that is used in every request, without re-creating client

Hi all, Consider the following ``` export const createContextInner = async ({...

Using TRPC Server Caller in client side.

What's up TRPCer. so i'm currently working in vanilla react app with seperate backend in .NET, in previous projects i have used Next with TRPC server and honestly loved DX with it so i wanted to implement it for the react app and parse .NET server response in TRPC route func and utilize @trpc/server pkg that way and use createCaller instance to use like almost server/query func. intention was to use tanstack react query and trpc routes as basically queryFn. Seems like that wont work tho. trpc throws not allowed to use server func in client side error. Is there a way to make it work? or TRPC requires a server implemented with trpc server....

Anyone has successfully setup a websockets subscription with an input ?

Hi guys, here is my environment: * node v20.11.1 * yarn@4.1.0 * trpc 11.0.0-next-beta.294 * next 14.1.4...

Middleware context changes aren't applied to `responseMeta(opts)` options

In our middleware I extend the ctx like this: ```ts const public = t.middleware(async ({ next, ctx }) => { return next({ ctx: {...

Cookie authentication flow

Hello can i get a bit of a help and explanation please? Im frontend learning backend on trpc, I have monorepo with trpc backend and next 14 frontend, I use wesockets, and my backend context accorgingly to the docs has type CreateHTTPContextOptions | CreateWSSContextFnOptions The problem is that in procedures I can’t use eg setHeader method from CreateHTTPContextOptions unless I type cast it so should I use a type assertion function or is there a way to infer proper type from createcontext so queries and mutation procedures have different context type than subscriptions? And when i log Object.keys(ctx)...
Solution:
Hi i would like to answer my question, the problem was that i did not pass credentials: include to the fetch options, currenty i use experimental_createTRPCNextAppDirClient with experimental_nextHttpLink, this does not allow to pass options to fetch, would you consider adding this option in future release? thanks

Is It Possible to use methodOverride with createNextApiHandler?

I'm trying to build queries for grids and filter and sort object could get very large which is exceeding the URI character limit for HTTP. so I'll switch them to POST and use body instead. the issue is this pattern keeps repeating in my app, so i found that there's a methodOverride option in the docs, but it doesn't seem to work in NextJs.

Lambda container reuse

In high traffic environments lambda reuses the same container to serve multiple requests. The lambda adapter appears to create a new Context inside the handler for each request. Is there any way to keep things like database connections and s3 clients in the global scope outside of the handler? We sometimes see lambdas fail due to running out of file descriptors when many connections are spawned from the same container.

Trouble with Vercel and deployment URL

Hey I've been having a problem with nextjs deploying to vercel. In localhost the calls to the backend are done correctly, but when deployed, the calls are made to https://myvercelurl.vercel.app/deployment_url/api/trpc/.... I don't know why the hell the deployment_url is inserted there. Running in npm, packages: @trpc/client: ^10.45.0 => 10.45.1...

1 trpc api server for 1 or many clients.

I'm a beginner, working on two monorepo projects that resides on the same folder, each of which with trpc (next) already setup. Both projects basically uses the same api, and what I've been doing currently is manually copying the routes from one project to another and run the server on the project where i'm running the client. I wanted to run the server on one project and have the other project connect to it as well, so I would no longer keep on switching servers cause most of the time I need the clients of two projects to run at the same time. Is this feasible, and if so, what's the optimal approach?...

Error formatting with trpcExpress.createExpressMiddleware

I'm trying to figure out how to do error formatting but it's unclear how to do it in the context of trpcExpress.createExpressMiddleware - The documentation use trpcInit.context().create({ errorFormatter(opts) { ... }) which I'm not using as I'm following the React Query example from the docs. Is there a concrete example I can refer to where should I plug the errorFormatter(opts)?...