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:
The problem I have with this, is that it looks horrendous and needs to be manually adjusted everytime the schema changesSolution:Jump to solution
```ts
const includableFields = z.enum([
"comments",
"readingProgress",
"novelInsights",...
5 Replies
So, my question basically is, how you usually do this. Do you just allow all strings to be passed and try-catch possible errors being thrown, or am I severly misunderstanding how to use tRPC.
why not make items of
includableFields
booleans ?yea i'd keep the include an object and just passthrough
Solution
Sorry it took me so long to respond. I've read your answer after you've posted it, but I completely forget about it because I was immersed into something else. Just wanted to say thanks.