【问题标题】:Apollo React GraphQL VariableTypeMismatch errorApollo React GraphQL VariableTypeMismatch 错误
【发布时间】:2018-12-27 15:36:12
【问题描述】:

我有一个看起来像这样的突变:

mutation ADD_CATEGORY($id: ID!, $category: ID!) {
  addCategory(id: $id, category: $category)
}

它作为 addCategory 传递到我的 React 组件中。

我的handleSave 函数如下所示:

    handleSave = () => {
      const { id, category } = this.state;
      addCategory({ variables: { id, category: category.id } });
    }

idcategory.idthis.state 对象上的字符串属性。

我收到以下错误:

[GraphQL 错误]:消息:类型验证错误 VariableTypeMismatch:变量类型不匹配,位置:[object 对象],路径:空

查看 GraphiQL 的 API,我发现 updateCategory 突变具有以下参数:

id: ID!
category: [ID!]!

我在这里错过了什么?

【问题讨论】:

    标签: reactjs graphql apollo


    【解决方案1】:

    请确保addCategory 架构接受String 类型的idcategory。从您的 API 输出来看,categoryArray 类型。

    【讨论】:

      猜你喜欢
      • 2020-01-15
      • 2018-01-28
      • 2018-08-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-23
      • 2017-10-25
      • 2018-08-26
      • 2019-06-12
      相关资源
      最近更新 更多