T
tRPC

createCaller Dependency Injection in Middleware ctx ?

createCaller Dependency Injection in Middleware ctx ?

Iisaac_way2/11/2023
createCaller makes it really easy to inject dependencies via anything that's created during the createContext function:
router.createCaller({ someClient: mockClient});
router.createCaller({ someClient: mockClient});
However, some times it makes sense to add dependencies in middlewares that are only used by a subset of the procedures. For example if I had a twilioClient that is only used by my authorizationRouter , it could make sense to supply that dependency via middleware instead of the createContext function. Is there anyway to inject dependencies into a middleware versus just the root createContext?

Looking for more? Join the community!

T
tRPC

createCaller Dependency Injection in Middleware ctx ?

Join Server