【发布时间】:2021-03-03 17:17:33
【问题描述】:
这是我第一次实现 GraphQL 订阅,如果这是一个明显的问题,请原谅。
我有一个使用Simple Subscription 方法的订阅,但不适用于SubscribeToMore 这是两个调用。
简单订阅:
$subscribe: {
onTransactionChanged: {
query: ON_TRANSACTION_CHANGED,
variables() {
return {
profileId: this.profile.profileId,
};
},
skip() {
return !this.profile?.profileId;
},
result({ data }: any) {
console.log(data.onTransactionChanged);
},
},
},
在这种情况下,我在控制台中看到了一个新事务。
订阅更多:
cartProducts: {
query: GET_CART_PRODUCTS,
loadingKey: "loading",
subscribeToMore: {
document: ON_TRANSACTION_CHANGED,
},
updateQuery: (previousResult: any, { subscriptionData }: any) => {
console.log("previousResult:", previousResult);
console.log("subscriptionData:", subscriptionData);
},
variables() {
return {
profileId: this.profile.profileId,
};
},
skip() {
return !this.profile?.profileId;
},
}
在这种情况下,控制台中没有任何内容。 我究竟做错了什么?提前谢谢你。
【问题讨论】:
-
没关系,我只是错过了花括号范围。它正在工作
标签: vue.js graph apollo vue-apollo graphql-subscriptions