I'm trying to batch put a number of items to DynamoDB using AppSync. When I call the resolver it throws no errors but nothing is saved to the database.
Schema
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 Role:
"Effect": "Allow",
"Action": [
"dynamodb:DeleteItem",
"dynamodb:GetItem",
"dynamodb:PutItem",
"dynamodb:Query",
"dynamodb:Scan",
"dynamodb:UpdateItem",
"dynamodb:BatchGetItem",
"dynamodb:BatchWriteItem"
],
Resolver:
#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)
}
}
Call from AppSync playground:
Response mapping template:
#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}),
}
Output template from Function test run:
DynamoDB Table
Where TABLENAME
is set equal to the DynamoDB table name that is displayed in the DDB console. So something like BoxScoreFact-woieieie99392-prod.
The table is always empty and the response is null. This is lifted almost straight out of the example from the docs. Also, I should note, that putting one item using the normal create graphql function does put an item to the intended table.
What am I missing here?
batchAddBoxScoreFacts(facts: [BatchAddCreateBoxScoreFactInput]): String
and the response mapping to$util.toJson($ctx)
? This way we'll have a full stringify response and get tips to solve your problem. You'll receive something like this:"{arguments={facts=[{boxScoreFactBoxScoreId=123, gameVariant=0}]}, identity=null, source=null, result={data={Test=[{gameVariant=0, boxScoreFactBoxScoreId=123}]}, unprocessedItems={Test=[]}}, request={...}, error=null, prev=null, stash={}, outErrors=[]}"
– ScrutinizeBatchAddCreateBoxScoreFactInput
schema as well? – Aftmost