tRPCttRPC
Powered by
sh03S
tRPC•4y 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.get
,
users.getAll
users.getAll
,
posts.get
posts.get
(as
Post.author
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
User.passwordHash
ever)
- How to express calculated fields (e.g.
fullName
fullName
=
firstName
firstName
+
lastName
lastName
)
- How to reuse output types in nested components (e.g. components that don't directly
useQuery
useQuery
)

Thanks 🙏
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

How to organise reusable functions
sh03Ssh03 / ❓-help
3y ago
client unable to infer output types
advancedAadvanced / ❓-help
2y ago
Router output types not mapping?
hashwarpHhashwarp / ❓-help
2y ago