How to access Response object in NestJS GraphQL resolver

Viewed 1295

How can I access pass @Res() into my graphql resolvers?

this doesn't work:

@Mutation(() => String)
  login(@Args('loginInput') loginInput: LoginInput, @Res() res: Response) {
    return this.authService.login(loginInput, res);
  }
1 Answers

@Res() is for HTTP Requests. To access to res object you'd need to first make sure it is added to the context for graphql by using context: ({ req, res }) => ({ req, res }) in the GraphqlModule's options, and then you can use @Context() ctx to get the context and ctx.res to get the response object

Related