tRPC

T

tRPC

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

Join

what is "use" keyword

```ts const baseProcedure = t.procedure .input(z.object({ townName: z.string() })) .use((opts) => { const input = opts.input;...

How to Type a Middleware factory?

Lemme first show you what I want, so you can get the gist of it. (Consider me less experienced in typescript) ```ts publicProcedure .input(z.object({ test: z.boolean() }))...
No description

Does "enabled" in useInfiniteQuery work?

I am trying to prevent the hook to fetch data using "enabled" parameter. It works in useQuery, but useInfiniteQuery tried to load the data anyway. ``` const {data} = trpc.testRouter.testInfiniteQuery.useInfiniteQuery({ test: true,...

How to use NextJS tRPC client without hooks?

I want to use the vanilla tRPC client in NextJS (both browser+server), but I can't because it doesn't support the page context (ctx w/ req and res). tRPC Next seems to be built on top of React Query, which I don't want to use (it switches query() and mutate() to useQuery() and useMutate(), which can only be used in components). Am I missing something?...

"Fast Refresh" messing with my WebSocketServer in Next.js development

I got my websockets up and running in tRPC + Next.js with this code: ```js import { WebSocketServer } from 'ws' import { applyWSSHandler } from '@trpc/server/adapters/ws'...

t3-turbo

Hey anyone know how to integrate clerk into t3-turbo app

avoiding used more hooks than previous render

I understand whats causing the error in my code, im checking if id is defined before calling useQuery as it requires it to be passed in. ```typescript const Update = () => { const router = useRouter()...
Solution:
Solution pass enabled: condition in useQuery options ```ts procedures.readOne.useQuery({ id: id as string }, { enabled: id !== undefined })...

How would batching result in a single database query?

On the httpBatchStreamLink docs it says that multiple query calls could result in a single database query. How would that work? Should you expect the passed input to possibly be an array to allow for this?
After that, you can make use of batching by setting all your procedures in a Promise.all. The code below will produce exactly one HTTP request and on the server exactly one database query:
After that, you can make use of batching by setting all your procedures in a Promise.all. The code below will produce exactly one HTTP request and on the server exactly one database query:
...

TS error cause Query is not returning correct type to the client!

So Ive build a query which return a type called Employee, for example. on my client I've props which are expecting the same type imported from server but after calling the query on the client the data is coming without the "cast" of Employee but an object of the properties of it. Now my typescript is screaming saying "Type {...props from Employee} is not assignable to type 'Employee'." ...

Typescript helper for router output

is there a helper to do this better? Get the output for a certain route? Or is this the way to do it? ```ts import type { AppRouter } from "$lib/api/root"; ...
Solution:
is there a helper to do this better? Get the output for a certain route? Or is this the way to do it? ```ts import type { AppRouter } from "$lib/api/root"; ...

Am I able to use "multer" with trpc?

Im currently trying to implement file uploads within a T3 app using S3. I am following along with a youtube tutorial (https://youtu.be/eQAIojcArRY?t=306) as this is a new area for me and I am unable to translate how I could use multer with my current stack. If there is a way, how do I do it? If not, what are some alternative solutions? For those unaware, the T3 stack includes - NextJS - tRPC - Prisma...

Losing type inference in vs-code

Hey, I'm having quite some trouble with type inference today. I create my client inside of function that returns it with ```ts...

How would you implement basic auth session tokens with tRPC?

I'm building a hobby app which requires basic auth. I'm used to use express and express-session along a SQL database (for the user data) and Redis (for the session data) to achieve that very easily, but I'm interested in learning tRPC. My app is built in Next.js as a monorepo, and I would like to NOT implement JWT for authentication, just plain old session tokens. I'm thinking in implementing my own version on express-session for tRPC, but that sounds dangerous as I'm not that familiar with the technology or with backend code in general. What would you suggest to keep it simple? I don't want to rely on external services like auth0 or firebase, but keep everything in my own server. This is a hobby app and it's not going to have a lot of active users....

Example for tRPC, stable version, with RSC

Hi This may be a stupid question... The readme of the experimental example mentions
Note You can already use tRPC with app directory, by:...

Dynamic return type

Is there any way to have dynamic return type with tRPC? Simple example: If I provide x: true on body, let me send number, otherwise string. ...
Solution:
Is there any way to have dynamic return type with tRPC? Simple example: If I provide x: true on body, let me send number, otherwise string. ...

Sometimes invalidate not work...

hello sometimes invalidate method does not work in onSuccess anyone same? using NextJS, pnpm...
No description

trpc client request size limits?

I am sending a pretty sizable request and am seeing
[TRPCClientError: JSON Parse error: Unexpected token: <]
[TRPCClientError: JSON Parse error: Unexpected token: <]
...

Make tRPC return Bad Request on Zod validation error?

As the title says, how can I make tRPC return a proper error message, like a Bad Request, when there is a Zod validation error?

Using proxyClient in vercel edge function

Hey guys, i want to call my trpc apis inside vercel edge functions. Edge runtime does not have all supported libraries so i need to use a lot of low level javascript apis. Right now i can do everything with the fetch api. For typesafety i wanted to use vanilla javacsript proxy. I created the proxy and wanted to call the api but keep gettings json errors ? Is the vanilla proxy client able to run on edge runtime ?...

cookies not being set in procedure

This is all the code for setting my cookie ```js import { publicProcedure, router, userProcedure } from '$lib/trpc/t' export const user = router({...