我有一个简单的AppSync API,该API具有适用于City和Venue的类型,示例是映射小型零售商店。我正在尝试通过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...)"
}
]
}
任何帮助将不胜感激,我看不到为什么我无法使用提供的String作为ID并将其标识为NULL来执行简单的Create ...
答案 0 :(得分:0)
## 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)
}
}