【发布时间】: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