简体   繁体   English

Apollo客户端Graphql查询变量类型错误

[英]Apollo client Graphql query variable type error

I am trying to execute delete query in which IDis required but I am getting an error. 我正在尝试执行ID为必填项的删除查询,但出现错误。 "Variable "$id" of required type "ID!" was not provided" “未提供所需类型为“ ID!”的变量“ $ id””

Query 询问

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

Mutation code in vuex actions vuex操作中的变异代码

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

    }

The variables option should be an Object, with each property mapping to an individual variable referenced inside your query. variables选项应该是一个对象,每个属性都映射到查询中引用的单个变量。 You cannot assign the value of an individual variable to variables like you're doing. 您不能像这样做一样将单个变量的值分配给variables The corrected method call would look something like: 更正后的方法调用将类似于:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Apollo 客户端和 graphQl 查询错误:变量 '$where' 类型的期望值 'OrganizationWhereUniqueInput - Apollo client and graphQl query error : Variable '$where' expected value of type 'OrganizationWhereUniqueInput GraphQL Apollo:在 apollo 客户端查询中未提供变量错误,尽管我认为我设置了变量 - GraphQL Apollo: Variable was not provided error in apollo client query, although I think I set the variable Apollo Server - GraphQL 错误:只能有一种名为“查询”的类型 - Apollo Server - GraphQL Error: There can be only one type named "Query" 反应中的奇怪错误 - 使用阿波罗/客户端 - graphql - Weird error in react - using apollo/client - graphql 获取所需类型“String”的错误变量“$name”。 没有提供。 在从 React-Apollo 发出 Graphql 请求时 - Getting Error Variable “$name” of required type “String!” was not provided. on firing Graphql request from React-Apollo 在 Javascript 中使用 GraphQL + Apollo 客户端查询具有部分字符串匹配的数据 - Query data with partial string match using GraphQL + Apollo client in Javascript 无法转换/规范化/修改 GraphQL 查询的响应 - Apollo Client - Can't transform/normalize/modify response of GraphQL query - Apollo Client 无法解构 GraphQL 查询,因为 apollo-client 未定义? - Cannot destructure GraphQL query as apollo-client is undefined? useParams 用于阿波罗 GraphQL 查询 - useParams for apollo GraphQL query Apollo GraphQL 客户端 + Next.JS 错误处理 - Apollo GraphQL Client + Next.JS Error Handling
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM