【问题标题】:Does the differents implementations of PubSub work with each other?Pub Sub 的不同实现是否相互配合?
【发布时间】:2021-08-28 12:17:58
【问题描述】:

apollo-server、apollo-server-express 和 Type-graphql 提供不同的 PubSub 实现,我一直在尝试使用 Apollo-Server 来触发使用 Type-graphql 完成的订阅。

这是我的 Type-Graphql 订阅解析器:


    @Resolver()
    export class TransactionsSubscription {
      @Subscription({
        topics: ({ context: { account } }) => {
          return account.id;
        },
      })
      newNotifications(
        @Root("data") data: Notification,
      ): Notification {
        return data;
      }
    }

这是我的 TypeORM 事件订阅者:


    @EventSubscriber()
    export class TransactionSubscriber implements EntitySubscriberInterface<Transaction>{
        listenTo(){
            return Transaction;
        }

        async afterInsert(event: InsertEvent<Transaction>){
            
            const account = await Account.findOne(event.entity.accountId);
            if (!account) throw Error("Invalid request");
            const notification = await NotificationRepository().createTransaction(account);
            pubsub.publish(event.entity.accountId.toString(), notification);
            console.log(notification);
        }
    }

我的问题是,是否可以使用 Apollo-Server 的 pubsub 来触发 Type-graphQL 订阅?

【问题讨论】:

    标签: graphql apollo-server typegraphql


    【解决方案1】:

    是否可以使用 Apollo-Server 的 pubsub 来触发 Type-graphQL 订阅?

    这是相同的PubSubEngine 实现。你检查过文档吗? https://typegraphql.com/docs/subscriptions.html#using-a-custom-pubsub-system

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-21
      • 2023-04-04
      • 2012-04-28
      • 2017-05-12
      • 1970-01-01
      • 2017-11-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多