如何在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获取响应对象


以上是如何在NestJSGraphQL解析器中访问Response对象的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>