Complete the code to define a GraphQL query that fetches all items from a DynamoDB table.
query ListItems {
listItems [1] {
items {
id
name
}
}
}The listItems query requires parentheses even if no arguments are passed, so () is correct.
Complete the mutation to add a new item with id and name fields.
mutation AddItem {
createItem(input: [1]) {
id
name
}
}The input argument must be an object with field names and values, so {id: "1", name: "Item1"} is correct.
Fix the error in the resolver mapping template to get an item by id.
{
"version": "2018-05-29",
"operation": "[1]",
"key": {
"id": $util.dynamodb.toDynamoDBJson($ctx.args.id)
}
}To get a single item by key, the operation must be GetItem.
Fill both blanks to create a resolver that queries items with a filter expression.
{
"version": "2018-05-29",
"operation": "[1]",
"filter": {
"expression": "[2]",
"expressionValues": {
":val": $util.dynamodb.toDynamoDBJson($ctx.args.filterValue)
}
}
}Scan operation supports filter expressions like name = :val to filter items.
Fill all three blanks to define a mutation resolver that updates an item attribute.
{
"version": "2018-05-29",
"operation": "[1]",
"key": {
"id": $util.dynamodb.toDynamoDBJson($ctx.args.id)
},
"update": {
"expression": "set [2] = :val",
"expressionValues": {
":val": $util.dynamodb.toDynamoDBJson($ctx.args.newValue)
}
},
"condition": "[3]"
}UpdateItem is the operation to update attributes. The expression sets the attributeName to a new value. The condition ensures the item exists.