aws / aws/aws-appsync-community
GraphQL batchGet returns 'null' from DynamoDB
- Dominant language
- HTML
- Stars
- 507
- Forks
- 37
- PR merge metrics
- No merged PRs in 30d
Description
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](https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-dynamodb-batch.html#single-table-batch) 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.
Contributor guide
Research direction
Start by reproducing the null response in the AppSync console using the schema.graphql definition, the shown request mapping, and the response mapping. Compare the setup with the recommended DynamoDB batch tutorial and verify the stated IAM permissions. Done means identifying why batchGet returns null and confirming a non-null response for the supplied IDs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, graphql, react
- Domain
- api, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100