【问题标题】:Apollo client Graphql query variable type errorApollo 客户端 Graphql 查询变量类型错误
【发布时间】:2019-11-02 09:29:42
【问题描述】:

我正在尝试执行需要 IDis 的删除查询,但出现错误。 “未提供所需类型“ID!”的变量“$id””

查询

export const DELETE_CUSTOMER = gql`
    mutation deleteCustomer($id:ID!){
        deleteCustomer(
            _id: $id
        )
    }
`

vuex 动作中的变异代码

deleteCustomer(vuexContext,id){
        return apollo
        .mutate({
            mutation: DELETE_CUSTOMER,
            variables: id.toString()
        })      
        .then(()=>{
            vuexContext.commit('deleteCustomer',id.toString());
        })
        .catch((err) => {
            throw err;
        });

    }

【问题讨论】:

  • 你能添加整个 Apollo 客户端突变代码,而不仅仅是突变标记吗?

标签: javascript vue.js graphql apollo-client


【解决方案1】:

variables 选项应该是一个对象,每个属性都映射到查询中引用的单个变量。您不能像您正在做的那样将单个变量的值分配给variables。更正后的方法调用如下所示:

apollo.mutate({
  mutation: DELETE_CUSTOMER,
  variables: { id: id.toString() },
})

【讨论】:

    猜你喜欢
    • 2020-11-27
    • 2018-10-16
    • 2018-03-02
    • 2021-10-12
    • 2022-11-04
    • 2016-08-31
    • 2020-06-14
    • 2020-04-23
    • 2021-11-18
    相关资源
    最近更新 更多