tRPC

T

tRPC

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

Join

Best way of handling recurring events through NextJs and tRPC

Hi, I'm working on a project that handles users' "bonuses" and I need to refill these bonuses every day (so, every 24 hours). The easiest solution that I was thinking uses sql events so that they would modify the users table periodically. However, I'm using PlanetScale which doesn't support stored routines (triggers, procedures, events...). What's the easiest solution to this problem with this stack? Probably cron jobs are the way to go right? What tech would you guys suggest using?...

Are GET and POST the only HTTP verbs supported?

I’d like to add a procedure to handle HTTP PUT.

Query param in every client request

Hi ! Im wondering if there is a way to add query params in every request without creating a custom fetch. I only need to forward one query param from the browser URL to the trpc where my procedures are hosted plus the authorization header. Would like to avoid adding a fetch middleware system. thanks!...

Not able to implement websockets with trpc

```ts import { applyWSSHandler } from "@trpc/server/adapters/ws"; import ws from "ws"; import { createTRPCContext } from "./api/trpc"; import { appRouter } from "./api/root";...

type error

TS2322: Type '{ name: string; bio: string; location: string; website: string; }' is not assignable to type '(Without<UserUpdateInput, UserUncheckedUpdateInput> & UserUncheckedUpdateInput) | (Without<...> & UserUpdateInput)'.   Object literal may only specify known properties, and 'bio' does not exist in type '(Without<UserUpdateInput, UserUncheckedUpdateInput> & UserUncheckedUpdateInput) | (Without<...> & UserUpdateInput)'. index.d.ts(6234, 5): The expected type comes from property 'data' which is declared here on type '{ select?: UserSelect<DefaultArgs> | null | undefined; include?: UserInclude<DefaultArgs> | null | undefined; data: (Without<UserUpdateInput, UserUncheckedUpdateInput> & UserUncheckedUpdateInput) | (Without<...> & UserUpdateInput); where: UserWhereUniqueInput; }'
TS2322: Type '{ name: string; bio: string; location: string; website: string; }' is not assignable to type '(Without<UserUpdateInput, UserUncheckedUpdateInput> & UserUncheckedUpdateInput) | (Without<...> & UserUpdateInput)'.   Object literal may only specify known properties, and 'bio' does not exist in type '(Without<UserUpdateInput, UserUncheckedUpdateInput> & UserUncheckedUpdateInput) | (Without<...> & UserUpdateInput)'. index.d.ts(6234, 5): The expected type comes from property 'data' which is declared here on type '{ select?: UserSelect<DefaultArgs> | null | undefined; include?: UserInclude<DefaultArgs> | null | undefined; data: (Without<UserUpdateInput, UserUncheckedUpdateInput> & UserUncheckedUpdateInput) | (Without<...> & UserUpdateInput); where: UserWhereUniqueInput; }'
```ts editProfile: protectedProcedure.input(z.object({ name: z.string(),...
Solution:
TS2322: Type '{ name: string; bio: string; location: string; website: string; }' is not assignable to type '(Without<UserUpdateInput, UserUncheckedUpdateInput> & UserUncheckedUpdateInput) | (Without<...> & UserUpdateInput)'.   Object literal may only specify known properties, and 'bio' does not exist in type '(Without<UserUpdateInput, UserUncheckedUpdateInput> & UserUncheckedUpdateInput) | (Without<...> & UserUpdateInput)'. index.d.ts(6234, 5): The expected type comes from property 'data' which is declared here on type '{ select?: UserSelect<DefaultArgs> | null | undefined; include?: UserInclude<DefaultArgs> | null | undefined; data: (Without<UserUpdateInput, UserUncheckedUpdateInput> & UserUncheckedUpdateInput) | (Without<...> & UserUpdateInput); where: UserWhereUniqueInput; }'
TS2322: Type '{ name: string; bio: string; location: string; website: string; }' is not assignable to type '(Without<UserUpdateInput, UserUncheckedUpdateInput> & UserUncheckedUpdateInput) | (Without<...> & UserUpdateInput)'.   Object literal may only specify known properties, and 'bio' does not exist in type '(Without<UserUpdateInput, UserUncheckedUpdateInput> & UserUncheckedUpdateInput) | (Without<...> & UserUpdateInput)'. index.d.ts(6234, 5): The expected type comes from property 'data' which is declared here on type '{ select?: UserSelect<DefaultArgs> | null | undefined; include?: UserInclude<DefaultArgs> | null | undefined; data: (Without<UserUpdateInput, UserUncheckedUpdateInput> & UserUncheckedUpdateInput) | (Without<...> & UserUpdateInput); where: UserWhereUniqueInput; }'
```ts editProfile: protectedProcedure.input(z.object({ name: z.string(),...

Is there a way to use a more updated version of React Query in tRPC?

I'm trying to make sure that my tRPC is using the most up to date version of v4 but I don't know how I can make it use the most accurate version.

Express + tRPC: handle express errors from client

I currently have Express as backend and react on frontend. I want to migrate gradually to tRPC + react query. In order to do that I want to use the tRPC express middleware. I have tons of express middleware that I want to continue using for now, as well as error handlers....

queries running on server even though ssr is set to false

Queries are running on server side only despite the fact of setting ssr:false. Besides that, the queries are not running on client side....

TypeError: client[procedureType] is not a function

Has anyone encountered this error before? I'm trying to implement an adapter for Auth.js that can communicate with my backend via tRPC proxy client but I keep getting this error for some reason. This is how i call my route: ``` import { client } from "../data" export default function StorefrontApiAdapter() {...
Solution:
I used sveltekit so the setup was a bit different and backend was just normal medusa.js node application, the methods are just built like this on the client: ```ts function StorefrontApiAdapter(client: AuthClient): Adapter { return { async createUser(user) {...

TRPC -useInfiniteQuery() refreshes all data when an input is varied, how to use?

So I have a TRPC infiniteQuery: ``` const { data, fetchNextPage, hasNextPage } = trpc.server.getAll.useInfiniteQuery(...

Cannot get server response headers in browser

Hi, I am working on retrieving a specific server-sent header using a custom link with tRPC. This methodology works flawlessly during testing, but issues arise when I implement it in the client browser (the latest Chrome). In the browser, the list of headers only contains Content-Type and Content-Length. However, I can confirm that the header I am seeking is present as it's visible within Chrome's developer tools. ...

eventemitter not having any listeners on websocket

Hi, I have a app router project with TRPC but I created a websocket server alongside and a websocket client with the approuter and usecontext modified to work, the problem is that first of all (i don't know if this is normal) it says there are two connections when i load a page...

tRPC + cls-hooked

Hi, im trying to implement cls-hooked library with trpc's protectedProcedure, but it doesnt seem to work. The value i set inside the usedoesnt exists afterwards. When im doing the same outside of the usefunction, it works as expected. Any idea what am i missing?...

trpc + fastify POST request not working

I have a trpc mutation like this: ``` create: publicProcedure .input(z.object({ title: z.string() }))...

problem with useContext (likely easy fix)

```tsx function userCard( user: { id: string; name: string | null;...

I think i found an TRPC BUG

I am using TRPC With Fastify and bun (node.js alternative) if you try to call any .mutation route the application crashes. Router example: ```ts export const appRouter = router({...

useMutation in useEffect dependency array causes infinite loop

I had a very unexpected issue today when testing out some code. I have a simple sum method in tRPC that accepts two numbers and returns the sum. I can change both of the number seperately in state and trigger the mutation every time I see a change in one of the two values (not an ideal way of handling this, but it is test code 😉 ) ```typescript const [first, setFirst] = useState(0); const [second, setSecond] = useState(0);...

how does batching work?

My understanding is that batching basically combines multiple requests in a single network request, does this require any setup on my end? How does trpc know to wait for another request to batch it together?

Links vs Middlewares

What is the difference between a middleware and a link? These two seems to behave the same?

Setting up tRPC with Supabase and Drizzle

Hi! 😄 Is there someone that has any recommendations on how I should setup tRPC with Supabase Auth and Drizzle as ORM? I'm looking to Replace Clerk with Supabase in this repo but not sure if there's anything specific I should think about? ...