tRPC

T

tRPC

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

Join

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";...

Is it okay to use a single proxy client in Next.js pages router?

Hey guys quick question if anyone is around. Are there any issues with defining a trpc proxy client once in nextjs pages router and then reusing it in client components by manually passing it to a useQuery? ```ts // define this once in src/trpc.ts export const trpc = createTRPCProxyClient<AppRouter>({...

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:...

Can I use tRPC on multiple platforms?

I want to make tRPC + Next.js my primary tech stack for building all my full-stack web apps, but the problem is, what if in the future I decide to build a mobile app for this web app using Expo (a React Native framework)? Can I still use tRPC as my backend? Like, does it have a REST API that I can fetch from the Expo codebase?

Missing Module in TRPC Migrate

I know you just released the migration for the TRPC upgrade but I thought I would share that I got this error ``` ❯ npx @trpc/upgrade@11.0.0-rc.772 node:internal/modules/cjs/loader:1408...

correct way to handle errors run time errors

I want to handle errors, for example when executing this mutation an error appears ```tsx "use client";...
No description

Nextjs Proxy an exteral TRPC api via pages/api/trpc/[trpc].ts ?

I have an already built TRPC api and I would like to use it in my nextjs application. I would like to proxy it from the [trpc].ts. I have tried http-proxy-middleware which works but it break sometime which is a bit difficult to debug. wondering if there is an example or some doucmentation around this use case ?...

Redirecting

Is it possible to use NextJS redirect inside a procedure? I don't want to do it onSuccess every mutation I make to that endpoint

invalidate query

whenever i add a user my user list is not updating ```tsx const mutation = trpc.user.addUser.useMutation(); ...

How to let an LLM "use" a tRPC api?

Hey, so I've been wondering lately how to build a simple LLM-supported CRUD app. With REST APIs, it's clear: I can give an LLM the entire API specs (e.g. using openAPI / swagger, etc.) and then ask it to translate the natural language user request (e.g. from a "chat") into a series of actions, using the REST endpoints. Then the LLM can write curl request code, for example, to "use" the REST api. But from a react / typescript perspective, using tRPC is just A LOT better (no need to tell you, hehe). How would you design a system where an LLM is basically "an additional client" that uses tRPC? Would the LLM have to generate typescript code (instead of curl requests) that I'd have to run? How would the LLM know about the api spec? Any other ideas here?...

Wrong input types derived from @effect/schema

It seems like trpc is unable to resolve the input types for a procedure I'm using. The input is ```ts .input( Schema.decodeUnknownSync(...

Can't build NextJS with TRPC vanilla client.

My mono-repo contains 3 apps and one packages as under. ``` - app - agent - server # trpc server...

Missing .query()

I've done something interesting, and I have no idea what. I've done something wrong in the setup of my router such that each endpoint I've defined exists, but lack a .query(). I'm using the T3 stack, so most of the integration work is already done. I have failed to copy the setup correctly for my own router. This is almost certainly a newbie problem, but searching for .query() produces just a few false positives....
Solution:
The issue was that I'm a client component, and need to use the useQuery() style of calling.

`FST_ERR_REP_ALREADY_SENT` when using `res.send()`

I've setup context as such: ```typescript import { CreateFastifyContextOptions } from '@trpc/server/adapters/fastify'; import models from '../database/models.js'; ...
Solution:
this looks like it should be an api endpoint outside of trpc

Passing generic inside tRPC query

Hi, I hope you're doing well. Server: ```typescript findManyUser: publicProcedure.input(UserFindManyArgsSchema)....

Prefetch and useQuery usage on tRPC 11 and NextJS 15

The example in the documentation works when using useSuspenseQuery but hydrated data isn't there if I use useQuery: https://trpc.io/docs/client/react/server-components Keeping everything else the same in the exampleSo in the last section instead of this:...

error handling

Hi, what is best method to handle errors like incorrect email or password etc, cuz when im using throw new trpcerror i have error info in left down corner

"Invalid Hook Call" with minimal example

I am getting react invalid hook call errors when trying to add the tRPC react query integration to a project. I am still scaffolding the project, so it isn't much more complicated than a minimal example. The only weird thing I am doing is trying to use deno. I started with one of the vite react templates (I think it was a deno based template, but it was based on deno v1 so I had to make a few small adjustments). It has a barebones hono server hosting tRPC with an adapter. All I am trying to do right now is follow the guide for adding the trpc and react query providers to App.tsx. ```...
Next