【发布时间】:2019-01-22 21:47:00
【问题描述】:
我正在使用 Apollo 客户端。我正在尝试对客户端进行突变。我想知道为什么当我进行突变时,服务器上传递的数据是无效的?
这是我的变异类型:
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
}
}
`;
我的 react-apollo 活页夹:
export default graphql(addRecipe)(Create);
我的组件中的突变调用:
onSubmit = (e) =>{
e.preventDefault();
this.props.mutate({
variables:{
title: this.state.title,
ingredients: this.state.ingredients,
}
})
}
当控制台记录我在表单中提供的数据时,我的服务器返回:
{}
我不知道为什么。
我试图进行以下突变调用:
this.props.addRecipe()
但我的控制台返回:
this.props.addRecipe() 不是函数
为什么会有这种行为?
任何提示都会很棒,
谢谢
【问题讨论】:
标签: javascript reactjs graphql react-apollo apollo-client