'"Not Authorized to access " error on create mutation + GraphQL

I'm running the below GraphQL query to create data on dynamodb table, but gets the response with "Not Authorized to access createClient on type Client"

Why this is happening at.

GraphQL query:

`mutation addClient{
  createClient(input:{
    fullName: "Jhon Smith"
    title: "Software Engineer"
    organization: "AWS"
    contactNo: "+341289655524"
    email: "[email protected]"
    country: "Canada"
    address: "AN/458, Norton place, Down Town"    
  }){
    fullName
  }
}`

Response :

{
  "data": {
    "createClient": null
  },
  "errors": [
    {
      "path": [
        "createClient"
      ],
      "data": null,
      "errorType": "Unauthorized",
      "errorInfo": null,
      "locations": [
        {
          "line": 2,
          "column": 3,
          "sourceName": null
        }
      ],
      "message": "Not Authorized to access createClient on type Client"
    }
  ]
}


Solution 1:[1]

It solved with authMode

const newTodo = await API.graphql({ query: mutations.createClient, variables: {input: inputData}, authMode: "AMAZON_COGNITO_USER_POOLS" });

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nadeesha Dileen