如何根据 GraphQL (NestJS) 中的条件发送不同的订阅响应?

How to send different subscription response based on condition in GraphQL (NestJS)?

我想根据某些条件向客户发送不同的订阅响应。 withFilter 仅在满足条件时过滤并发送响应。我想根据某些条件发送两个不同的响应 - 基于条件的映射响应。有没有withMap之类的?

看起来您可以使用 resolve 属性 并映射其中的响应。

文档中的示例:

@Subscription(returns => Comment, {
  resolve(this: AuthorResolver, value) {
    // "this" refers to an instance of "AuthorResolver"
    return value;
  }
})
commentAdded() {
  return pubSub.asyncIterator('commentAdded');
}