创建突变 + GraphQL 时出现“未授权访问”错误

Nad*_*ama 7 node.js graphql graphql-js aws-appsync aws-amplify-cli

我正在运行下面的 GraphQL 查询来在 dynamodb 表上创建数据,但得到的响应是“未授权访问 Client 类型上的 createClient”

为什么会发生这种情况。

GraphQL 查询:

`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
  }
}`
Run Code Online (Sandbox Code Playgroud)

回复 :

{
  "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"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

Nad*_*ama 7

用 authMode 解决了

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