4

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: "smithj@amazon.com"
    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"
    }
  ]
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Is it possible that the HTTP client that sends the GraphQL query to the server need to also send an Authorization header with an authentication token? (or some other form of authentication) – Tal Z Feb 05 '22 at 11:07
  • Seems yes. it needs some autorization. Do you have any samples for that? – Nadeesha Nawagaththegama Feb 05 '22 at 16:55

1 Answers1

5

It solved with authMode

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

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 09 '22 at 13:33
  • This answer worked for me, some more info in [the amplify docs](https://docs.amplify.aws/lib/graphqlapi/authz/q/platform/js/) – conor909 Aug 09 '22 at 15:46