【问题标题】:Vue Apollo subscription not updating the queryVue Apollo 订阅未更新查询
【发布时间】: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


【解决方案1】:

我只是错过了花括号范围。它正在工作

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;
        },
      }
}

【讨论】:

    猜你喜欢
    • 2019-07-11
    • 2020-07-07
    • 2017-05-29
    • 2017-11-28
    • 1970-01-01
    • 2018-12-31
    • 1970-01-01
    • 2017-09-19
    • 2019-01-22
    相关资源
    最近更新 更多