Vue Apollo 订阅不更新查询

Vue Apollo subscription not updating the query

这是我第一次实现 GraphQL 订阅,如果这是一个明显的问题,请原谅。

我有一个正在使用 Simple Subscription approach, but doesn't work with 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;
      },
    }

在这种情况下,控制台中没有任何内容。 我究竟做错了什么?提前谢谢你。

我只是错过了大括号范围。有效

cartProducts: {
  query: GET_CART_PRODUCTS,
  loadingKey: "loading",
  subscribeToMore: {
        document: ON_TRANSACTION_CHANGED,
        updateQuery(previousResult: any, { subscriptionData }: any) {
          console.log("previousResult:", previousResult);
        },
        variables() {
          return {
            profileId: this.profile.profileId,
          };
        },
        skip() {
          return !this.profile?.profileId;
        },
      }
}