【问题标题】:When leaving the page I get: Unhandled GraphQL subscription error Error: GraphQL error: Variable xx of required type xxx was not provided离开页面时,我得到:未处理的 GraphQL 订阅错误错误:GraphQL 错误:未提供所需类型 xxx 的变量 xx
【发布时间】:2020-05-22 06:44:55
【问题描述】:

我正在使用 vue-apollo graphql 进行开发。

在页面 multisgs/_id.vue 我有几个“subscribeToMore”的查询,每个都有不同的变量。

      variables() {
        return {
          multisigId: this.$route.params.id,
        }
      },

当我离开页面时,我得到:

Unhandled GraphQL subscription error Error: GraphQL error: Variable "$multisigId" of required type "ID!" was not provided. 

我试过了:

  beforeDestroy() {
    this.$apollo.queries.multisig.skip = true
    this.$apollo.queries.multisig.stop()
  },

没有运气。

为什么我在离开页面时会收到此错误?

为了提供更多上下文,我还在 layout.vue 中对数据库中的所有多重签名运行查询:

    multisigs: {
  query: gql`query {
    multisigs {
      _id
      name
      address {
        _id
        balance
      }
    },
  }`,

所以我必须在不同地方查询对同一实体的订阅。当我转到 multigs/_id.vue 时,查询没有执行,所以除非我执行,否则我看不到任何订阅通知:

  mounted() {
    this.$apollo.queries.multisig.refetch()
  },

我感觉 apollo 将两个查询合并为一个,因为它们是关于同一个实体 multisg 的查询。 这非常令人困惑和烦人。

谢谢。

【问题讨论】:

    标签: vue.js graphql apollo


    【解决方案1】:

    我通过添加解决了它:

      skip () {
        return !this.$route.params || !this.$route.params.id
      },
    

    即使我不明白为什么离开页面时查询处于活动状态,它仍然有效。

    【讨论】:

      猜你喜欢
      • 2017-08-08
      • 2021-07-18
      • 2020-03-01
      • 2019-05-29
      • 1970-01-01
      • 2017-08-01
      • 2019-06-29
      • 2021-03-25
      • 2021-12-15
      相关资源
      最近更新 更多