tRPC

T

tRPC

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

Join
Luka
Luka5/17/2024

how do you guys start a standalone trpc server?

settings up ts alone and express afterwards seems a bit of a hassle. wanna know if there is an easy way of doing it
Jonathan
Jonathan5/16/2024

TRPC completely broke

I have a project I haven't touched in only about a week, it was working and now every request over TRPC is broke. I have tried everything I can think of and I get responses like the attachment Here is part of my package.json ```json...
astro
astro5/13/2024

trpc + server actions

i wanted to use trpc without react query like with next's server actions but using a relative url throws error ```tsx import React from "react"; export default function ProjectList() {...
No description
Vinnie
Vinnie5/12/2024

Infer context from procedure after middleware

I'm using trpc version 10 on pnpm. I I have my handler functions in separate files from the routers themselves. I'm looking to type the context correctly based on the procedure the handler is used with....
Solution:
Okay I didn't come up with a direct solution, but I did solve it in a different way. Instead of just having the handler functions be in separated files. These -> .mutation(handlerFunc) I moved the whole creation of the procedure into seprate files. This way you can put the handler function directly into the .mutation call. This way the options (so also the context) are correctly inferred and the need to import the Context type becomes unnecessary. ```ts...
vildantursic
vildantursic5/11/2024

Why is Uint8Array converted in object when passed as input in `.mutate({ img: u8 })` - v11

I passed Uint8Array as input for file saving but when I log it on API (trpc function) it is shown as object of same array not array itself. Why is that?
'tonyyprints'
'tonyyprints'5/11/2024

Error: TRPCError: A non-domain error occurred

Been just randomly getting these. Has anyone else and do u know what it could be caused by?
Wiznet
Wiznet5/11/2024

GraphQL Mutation API Design

may be a dumb question. I'm new to graphql type api design coming from a rest controller api. Now often times with our rest api well have one service method to patch an object from a given patch. It seems like this may not be the way to go with graphql? Instead writing specific actions. Aka 'patchObjectName' instead of just 'patchObject' which takes a patch object. Is this correct design?
Peform
Peform5/10/2024

uploading image via trpc endpoint

Hello, is there any example for uploading an image to a trpc endpoint?
wleistra
wleistra5/10/2024

Unexpected end of JSON input error after upgrade to v11.0.0-rc.366 from rc.359

We updgraded from version 11.0.0-rc.359 to 11.0.0-rc.366 and now see BAD_REQUEST error being returned for mutations which worked fine before to upgrade. Stack: `TRPCError: Unexpected end of JSON input...
skagedal
skagedal5/10/2024

How can I get lint warnings for onSuccess/onError?

Maybe this isn't exactly a trpc question, but I'm thinking someone here would know. I would like to keep our project prepared for the transition to tRPC v.11 and the changes that come because of TanStack Query v.5.x. We have a lot of usage of onSuccess/onError in useQuery. So now I bumped tRPC to the latest 4.x (4.36.1) where they are marked as deprecated. I then realized that our lint setup does not warn for deprecations, so I added eslint-plugin-deprecation and enabled it per instructions. I then got a bunch of other deprecation warnings, so the plugin seems to be working, but nothing on these onSuccess / onError callbacks. Is this supposed to be working this way, or is there another way I could make it work?...
Gabriel Lucena
Gabriel Lucena5/10/2024

How can I add React to SST's TRPC example?

SST recently release an example on how to deploy TRCP to AWS, it's pretty cool! but I'm wondering how can I add react to it's client so I have both worlds: Repo: https://github.com/sst/ion/blob/dev/examples/aws-trpc/client.ts...
Solution:
who would've guessed that I could built it just reading the docs: https://github.com/gnllucena/trpc-sst...
Luke
Luke5/10/2024

tRPC useQuery with skipToken

I am trying to implement a useQuery which only happens once. I haven't been happy with setting enabled so something like enabled: !!foo as it'll still refetch, etc (and yes I know you can disable certain refetches, but that's not the goal here). I found a supported, type-safe solution on the tRPC docs (https://trpc.io/docs/client/react/disabling-queries).
But... following their example nearly identically doesn't work for me....
Solution:
Nevermind, this idiot wasn't on tRPC v11. Just did the upgrade, was pretty painless. Shoutout to the tRPC team. I'll leave this up incase anyone else experiences a similar issue and goes down the rabbithole. UPGRADE TO V11 TO GET SKIPTOKEN TO WORK!...
bill92
bill925/9/2024

Error calling middleware

I'm getting an error trying to test out some pretty basic middleware. This is my code ```ts export const createContext = ({ req,...

Mutation returning a long URL is being cut off

I have an authentication URL for an oauth2 provider that returns a long URL due to scopes being added. The server returns a cut-off version of it to the client. Not sure why.
jonathanj
jonathanj5/7/2024

TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize.

I have tsc complaining about my root app router type being too large when using --declarations. There was a ticket from 2022 about this, but it seems to have been closed as solved. There are some Zod tickets about this too, but unfortunately they don't provide solutions that are viable (e.g. disabling --declaration is not viable for me.) It seems like this is caused by having a large app router, where "large" means it has a bunch of endpoints, and the total combination of those endpoints' input and output validators (using Zod schemas) go above a certain threshold. I can solve it by strategically adding explicit types to some of the query/mutation handler function definitions, but it's a bit odd....
Catlike
Catlike5/7/2024

useUtils changes at every render and causes useEffect to be called continuously

I have a context provider where I need to invalidate a query on unmount. So I wrote this piece of code: ```ts const utils = trpc.useUtils(); useEffect(() => ( () => utils.user.example.invalidate()...
kgni
kgni5/6/2024

tRPC context, NeonDB & WebSockets

Hi there! I'm currently working on a serverless app with the following tech stack: Cloudflare Workers, Hono, tRPC, DrizzleORM & NeonDB....
Jay_Ohhh
Jay_Ohhh5/6/2024

Can't access mutate utils by createTRPCQueryUtils

I can use any query utils by createTRPCQueryUtils but not mutate utils. Here is my code...
No description
crummy
crummy5/6/2024

gzip responses

Is it possible to have trpc gzip its responses? Or do I need to do this somewhere else, like an intermediate webserver?
Next