You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have not found anything in the docs that says this should not work or how to achieve this differently, so if this is expected or just works differently please let me know. I think this may be a similar issue as discussed in #22, but it was never reproduced or fixed.
Yeah, @Ctx() does work in resolvers. Maybe my example wasn't the best, because I am trying to access the Request/Context not within a resolver itself, but just generally within a Nest provider.
In my application, I have a service that must be a singleton per request that is then shared between all resolvers as well as some middlewares via Nest's dependency injection. Within that singleton, I need access to the request headers, thus I tried to inject the context there. As mentioned, following the examples from @nestjs/grapqhl this works quite well, but I haven't been able to make something like this work for typegraphql-nestjs. I could probably somehow work around this, but I think ideally it would work through Nest's dependency system.
It seems that
@Inject(CONTEXT)
is not working withtypegraphql-nestjs
the way it does for@nestjs/graphql
.I am trying to do something like this:
With an app module that looks like this:
However,
context
is just undefined. A similar example using@nestjs/graphql
however does work, mostly following https://docs.nestjs.com/fundamentals/injection-scopes#request-provider.I have not found anything in the docs that says this should not work or how to achieve this differently, so if this is expected or just works differently please let me know. I think this may be a similar issue as discussed in #22, but it was never reproduced or fixed.
Initially I was not sure myself where the issue comes from, so I have created a reproduction with both
typegraphql-nestjs
and@nestjs/graphql
here: https://github.com/ahilke/typegraphql-nestjs-inject-context.Thank you for your support!
The text was updated successfully, but these errors were encountered: