AWS AppSynC语言 Create Mutation returns Null



我有一个简单的AppSync API,它有一个城市和场地的类型,示例是映射小型零售店。我正在尝试通过 AppSync 中的"查询"窗格创建一个新城市,我还想提供一个缩短的 ID - 而不是长 autoId,以便我可以对缩短的 ID 运行查询,前端应用程序可以从 URL 中的参数使用它。

我正在尝试使用以下代码在 DynamoDB 中创建新项目:

图式

type City {
id: String!
name: String!
}
type Mutation {
...
createCity(input: CreateCityInput!): City
...
}
input CreateCityInput {
id: String!
name: String!
}

Mutation.createCity

// Request mapping template
{
"version" : "2017-02-28",
"operation" : "PutItem",
"key" : {
## If object "id" should come from GraphQL arguments, change to $util.dynamodb.toDynamoDBJson($ctx.args.id)
"id": $util.dynamodb.toDynamoDBJson($ctx.args.id)
},
"attributeValues" : $util.dynamodb.toMapValuesJson($ctx.args)
}
// Response mapping template
$util.toJson($context.result)

这是我在"查询"页面中运行的突变

mutation CreateCity {
createCity(input: {
id: "11538062"
name: "Manchester"
}) {
id
name
}
}

这是从AppSync和/或Dynamo返回的错误

{
"data": {
"createCity": null
},
"errors": [
{
"path": [
"createCity"
],
"data": null,
"errorType": "DynamoDB:AmazonDynamoDBException",
"errorInfo": null,
"locations": [
{
"line": 32,
"column": 3,
"sourceName": null
}
],
"message": "One or more parameter values were invalid: Type mismatch for key id expected: S actual: NULL (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: 7PU4D2...)"
}
]
}

任何帮助将不胜感激,我不明白为什么我无法使用提供的字符串作为 ID 执行简单的创建并将其标识为 NULL...

## Request Mapping
{
"version" : "2017-02-28",
"operation" : "PutItem",
"key" : {
"id" : $util.dynamodb.toDynamoDBJson($ctx.args.input.id)
},
"attributeValues" : {
"name" : $util.dynamodb.toDynamoDBJson($ctx.args.input.name)
}
}

最新更新