T
tRPC

❓-help

Help with inferring output

ZZion11/1/2023
return ctx.prisma.product.findMany({
include: {
price: {
select: {
contractor: group === "CONTRACTOR",
customer: group === "CUSTOMER",
frequent: group === "FREQUENT",
professional: group === "PROFESSIONAL",
vip: group === "VIP",
visitor: group === "VISITOR",
},
},
},
});
return ctx.prisma.product.findMany({
include: {
price: {
select: {
contractor: group === "CONTRACTOR",
customer: group === "CUSTOMER",
frequent: group === "FREQUENT",
professional: group === "PROFESSIONAL",
vip: group === "VIP",
visitor: group === "VISITOR",
},
},
},
});
I have the following return and I want to infer the types of a single item, before I added the include bit the code worked, but now it gives me an error, how to set it up correctly?
No description
ZZion11/1/2023
No description
FRFouad Raheb11/1/2023
Prisma won't properly infer types with a condition in select input You better create a separate prisma findMany for each group type
ZZion11/1/2023
I thought this might be the problem but even if I just have a price: true the error is the same, I dont need it to tell me what pricing is there, I just dont want it sent to the user, it pretty much just have every price as number | undefined which is fine by me the issue is that I need to turn it to a singular item from the array and its not working when having that include, with or without the coditions
TSTamás Soós11/1/2023
Does this help? Prisma has some tools to infer the types of select, include, etc..., I also had a similar use case. Sorry, forgot to address the conditionals. I found a bug report here

Looking for more? Join the community!

Recommended Posts
Would you recommend tRPC’s usage in this case?So we have two applications, one existing, one about to be started. These two applications will talkHow to limit payload size?Is there a way to limit the payload size? E.g., if a particularly large JSON payload is sent to the Next.js app directoryHi. I have been able to set up tRPC with the app directory in Next.js. It was a frustrating experientrpc errorTrpc not working in next js 14 app router. Please help me to resolveFeature or happy accident: error message from `cause` being used as TRPC's error messageWhen a procedure throws a TRPC error with no message, it turns out that if the thrown error has a caWhen error in tRPC route, the error message is vaugeThere are no line numbers when a runtime error happens in a tRPC route. Surely I am missing somethinHow to have 2 separate trpc clients for http and websockets?I'm trying to have a setup where I can use trpc with 2 separate clients, one for normal HTTP requestHow to configure context for a standalone server?Are there any examples out there on how to set up context for a standalone server? The docs do incluDocs hard to follow with so much `next` codeNot having a great experience with the docs. There are many examples that use `next`, making it hardadding information to the QueryKey that is not part of the procedure inputwe have the situation that we have our trpc routes read some specific information from the browsesr How to make typed error responses in the context of a specific query?Each query has a typed (success) response, although it seems all queries have a shared type for the What's the negative code returned in error responses?What's the negative error code returned in errors responses and how is it meant to be used by the clTRPC File as InputHi can someone pls help me: https://stackoverflow.com/questions/77381516/nextjs-trpc-file-as-input`refetchOnWindowFocus` with RSC?Hi. Is there any way to have `refetchOnWindowFocus` work with server components? Seems like it onlyMulti useSubscription with trpc react -query integration failed to find second subusing trpc in nx monorepo, node version is 20 with yarn. backend is using trpc with express integratIs there any easy way to create a Type for a trpc routerI want to publish a set of trpc api client to npm, which will be used by my customer directly. But iTRPC with Nextjs 13 App RouterIm trying to implement TRPC with my already existing Nextjs 13 App to get typesafe API's. I've managSecurity: DDOS attack prevention for open endpoints tRPCSo we are building an application and got multiple trpc endpoints associated with it, some of them a