【问题标题】:How to send different subscription response based on condition in GraphQL (NestJS)?如何根据 GraphQL (NestJS) 中的条件发送不同的订阅响应?
【发布时间】:2021-03-27 11:39:54
【问题描述】:

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

【问题讨论】:

    标签: graphql nestjs publish-subscribe subscription


    【解决方案1】:

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

    文档中的示例:

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

    【讨论】:

    • 谢谢,这正是我要找的。​​span>
    猜你喜欢
    • 2021-01-29
    • 1970-01-01
    • 2017-08-09
    • 2021-11-09
    • 2022-08-22
    • 2020-01-30
    • 2020-11-14
    • 2021-04-10
    • 1970-01-01
    相关资源
    最近更新 更多