tRPC

T

tRPC

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

Join Server
SShooe#64684063/1/2024

Type 'QueryClient' is missing the following properties from type 'QueryClient': queryCache, mutation

I'm getting this error:
Type 'QueryClient' is missing the following properties from type 'QueryClient': queryCache, mutationCache, logger, defaultOptions, and 4 more.ts(2740) context.d.ts(48, 5): The expected type comes from property 'queryClient' which is declared here on type 'IntrinsicAttributes & TRPCProviderProps<CreateRouterInner<RootConfig<{ ctx: object; meta: object; errorShape: DefaultErrorShape; transformer: DefaultDataTransformer; }>, { ...; }>, unknown>'
...
FFinn3/1/2024

How to properly handle Prima selects/includes with tRPC?

Hello, my understanding of optimizing procedures to be the most efficient would be to enable one procedure to handle different use-cases. So I'd like a procedure like getById to take a list that allows all possible attributes from the prisma models and optionally a list of models to include. Currently, I define a list of all attributes on a global level for each router, that includes all includable Fields (I'd then do the same for the selectable fields). But that - even with just the includable fields - ends in this madness: ...
BBillyBob3/1/2024

onSuccess with createTRPCProxyClient

What is the best way to setup onSuccess with createTRPCProxyClient?
Ppietro 🌴3/1/2024

trpcNext from client for testing

Hi guys, I have created a client that uses a mock database for testing. Can I create a context and trpcNext to use in my Components and test the whole component together with the backend but without creating the server? Thank you for your help ...
Ppupo2/29/2024

Missing content type header for mutations leads to 405

Im migrating my app from Next Pages Router to App Router. I implemented the new trpc wrapper as explained here and everything seems to be working as I expected, except mutations. Mutations fail on preflight with a 405 (local development, same server). The only difference between the "before" and "after" of the migration (As well as the only difference to queries) is that mutations are missing a content-type: "json" (See attached). Any idea how I can fix this?...
Solution:
Ok .... so for prosterity the issue was in the server API route. it was missing a POST handler. Fixed version: ```tsx import { fetchRequestHandler } from "@trpc/server/adapters/fetch";...
No description
Jjman2/29/2024

Is there any way to temporarily disable mutations?

My goal is to move into a read-only mode temporarily. I'm thinking anything could be fine as a short term solution. 1. Throw an explicit error when mutations try to be called 2. Procedure not found error...
SSongkeys2/29/2024

After upgrading to 11.0.0-next-beta.300, every request throws zod error

I didn't do anything but upgrading the trpc, and the error throws:
{"issues":[{"code":"invalid_type","expected":"object","received":"undefined","path":[],"message":"Required"}],"name":"ZodError"}
{"issues":[{"code":"invalid_type","expected":"object","received":"undefined","path":[],"message":"Required"}],"name":"ZodError"}
...
No description
Nnotoriousfeli2/28/2024

Setting up tRPC for next.js with edge AND serverless functions

tldr: I am trying to build an app that uses both edge AND serverless functions by creating separate endpoints. Has anyone ever done this successfully? I am building an app that runs openai-API-requests and is connected to a Planetscale mySQL-DB with a prisma-layer (t3-setup). All functions are serverless. I am facing timeout issues on the openai-requests, since they are taking quite long. I am trying to switch all openai-functionalities to run on the edge. This means longer timeout-limits on vercel and the ability to stream the response. All the other functions need to remain serverless, since they use prisma, which isn't available on the edge. What I have tried so far:...
Mmenna2/28/2024

Hello i am using trpc open api but there is an issue regarding using z.optional() however in the lib

Hello i am using trpc open api but there is an issue regarding using z.optional() however in the lib it is used optional
LLunaCrafts2/28/2024

CreateCaller with React-query

Hey guys. Is it possible to combine createCaller approach with React-query? I figured out that react-query needs HTTP/WS link to work at all. Do you have any idea how to combine them?
ASAugustin Sorel2/27/2024

Beginner: form field error handling ?

hey guys, I have a question regarding error handling with trpc. How could I specify a form field in the error that I am returning from the backend ? The doc page does not explain this. The way I do it is by checking for a specific code. But surely this wouldn't scale very well for a large form ? ...
Rrik2/26/2024

Zod.enum makes my tRPC explode

I'm having an issue with what appears to be circular dependencies. My problem is that I'm not sure what is being parsed that is causing the issue. I don't see a circular dependency. I think that the error message is not indicating the problem line correctly, as I just added more debug to the file and the error message didn't change. Is there a way to switch on more debug logging in v10 on the server side, so that I can see what's happening more? The error message:...
MMerlin2/26/2024

React type errors because of backend

Hello, I'm using tRPC in React and it's working fine generally. However, WebPack always finds something to complain about that is in my backend where I import AppRouter from and I haven't found a clean way yet to fix this. As you see in the screenshot, it complains about some fastify types. Those errors aren't present on the backend side and I could just install the types in my react repo too, but that does feel really dirty. Is there a nice way to handle this? Thanks in advance. And generally spoken, tRPC is the best API layer I have ever used. I come from ApolloGraphQL which is kind of nice, but also always a pain to set up....
No description
MMugetsu2/26/2024

Value attached to all queries

Is it possible to add a value the all queries so its preset within every procedure call on the client?? Lets say I have a cookie which Is determied on the server and I want it to be added to every response or the trpc query calls. Is it possible to add it in a single place rather adding it in every procedure I make making it very prone to error because I can forget it ?
Rreepicheep2/25/2024

Invalidating query cache irrespective of query params

Hey is it possible to invalidate a query cache without providing parameters? I have a query for example with filter parameters and each filter produces a different cache, but from elsewhere I want to invalidate all of the caches involved in that query. I'm using tRPC 10.38.2 (can't upgrade right now)...
KKimblis2/25/2024

Sentry integration

Hello. I'm using trpc + fastify approach. I need a proper error loggin so I added fastify sentry, which works fine and logs the errors, however i'm missing some context- trpc data sent for the query/mutation, user information and etc. I would like to add that. Anyone had to deal with this before? So far can't find a decent solution for this, especially for retrieving the input.
TMOTeodorant Master Of Nonsense2/24/2024

In my NEXTJS app can read value next-auth session in localhost ,but not when deployed to Vercel

I have several procedures in my TRPC router (https://github.com/Teodorant1/nighthawk_repair/blob/master/server/index.ts), it seems to be bricking in the ones where I am awaiting the session const session = (await getServerSession(authOptions)) as Session; seems to be the line of code that is bricking it on Vercel...
TTOBII2/24/2024

WebSocket Authentication: Cookie missing

Hi community 👋 I'm currently trying to integrate the wsLink, and I've noticed that cookies are not automatically sent during initialization (first request). What could be the reason for this? My website runs under the URL http://localhost:3000, and the web server under http://localhost:3001. Does it have something to do with CORS? ...
NNeoBean2/23/2024

Client request headers with createTRPCProxyClient

Simple proxy client, following the documentation ```ts import { createTRPCProxyClient, httpBatchLink } from '@trpc/client' import SuperJSON from 'superjson' // .. other imports...
YY0z642/23/2024

Get auth token from context when defining httpBatchLink

Im setting up an ApiProvider for react query and I want to get the authorization token for the Authorization header from trpc context since my session is stored there. My api is defined here ```typescript ...
Next