tRPC

T

tRPC

Join the community to ask questions about tRPC and get answers from other members.

Join

126 routers | TS7056: inferred type node exceeds - Multiple Providers?

Hello hope you are all well. quick info: env: node 20, pnpm, trpc^11.0.0-rc.466, monorepo. Everything in my monorepo is built/typescript declarations (otherwise autocomplete is a snail). I have 126 routers (didn't realise it was so much)...

How to get cursor in new Tanstack Query integration?

How can I access the cursor (or pageParam) in the new infiniteQueryOptions function? The current procedure input takes a cursor but I'm getting and error saying cursor is not passed to infiniteQueryOptions, and I can't pass it manually as it is calculated using getNextPageParam.

monorepo can't resolve trpc context

I'm usig a mono repo with next15 and trpc v11 + pnpm. I can't seem to share the trpc across the monorepo for some reason. What is weird is that the dev server runs it well but the build can't seem to find the useContext from the trpc. Says it collides with something. Type error: Property 'Provider' does not exist on type '"The property 'useContext' in your router collides with a built-in method, rename this router or procedure on your backend." | "The property 'useUtils' in your router collides with a built-in method, rename this router or procedure on your backend." | "The property 'Provider' in your router collides with a built-in ...'. Does anyone have a decent idea or a suggested setup for express backend, nextjs front, and trpc 11? I want a mono so that I can share a lot betyween them + share hooks with future projects. I want express so that I can scale them in AWS. and next pushed through AWS amplify. That's the current idea ayways. This is my experimental project where the dev works but the build fails. This is killing me for over a week now.
https://github.com/dsmurl/an-express-next...

Catch the error on trycatch and show the message

Hello, I am throwing a TRPCError inside my procedure ```js throw new TRPCError({ code: "BAD_REQUEST",...

operation input is formdata but trpc makes it an application/json POST call

operation: ``` { "type": "mutation", "path": "vectleProfiles.updateProfileLogo",...

v11 with tanstack mutation not invalidate query

When the mutation is successful and the router switches to the dashboard, sometimes the data refreshes, but other times it does not. However, if I press Alt + Tab, the data refreshes.
No description

Extra query keys for functions for invalidation

Is it possible to easily provide extra query hashes for functions? For example, lets say i have a procedure GetCurrentState()...

Type 'DecorateQueryProcedure<{ input: string; output: { id: string; name: string; }; transformer: fa

Hi all, I'm been trying to hook TRPC up with my Vite + Express stack. The guides work OK but when I try to use a procedure I get the following error. ```...

Should `.queryFilter()` not take a partial arg?

Replacing .invalidate(partialObject) to qc.invalidateQueries(trpc.path.queryFilter(partialObject)) doesn't work, since queryFilter type isn't partialled. Is this correct behavior? I would imagine the filter could be anything Really like this integration update btw ๐Ÿ™‚...

skipToken combined with the new tanstack query options

I am trying to prefetch the next x pages in a table, but i have some logic to determine whether or not this should happen. I used to use skipToken for this, with the old tanstack query package, and it seemed to sort of working. I tried changing the code to fit the new react query package, but it instead of skipping it now runs the API call without any options. ...

different transformers for different routers

How can I specify a transformer per router? On the client, I use superjson with BatchLink for everything, except file uploads (no superjson, HttpLink). It works fine, but on the backend all routers use superjson, so the returned object has a wrapper with a single json field in it, and TS types are mismatching (TS types assume no wrappers will be there)

super quick question about prefetching

Is it best to use a promise.all when using multiple instances of prefetch to fetch data on the server to ensure that both queries are running at the same time? From the looks of it trpc handles this automatically so it is unneeded?
await Promise.all([api.guild.get.prefetch({ guildId }), api.application.getList.prefetch({ guildId })]);
await Promise.all([api.guild.get.prefetch({ guildId }), api.application.getList.prefetch({ guildId })]);
...

TRPC not writing to QueryCache?

Hi all, I've been using TRPC in a production site for over a year now. I recently have made some additions to this site that required cache invalidations, but for whatever reason I couldn't get them working. Troubleshooting the reason led me to discover that it appears the querycache my trpc instance is using is just always empty. (Empty cache = nothing to invalidate?). I built the app using T3 and when I migrated to app router I built a new T3 app and used it as a reference. I've been looking at the differences between a fresh T3 creation and my app and I just can't find anything that could be the culprit. I've tried saving the queryclient to the window and it looks fine except itโ€™s got an empty cache....

Query via a non-connected wsLink never times out despite AbortSignal

When the wsLink is disconnected (eg server not available), is it normal that a query does not timeout despite passing an AbortSignal ? I was not expecting this behavior. Is there an easy workaround for this? ```ts import { createTRPCClient, createWSClient, wsLink } from "@trpc/client";...

Where did useUtils go?

I am working through upgrading my project and I use useUtils here and there to do fetches from components like ag-grid which requires a data source It looks something like this ```js...

get state of streaming response

Is there a way to get the state of a streaming response when using https://trpc.io/docs/client/links/httpBatchStreamLink and returning an async iterator? "isPending" is false once the headers arrive and I did not find anything else....

How can I break this loop when the client disconnects?

onReceiveMessage: protectedProcedure .input(receiveSchema) .subscription(async function* ({ ctx, input }) { let lastCheck = input.lastMessageTime ?? Date.now() ...

Early return for certain input parameter for queryFn

I want to transform this useQuery to trpc ```typescript import { useSuspenseQuery } from "@tanstack/react-query"; import { useParams } from "next/navigation";...

Upgrading tRPC v10 to v11 in NextJS 15.0.1

I'm want to upgrade my tRPC to v11, I already follow the instructions on the docs https://trpc.io/docs/migrate-from-v10-to-v11#installation--upgrading using pnpm. Installation is running smoothly, but when i run pnpm build i get ```...
No description

best practice for invalidating protected queries upon profile switch

I have an app where users can have multiple profiles. I have a protectedProcedure that does a db check on the user and profile ownership as a base. on the frontend, once user switches profile, I want to invalidate all queries that are "protected". Well known option is:...