如何在NestJSGraphQL解析器中访问Response对象
如何访问传递@Res()到我的 graphql 解析器?
这不起作用:
@Mutation(() => String)
login(@Args('loginInput') loginInput: LoginInput, @Res() res: Response) {
return this.authService.login(loginInput, res);
}
回答
@Res()用于 HTTP 请求。要访问res对象,您需要首先确保context通过context: ({ req, res }) => ({ req, res })在GraphqlModule's 选项中使用将其添加到for graphql ,然后您可以使用它@Context() ctx来获取上下文并ctx.res获取响应对象