Amazon dynamodb 只要有主键,提供的键元素就与架构错误不匹配

Amazon dynamodb 只要有主键,提供的键元素就与架构错误不匹配,amazon-dynamodb,aws-amplify,aws-appsync,aws-amplify-cli,Amazon Dynamodb,Aws Amplify,Aws Appsync,Aws Amplify Cli,我使用aws amplify,并有这样一个graphql模式,我使用amplify push推送: type User @model { id: ID! lastname: String! customerID: ID! status: Status @connection statusID: ID! } type Status @model { id: ID! name: String } 我可以在appsync控制台中插入新用户,而不会出现以下错误: mut

我使用aws amplify,并有这样一个graphql模式,我使用amplify push推送:

type User @model  {
  id: ID!
  lastname: String!
  customerID: ID!
  status: Status @connection
  statusID: ID!
}

type Status @model {
  id: ID!
  name: String
}
我可以在appsync控制台中插入新用户,而不会出现以下错误:

mutation CreateUser($input: CreateUserInput!) {
  createUser(input: $input) {
    id
    customerID
    lastname
    status {
      id
      name
    }
  }
}

{"input": {
  "id": 1,
"customerID": 1,
  "statusID": 1
"lastname": "Doe"
}
}
但是,当我通过在graphql模式中添加@key(字段:[“customerID”])创建具有主键customerID的同一dynamodb表用户时,appsync控制台中就会出现以下错误:

 {
      "path": [
        "createUser",
        "status"
      ],
      "data": null,
      "errorType": "DynamoDB:AmazonDynamoDBException",
      "errorInfo": null,
      "locations": [
        {
          "line": 6,
          "column": 5,
          "sourceName": null
        }
      ],
      "message": "The provided key element does not match the schema (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: 4SUT0SN1R6BKS8KG2V1AGUCHGRVV4KQNSO5AEMVJF66Q9ASUAAJG)"
    }
虽然在数据库中,但用户已正确创建。 除了pk customerID之外,我看不到创建代码中的两个表之间有任何区别

有什么想法吗?

您的模式为“只有一个”关系建模,您可以参考本文档了解示例模式

不带参数的@connection指令将使用主键。Amplify CLI还将为您生成以下输入类型。 如果我正确理解了您的意图,那么您的模式中不需要用户类型中的statusID字段。 您可以在@connection定义中指定
字段
参数。如果您想为连接使用特定字段(例如“statusID”),文档中也有一个示例

执行创建时,应首先创建状态对象,获取其Id,然后创建用户对象,并将userStatusId指定为状态Id

input CreateUserInput {
  id: ID
  lastname: String!
  customerID: ID!
  statusID: ID!
  userStatusId: ID
}