我正在尝试使用 AppSync 将一些项目批量放入 DynamoDB。当我调用解析器时,它不会引发任何错误,但不会将任何内容保存到数据库中。
架构
type BoxScore @model {
id: ID!
userId: String!
gameVariant: String!
complete: Boolean!
failFact: BoxScoreFact @connection
totalCorrect: Int!
}
type BoxScoreFact @model {
id: ID!
left: Int!
right: Int!
gameVariant: String!
timestamp: Int!
correct: Boolean!
}
input BatchAddCreateBoxScoreFactInput {
id: ID
left: Int!
right: Int!
gameVariant: String!
timestamp: Int!
correct: Boolean!
boxScoreFactBoxScoreId: ID!
}
IAM 角色:
"Effect": "Allow",
"Action": [
"dynamodb:DeleteItem",
"dynamodb:GetItem",
"dynamodb:PutItem",
"dynamodb:Query",
"dynamodb:Scan",
"dynamodb:UpdateItem",
"dynamodb:BatchGetItem",
"dynamodb:BatchWriteItem"
],
解析器:
#set($factsdata = [])
#foreach($item in ${ctx.args.facts})
$util.qr($factsdata.add($util.dynamodb.toMapValues($item)))
#end
{
"version" : "2018-05-29",
"operation" : "BatchPutItem",
"tables" : {
"TABLENAME": $utils.toJson($factsdata)
}
}
从 AppSync 游乐场调用:
响应映射模板:
#if($ctx.error)
## Append a GraphQL error for that field in the GraphQL response
$utils.error($ctx.error.message, $ctx.error.message)
#end
{
"boxScoreFacts": $util.toJson({"res": "no error", "ctx": $ctx}),
}
功能测试运行的输出模板:
DynamoDB 表
WhereTABLENAME
设置为等于显示在 DDB 控制台中的 DynamoDB 表名称。所以像 BoxScoreFact-woieieie99392-prod 这样的东西。
该表始终为空,响应为空。这几乎是直接从文档中的示例中提取出来的。另外,我应该注意,使用正常的 create graphql 函数放置一个项目确实会将一个项目放置到预期的表中。
我在这里想念什么?