sh032y ago

How to organise output types?

I'm having a hard time trying to figure out what the best way to organise output types and I was wondering if you guys/gals have any tips. Things I'm having a hard time with: - Some output objects that may be returned in multiple places (e.g. users.get, users.getAll, posts.get (as, etc.) all need the same extra fields that can't come directly from Prisma (e.g. "the last post from the user" or "whether one can delete this user"); what's the best way to extract and reuse the logic for these fields? - How to mask output types (e.g. make sure that I don't return User.passwordHash ever) - How to express calculated fields (e.g. fullName = firstName + lastName) - How to reuse output types in nested components (e.g. components that don't directly useQuery) Thanks 🙏
3 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Alex / KATT 🐱
You can also do a middleware for that second one to make sure the result never returns any blocklisted keys also looks like your'e looking for prisma validators here's how ot infer example of a prisma validator calculated fields i usually do with some like reused mapToUser()-style pure functions but prisma is soon releasing prisma client extensions to help with that
sh032y ago
Gotcha thanks