brand marke
brand marke

Reputation: 459

How to access Response object in NestJS GraphQL resolver

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);
  }

Upvotes: 5

Views: 3378

Answers (1)

Jay McDoniel
Jay McDoniel

Reputation: 70061

@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

Upvotes: 12

Related Questions