nestjs-session: [BUG] Middleware not called while using nestjs-session with @nestjs/graphql
What is the current behavior?
I don’t succeed to make this package work with @nestjs/graphql
.
When I call a REST route, it’s working well, and the session(req, res, next)
middleware (from express-session
) is well called.
But when I call the GraphQL entrypoint, the middleware is not called at all.
I’ve digged deep in nestjs source-code, but I don’t know really where to look.
Even with a forRoutes: [{ path: '/*', method: RequestMethod.ALL }],
this change nothing.
What is the expected behavior?
In practice, the consequences are that no cookie is defined in the GraphQL response, and so, the sessions don’t work.
Please mention other relevant information such as Node.js version and Operating System.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (5 by maintainers)
I’m using redis to manage the session. It’s really odd because the session in my controllers works great. However, with graphql, every request creates a brand new empty session.
Session in Controllers
Session in Graphql
Notice that only the first session is used in the controller, but all the rest of the sessions are created new with every graphql request.
So, I’ve built a simple module to do the init and session, and it works well. So I think the problem is not from your side, but from @nestjs/passport side who should integrate a way to register these middlewares.
I’ll try to find the time to build an example but it’s quite a big work, so I admit I’d hope you had an “intuition” about the problem before :p
I’ll let you know !