Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am using the AWS AppSync service as my GraphQL server. I am passing a mutation GraphQL tag to create a user but somehow I am getting this error in the console:

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

The mutation GraphQL tag is like this:

     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
          }
       }`;

and I am passing this GraphQL tag inside my SignupForm.js to create a user like this:

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

When I call this.props.AddUser(user)

where user is signup user details object

I got error mentioned above.

like image 243
Rizwan Avatar asked Mar 12 '26 06:03

Rizwan


1 Answers

It seems the problem is a typo in the mutation options:

{ variable: user } should be { variables: user } (with an 's')

like image 96
Tal Z Avatar answered Mar 14 '26 00:03

Tal Z