Papooch / nestjs-cls

A continuation-local storage (async context) module compatible with NestJS's dependency injection.

Home Page:https://papooch.github.io/nestjs-cls/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Setup in a different enhancer than mounting?

Faithfinder opened this issue · comments

I would like to mount CLS in middleware, since it guarantees one mount per request context (in graphql if you use interceptor, the context will be per resolver instead).

However, middleware doesn't yet have access to user and stuff, since that gets resolved in Guards. So I would like to add that in an interceptor (and not directly in a guard, for separation of concerns). Setting up such an interceptor myself would be kinda trivial, but I wonder if it's a good enough case to include in the library anyway?

UPD: not that trivial, since a global interceptor for setup can't inject ClsService, lol. Oh well, there are workarounds

Actually, there's a system in place that guarantees common CLS context across all resolvers within one request if you use the ClsInterceptor with GQL. It got implemented just recently in reaction to this issue: #53