tRPC

T

tRPC

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

Join
Aastro5/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
VVinnie5/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...
Vvildantursic5/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?
T'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?
WWiznet5/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?
PPeform5/10/2024

uploading image via trpc endpoint

Hello, is there any example for uploading an image to a trpc endpoint?
Wwleistra5/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...
Sskagedal5/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?...
GLGabriel 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...
LLuke5/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!...
Bbill925/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,...
Bb5/8/2024

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.
Jjonathanj5/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....
CCatlike5/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()...
Kkgni5/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....
JJay_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
Ccrummy5/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?
KKranga5/4/2024

All my mutations are failing due to an empty body after upgrading to 11.0.0-rc.362

TRPCError: JSON Parse error: Unexpected EOF\n at new TRPCError (/mnt/c/Users/Ángel/IdeaProjects/back/node_modules/.pnpm/@trpc+server@11.0.0-rc.362/node_modules/@trpc/server/dist/unstable-core-do-not-import/error/TRPCError.mjs:51:12)\n at <anonymous> (/mnt/c/Users/Ángel/IdeaProjects/back/node_modules/.pnpm/@trpc+server@11.0.0-rc.362/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/contentType.mjs:23:30)\n at processTicksAndRejections (:12:39) I have tried debugging in http/contentType.mjs and I found the request body is coming empty even if it shows a body on the browser devtools. Originally happened after upgrading a lot of rc.xxx versions at once but I pinpointed it on rc.362. The mutation works fine on rc.361 even using rc.364 on the client....
GG$Row5/3/2024

How to get data type from onMutate function in useMutation

I'm doing optimistic updates using the technique which is documented here https://tanstack.com/query/latest/docs/framework/react/guides/optimistic-updates . I found that I'm using the same queries in multiple spots and want to extract the update code so that I don't have to copy and paste. I can't figure out the type of the data parameter in the onMutate function. ``` api.task.createTask.useMutation({ onMutate: async (data) => {}})...
Next