tRPCttRPC
Powered by
isaac_wayI
tRPC•3y ago
isaac_way

createCaller Dependency Injection in Middleware ctx ?

createCaller
createCaller
makes it really easy to inject dependencies via anything that's created during the
createContext
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
twilioClient
that is only used by my
authorizationRouter
authorizationRouter
, it could make sense to supply that dependency via middleware instead of the
createContext
createContext
function.

Is there anyway to inject dependencies into a middleware versus just the root
createContext
createContext
?
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Deprecated createCaller alternative?
HichHHich / ❓-help
13mo ago
CreateCaller with React-query
lunacraftsLlunacrafts / ❓-help
2y ago