T
tRPC

❓-help

Multiple Clients/Services In tRPC Context

Iisaac_way1/28/2023
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
Nnlucas1/28/2023
Do what works for you, injecting via context can make testing a lot easier though, even if it means writing your own wrapper interfaces
Iisaac_way1/28/2023
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
Nnlucas1/28/2023
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

Looking for more? Join the community!