title: How can I set a session key from inside a GraphQL resolver in NestJS?
body: <p>I'm discovering Nest.js and I want to setup a cookie based authentication system with GraphQL.</p>
  
  <p>I already installed express-session middleware, here is the configuration:</p>
  
  <p><strong>main.ts</strong></p>
  
  <pre><code> app.use(
      session({
        store: new redisStore({
          client: redis
        } as any),
        name: 'qid',
        secret: SESSION_SECRET,
        resave: false,
        saveUninitialized: false,
        cookie: {
          httpOnly: true,
          secure: !isDev,
          maxAge: 1000 * 60 * 60 * 24 * 7 * 365
        }
      })
    )
  </code></pre>
  
  <p>it works fine because when I do :</p>
  
  <pre><code> app.use((req: any, res: any, next: any) =&gt; {
        // Debug purpose
        req.session.userId = '42'
        next()
      })
  </code></pre>
  
  <p>The cookie is added.</p>
  
  <p>Right now I have two mutations, <strong>register</strong> and <strong>login</strong>.
  In the login mutation (or in the userService), after I found a user I want to do something like <code>req.session.userId = user.id</code> but I can't find a way to do this.</p>
  
  <p>I tried to add <code>@Context() ctx</code> to my mutation.
  If I console log ctx, it contains everything I expect (req.session.id for example)</p>
  
  <p>But if I do <code>ctx.req.session.userId = 'something'</code>, the cookie is not set!</p>
  
  <p>Here is my mutation:</p>
  
  <p><strong>user.resolver.ts</strong></p>
  
  <pre><code>@Mutation('login')
    async login(
      @Args('email') email: string,
      @Args('password') password: string,
      @Context() ctx: any
    ) {
      console.log(ctx.req.session.id) // Show the actual session id
      ctx.req.session.userId = 'something' // Do not set any cookie
      return await this.userService.login(email, password)
    }
  }
  </code></pre>
  
  <p>I am totally lost and I really need help, I'd love to understand what's happening. I know I'm probably doing this totally wrong but I'm new to both Nest and GraphQL..</p>
  
  <p>Thank you guys...</p>