首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PubSub的不同实现可以相互协作吗?

PubSub的不同实现可以相互协作吗?
EN

Stack Overflow用户
提问于 2021-06-11 22:36:53
回答 1查看 42关注 0票数 0

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

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

代码语言:javascript
复制
    @Resolver()
    export class TransactionsSubscription {
      @Subscription({
        topics: ({ context: { account } }) => {
          return account.id;
        },
      })
      newNotifications(
        @Root("data") data: Notification,
      ): Notification {
        return data;
      }
    }

这是我的TypeORM事件订阅者:

代码语言:javascript
复制
    @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订阅?

EN

回答 1

Stack Overflow用户

发布于 2021-07-01 16:39:09

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67938955

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档