【问题标题】:GraphQL error: Variable 'id' has coerced Null value for NonNull type 'ID!'GraphQL 错误:变量 'id' 已强制 NonNull 类型 'ID!' 的 Null 值
【发布时间】:2018-09-11 23:40:26
【问题描述】:

我使用 AWS AppSync 服务作为我的 GraphQL 服务器。我正在传递一个突变 GraphQL 标记来创建一个用户,但不知何故我在控制台中收到了这个错误:

GraphQL error: Variable 'id' has coerced Null value for NonNull type 'ID!'

突变的GraphQL标签是这样的:

     import gql from 'graphql-tag';

    export default gql`
    mutation addUser ($id:ID!,$name:String!,$email:String!,$number:String!,$gender:String!,$password:String!,$createdAt:String!,$type:String!){
      addUser(
            id:$id,
            name:$name,
            email:$email,
            number:$number,
            gender:$gender,
            password:$password,
            createdAt:$createdAt,
            type:$type
          ){
            id
            name
            email
          }
       }`;

我在我的SignupForm.js 中传递这个 GraphQL 标记来创建这样的用户:

    export default graphql(AddUser,{
    props:props=>({
    AddUser:user=>props.mutate({
      variable:user,
      })
    })
    })(SignUpForm);

当我打电话给this.props.AddUser(user)

其中用户是注册用户详细信息对象

我收到了上面提到的错误。

【问题讨论】:

  • 你能打印你的user吗?
  • 可能是你打错字了,应该是variables: user而不是variable: user
  • 非常感谢它现在正在工作
  • @TalZ 请将您的回复添加为答案,以便其他人可以快速找到它。 @Rizwan 你考虑过新的Mutation 组件吗? dev-blog.apollodata.com/…

标签: graphql apollo graphql-js react-apollo aws-appsync


【解决方案1】:

问题似乎是突变选项中的拼写错误:

{ variable: user } 应该是{ variables: user }(带有's')

【讨论】:

    猜你喜欢
    • 2019-10-24
    • 2020-05-01
    • 2019-01-30
    • 2019-05-29
    • 2019-11-29
    • 1970-01-01
    • 1970-01-01
    • 2019-05-01
    • 1970-01-01
    相关资源
    最近更新 更多