why do we add prisma in ctx instead of using import ?
As stated in the doc
but there is no explanation
Why is it better ?
What is the difference ?
5 Replies
It’s mainly so u dont have to setup and initialize prisma or import it in every router. Instead the ctx option allows keeping all these sort of things shared.
Ok but if my routers become more complexe and I want to externalise it in services files, can I import it there or should I "drill prop" prisma in ctx ?
Could you give an example of what you mean?
i think the ctx is exposed to make it easier group up such shared services in one place, but there isn't any requirement to use it. i would say that the better way would be ctx because that way u dont have dup imports
its done this way so that you know you have the same instance in every procedure, better dx of having it on ctx, and lets you monkeypatch it for testing
but in terms of just the procedure itself it doesn't make a difference