aws-appsync-community
aws-appsync-community copied to clipboard
GraphQL batchGet returns 'null' from DynamoDB
This post comes from spending 3 hours with AWS premium support for the past 2 days, in addition to time spent individually debugging. Perhaps I could get some clarity in this forum.
I'm trying to create a GraphQL API that leverages the batchGet
functionality. Regardless of configuration, however, I consistently get the following from the AppSync console:
{
"data": {
"batchGet": null
}
}
I'm using this request:
query MyQuery {
batchGet(ids: ["value5", "value6"]) {
growth
}
}
This is my DynamoDB table:
And this is my schema.graphql
in React:
type Value @model {
id: ID!
result: [[Float]]!
growth: Float
}
type Query {
batchGet(ids: [ID]): [Value]
}
I went through the recommended tutorial. Also, I have the proper IAM permissions for batch commands.
Finally, here are the respective request and response mappings, taking from the schema
section of the AppSync console:
#set($ids = [])
#foreach($id in ${ctx.args.ids})
#set($map = {})
$util.qr($map.put("id", $util.dynamodb.toString($id)))
$util.qr($ids.add($map))
#end
{
"version" : "2018-05-29",
"operation" : "BatchGetItem",
"tables" : {
"Value-ctwvdp7ygfhyjhq25uvkfzftfy-devtwo": {
"keys": $util.toJson($ids),
"consistentRead": true
}
}
}
$util.toJson($ctx.result.data.Value)
After days of trying to solve this, I'm beginning to suspect that it's an AppSync bug rather than an error in my code. That said, hopefully I'll stand corrected.
Result returns by table name.
$util.toJson($ctx.result.data.get("Value-ctwvdp7ygfhyjhq25uvkfzftfy-devtwo"))
P.s. Also I advice to enable debug logging to cloudwatch - it helps a lot