isaac_way
isaac_way2y ago

Multiple Clients/Services In tRPC Context

I know it's typical to pass around the prisma client in the trpc context, is the same true for other services/clients as well? IE a twilio or sendgrid client
3 Replies
Nick
Nick2y ago
Do what works for you, injecting via context can make testing a lot easier though, even if it means writing your own wrapper interfaces
isaac_way
isaac_way2y ago
yeah I'm really enjoying injecting via context, just converted a small project to this approach. Passing in all the clients seems to be pretty straightforward and has made it a lot easier to implement debugging mechanisms and to write tests. I'm thinking it was a good choice... Just was curious if it was something others were doing. Haven't needed to write wrapper interfaces yet, seems to be good so far just passing clients directly
Nick
Nick2y ago
You can also build up context via middlewares, so if you end up with a huge context and most of it isn't needed in each router/procedure, you can compose together what you do need