sh03S
tRPC3y ago
8 replies
sh03

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 Post.author), 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 🙏
Was this page helpful?