当离开页面时,我得到:未处理的GraphQL订阅错误错误:GraphQL错误:未提供所需类型xxx的变量xx

问题描述 投票:1回答:1

我正在使用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()
  },

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

谢谢。

vue.js graphql apollo
1个回答
0
投票

我通过添加解决了它:

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

即使我不明白为什么离开页面时查询仍处于活动状态也可以。

© www.soinside.com 2019 - 2024. All rights reserved.