Skip to content
This repository was archived by the owner on Apr 30, 2024. It is now read-only.
This repository was archived by the owner on Apr 30, 2024. It is now read-only.

Optional Query.getDestinationsByState #6

@idkjs

Description

@idkjs

Hey folks. Thanks for sharing this. So many good bits, especially on resolver mapping.

I can't get the optional resolver to resolve.

Using the suggested mapping:

{
    "version": "2017-02-28",
    "operation": "Query",
    "index":"state-index",
    "query":{
    	"expression":"#state = :state",
        "expressionNames":{
        	"#state":"state"
        },
        "expressionValues":{
        	":state" :{
            	"S": $util.dynamodb.toDynamoDBJson($ctx.args.state),
            }
        }
    }
}

with this default request mapping template:

## Pass back the result from DynamoDB. **
$util.toJson($ctx.result.items)
  • called with this query:
query GetByState {
  getDestinationsByState(state:"Florida"){
    id
    description
  }
}
  • returns this error:

screen shot 2018-12-02 at 11 08 03 am

{
  "data": {
    "getDestinationsByState": null
  },
  "errors": [
    {
      "path": [
        "getDestinationsByState"
      ],
      "data": null,
      "errorType": "MappingTemplate",
      "errorInfo": null,
      "locations": [
        {
          "line": 14,
          "column": 3,
          "sourceName": null
        }
      ],
      "message": "Value for field '$[query][expressionValues][:state][S]' must be text."
    }
  ]
}
{
    "version": "2017-02-28",
    "operation": "Query",
    "index": "todoid-index",
    "query": {
        "expression": "todoid = :todoid",
        "expressionValues": {
            ":todoid": {
                "S": "$context.source.id"
            }
        }
    }
}

I'm thinking the solution is to create an index called state-index. We can only create a secondary index when we create the dynamodb table. What would you suggest is the best way to go about setting up the optional query?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions