首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >阿波罗-客户端_mutation输入类型数据为空。

阿波罗-客户端_mutation输入类型数据为空。
EN

Stack Overflow用户
提问于 2018-08-16 01:34:44
回答 1查看 872关注 0票数 1

我和阿波罗客户一起工作。我在试着对客户进行变异。我想知道为什么当我做我的变异时,在服务器上传递的数据是无效的?

在这里,我的突变类型:

代码语言:javascript
复制
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
        }

在这里,我的突变请求:

代码语言:javascript
复制
const addRecipe = gql`
    mutation addRecipe($data: RecipeInput){ 
        addRecipe(data: $data){ 
          id
          title 
        }
    }
`;

我的反应-阿波罗粘合剂:

代码语言:javascript
复制
export default graphql(addRecipe)(Create); 

我的突变信号在我的成分中:

代码语言:javascript
复制
onSubmit = (e) =>{ 
    e.preventDefault();
    this.props.mutate({ 
      variables:{  

        title: this.state.title,
        ingredients: this.state.ingredients,          
    }
    })
  }

当console.loging在表单中提供的数据时,我的服务器返回:

代码语言:javascript
复制
{}

我搞不懂为什么。

我试图发出以下突变电话:

代码语言:javascript
复制
this.props.addRecipe() 

但是我的控制台返回:

this.props.addRecipe()不是函数

为什么会有这种行为?

任何暗示都会很好,

谢谢

EN

回答 1

Stack Overflow用户

发布于 2018-08-16 12:36:09

要到达数据,必须在变量对象中重新输入数据标题。就我而言:

代码语言:javascript
复制
this.props.mutate({ 
      variables:{
          data: {
            {...}
        }
    }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51868473

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档