[英]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.