tRPC

T

tRPC

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

Join

Can you get the queryClient without using a hook?

Can you get the queryClient without using a hook?

How can I reset the cursor when using useInfiniteQuery?

I have various filters that I can set for the query, but when setting those filters I need to reset the cursor to undefined before setting the filter. Right now when I set the filter, the last cursor is always being sent. How can I reset it? What I've tried is calling invalidate and reset on the query, but the cursor is not being set to undefined as can be seen in the screenshot. ...

How does routing work in tRPC especially when using merged routers?

I am having trouble understanding how tRPC lays out routes. Let's say I have the below ```typescript export const apiRouter = router({ version: publicProcedure.query(() => {...

where is useQuery [key]?

Learning trpc, i use to tanstack with queryKey, can not find how that works with trpc, if i want to revalidate my query? const query = useQuery({ queryKey: ['todos'], queryFn: getTodos })...

useInfinieQuery with initialData, Refetch only after second change of inputs

Hi everyone, I have the problem as stated in the title. My code looks like the following: ```ts...
No description

Adding tRPC HOC breaks zustand

It seems that adding the trpc hoc breaks my zustand stores initial values and generates bad data. After installing trpc following an install guide, I realized that now my zustand items don't take their initial values anymore. I am not sure why it is due. Happens both with SSR and non SSR setting. My error is the following : (please see the image) I am using yarn to install packages and running latest Nextjs/React....

Next.js + tRPC, multitenancy, access Next.js Router when setting tRPC headers

Hey all! I'm writing a multi-tenant solution. Most Next.js pages lie under the /pages/[tenantKey]/ path. The tenantKey describes which tenant we are working with at the moment. I'm messing around with Next.js + tRPC, and I would love to be able to access the Next.js Router (to access the tenantKey) in a generic way when accessing the tRPC client. Using the tenantKey in the path, I could automatically send a header, X-Tenant-Key, that the server side of tRPC could look at when generating the appropriate context. I'm thinking some React hook or something for this: ```ts const useTRPC = () => {...

getInfiniteData returns undefined

I am using the t3-stack. Whenever I am calling getInfiniteData it returns undefined. ``` console.log( trpc.events.getAll.getInfiniteData() )...

Enable both `useQuery` and a raw `query` from the frontend (for use in async validation)

Hello everyone, some context: ``` . I'm building a project with a variant of the t3 stack (key point: using trpc layered on tanstack query: trpc.xxx.yyy.useQuery({zzz}) ) . I'm using zod with react-native-forms, using the zodResolver (key point: form validation through zod, can't add external validation without a lot of hackiness)...

Nextjs http endpoint (no prisma)

I have simple pages/api/todoEndpint how do i call this endpoint with trcp? I don't want to use prisma?

Adding clerk auth object to createServerSideHelpers

So I followed clerk's docs for TRPC (https://clerk.com/docs/nextjs/trpc) and I added auth to the context object. This works great for most requests I've made, but I'm having trouble now that I'm trying to use getStaticProps and createServerSideHelpers. I slightly changed the AuthContext type so that auth can be undefined, which would make sense when the page is generated at build. But is there a way to get auth info in there, when the page gets regenerated later as a user visits? Or would I need to make any auth-related stuff part of the client code? Snippet:...

Call retries were exceeded with ssg

I'm running a create-t3-app on Node 18. Has anyone seen errors trying to use SSG with TRPC and Prisma? I'm new to the T3 stack overall so I'm not sure if the error really comes down to Next, Prisma, or TRPC here. But when I try building with the code below, I'll run into Error: Call retries were exceeded, coming from, of all things, next/dist/compiled/jest-worker/index.js, which I thought was super weird. Not sure how this could be related to Jest. There are 1204 cats, so I'm trying to generate 1204 pages here, so maybe that's just too much? I noticed that if I add take: 10 to getStaticPaths, then I don't see this error anymore. But on the other hand, all I'm trying to do to generate each one is just a simple db query. TBH I would have this expected to scale to as many pages as I need to generate here....

How does batching work in SSR & nextjs app directory?

I'm currently playing with the app directory for nextjs. If I have a SSR client set up like this: ```typescript export const client = createTRPCProxyClient<UserRouter>({...

"This is likely not portable" error

Randomly started getting this weird error on my front end, can't find anything online on it. Something wrong with my project config, I'm sure It appears on my trpc react but also in some other places: ```ts...

Integrate third-party added endpoints into the router definition?

Its would be cool but not too important, so I was wondering whether or not it would be possible to have dummy router configs without any actual routers. I am using SuperTokens for my Auth and it adds several endpoints to my server (/auth/signup, /auth/login and so on), and it would be cool to somehow add these into tRPC so that I could ditch custom fetch calls.

Why am I seeing 500 errors on responses to clients in production?

I'm running my trpc server with NODE_ENV=production with the expressjs adapter, and I'm getting this in the response of a client. [{"error":{"message":"connect ECONNREFUSED 127.0.0.1:5432","code":-32603,"data":{"code":"INTERNAL_SERVER_ERROR","httpStatus":500,"path":"budget"}}}] I would expected the message to not show up, and just give a generic error message. Why don't these errors get written to stdout by default instead? Or maybe I don't have it setup correctly?...
Solution:
You can use an errorFormatter to customise this

trpc auto refreshes page when I lose focus

Hi, i thought this was a development environment only configuration, but it does it even in production. How am I able to change this functionality?

Incorrect type errors

No idea if this is a trpc issue, but i'm having a bit of a nightmare with type errors. Nothing is showing up in vscode, but when I run eslint I'm getting a bunch of errors that shouldn't be showing. Has anyone seen anything like this before?...

test post 2

hello again
Solution:
solution

query debounce

Hey there ! I wonder if anyone could point me to a standard recipe to achieve query debouncing and caching using trpc and useQuery in react. I'm basically firing an api call everytime the user change his input which start to be quite a lot when he keep the "delete" key pressed on the keyboard....