【问题标题】:How to add in dynamic parameters into a graphql query如何将动态参数添加到 graphql 查询中
【发布时间】:2019-12-30 18:54:20
【问题描述】:

我想做一个 GraphQL 查询,从我的 Vue 应用程序的数据字段中获取一些数据。但是,当我设置变量挂钩并尝试使用 this.object 引用我需要的对象时,我得到一个无法读取未定义的“xxx”。

apollo: {
    question: {
      query: gql `
      query question($id: Int!) {
        question(id: $id){
          ...
        }
      }
`, variables: { id: this.presentQuestionId}
    }
  },

Uncaught TypeError: Cannot read property 'presentQuestionId' of undefined 是不断出现的错误消息。

【问题讨论】:

    标签: vue.js graphql apollo vue-apollo


    【解决方案1】:

    variables 选项应该是一个返回如下对象的函数:

    variables(){
        return{
         id: this.presentQuestionId
       }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-04
      • 2021-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-26
      相关资源
      最近更新 更多