我和阿波罗客户一起工作。我在试着对客户进行变异。我想知道为什么当我做我的变异时,在服务器上传递的数据是无效的?
在这里,我的突变类型:
type: recipeType,
args:{
data: {
name: 'data',
type: recipeInputType
}
},
resolve(parent, args) {
const recipe = new recipeModel(args.data);
const newRecipe = recipe.save();
if(!newRecipe){
throw new Error("Error adding recipe")
}
console.log("recipe add with success!! ", args)
return newRecipe
}在这里,我的突变请求:
const addRecipe = gql`
mutation addRecipe($data: RecipeInput){
addRecipe(data: $data){
id
title
}
}
`;我的反应-阿波罗粘合剂:
export default graphql(addRecipe)(Create); 我的突变信号在我的成分中:
onSubmit = (e) =>{
e.preventDefault();
this.props.mutate({
variables:{
title: this.state.title,
ingredients: this.state.ingredients,
}
})
}当console.loging在表单中提供的数据时,我的服务器返回:
{}我搞不懂为什么。
我试图发出以下突变电话:
this.props.addRecipe() 但是我的控制台返回:
this.props.addRecipe()不是函数
为什么会有这种行为?
任何暗示都会很好,
谢谢
发布于 2018-08-16 12:36:09
要到达数据,必须在变量对象中重新输入数据标题。就我而言:
this.props.mutate({
variables:{
data: {
{...}
}
}https://stackoverflow.com/questions/51868473
复制相似问题