如何访问 NestJS GraphQL 解析器中的 Response 对象

How to access Response object in NestJS GraphQL resolver

如何将 @Res() 传递到我的 graphql 解析器中?

这行不通:

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

@Res() 用于 HTTP 请求。要访问 res 对象,您首先需要确保通过在 GraphqlModule 的选项中使用 context: ({ req, res }) => ({ req, res }) 将其添加到 graphql 的 context,然后您可以使用 @Context() ctx 获取上下文并使用 ctx.res 获取响应对象