Santanu Karar
Santanu Karar

Reputation: 1076

AWS Amplify mutation call returns "Validation error of type UnknownArgument: Unknown field argument"

When ran this query to Amplify console, this works good - so I assume schema and db setup properly:

mutation CreateUser {
  createUser(input: {
    name: "Nader Dabit"
    email: "[email protected]"
    image: "someimagepath"
    mobile: 122122
  }) {
    id
    name
    email
    image
    mobile
  }
}

Inside my RN app, I configured AWS Amplify in following way (but I'm not sure if this is how it should be, but login/register etc. process seems working fine):

Amplify.configure({Auth: apiKeyStore, aws_appsync_graphqlEndpoint: "https://xxx.appsync-api.ap-xxx-1.amazonaws.com/graphql",
        aws_appsync_region: "ap-xxx-1", aws_appsync_authenticationType: "API_KEY", aws_appsync_apiKey: "da2-xxxx"});

I have following codes therefore to call the mutation method:

const CreateUser = `mutation CreateUser(
    $name: String!,
    $email: String!,
    $mobile: Int!,
    $image: String!
  ) {
        createUser(name:$name, email:$email, mobile:$mobile, image:$image)
        {
            id
            name
            email
            mobile
            image
        }
}`;

// inside a method
try 
{
   const newUser = await API.graphql(graphqlOperation(CreateUser, {name: name, email: email, mobile: mobile, image: image}));
   console.log('newUserIncoming: ', newUser);
}
catch (err) 
{
   console.log('error while create user: ', err);
}

But the above call always turns to error/catch, with following error objects (as seen with React Native Debugger):

enter image description here

Upvotes: 1

Views: 4171

Answers (1)

Santanu Karar
Santanu Karar

Reputation: 1076

I see, probably the above GraphQL context are a little old. Looking into the current documentation as hosted at https://aws-amplify.github.io/docs/js/react, I found it requires some adjustment. After doing so, I able to return positive and able to store value to the db.

Following is my latest query format (if helps to anyone like me, notice the comma usage now removed, and also added with a new tag input):

const CreateUser = `mutation CreateUser(
    $name: String!
    $email: String!
    $mobile: Int!
    $image: String!
  ) {
        createUser(input:{name:$name email:$email mobile:$mobile image:$image})
        {
            id
            name
            email
            mobile
            image
        }
}`;

Rest are remain same for me.

Upvotes: 1

Related Questions