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订阅?
发布于 2021-07-01 16:39:09
是否可以使用Apollo-Server的pubsub来触发Type-graphQL订阅?
这是相同的PubSubEngine实现。你检查过文档了吗?https://typegraphql.com/docs/subscriptions.html#using-a-custom-pubsub-system
https://stackoverflow.com/questions/67938955
复制相似问题