How is inner context persistent if we call 'createContext' for every batch?
As per title. According to the docs, inner context doesn't depend on the request, and is useful for persistent objects like your database connection. However, given that
createContext
is called for every request, I fail to see how calling createInnerContext
inside of createContext
provides persistence?
Docs that I read: https://trpc.io/docs/server/context#inner-and-outer-contextContext | tRPC
Your context holds data that all of your tRPC procedures will have access to, and is a great place to put things like database connections or authentication information.
1 Reply
createInnerContext isn't about persistence, it just doesn't depend on something like a request object. You don't need a createInnerContext if you aren't doing stuff like integration tests or you need to create a caller where you don't have access to the request object.
You can just put your db connection in the createContext if you want to, createInnerContext isn't neccessary