我正在尝试执行需要 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;
});
}
最佳答案
variables
选项应该是一个对象,每个属性映射到查询中引用的单个变量。您不能像您所做的那样将单个变量的值分配给variables
。更正后的方法调用将类似于:
apollo.mutate({
mutation: DELETE_CUSTOMER,
variables: { id: id.toString() },
})
关于javascript - Apollo客户端Graphql查询变量类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56671093/