我使用 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(fields: ["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 之外,我没有看到创建的代码中的 2 个表之间有任何区别。
有任何想法吗?