(appsync): support filters in DynamoDB Query
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 74
Description
Currently, the Query mapping template doesn't support filters.
### Use Case
Query DynamoDB with additional filters.
### Proposed Solution
Provide an optional way to specify filter conditions like the already existing key conditions.
### Other
Here is an example of what is not currently possible. It is taken directly from the examples inside the appsync was console.
```
## Below example shows an example of a query against a table, indexed by the "name" attribute
## The query returns any items in the index matching a certain "name", and then applies a
## filter to the results to match only the results with a certain "city" attribute
## "expressionNames" is used as a placeholder or alias to the DynamoDB attribute, and is
## necessary for certain reserved attribute keywords like "name" or "owner"
## "filter" : "expression" is the logical condition applied after the query runs, you can use:
## - NOT_NULL(), NULL(), CONTAINS(), NOT_CONTAINS()
## - This also works for attributes that are sets. For example, you can use "expression" : "contains(projects, :favfood)
## to check an attribute called "projects" of type String Set ("SS") for matches of a certain favorite food
## - BEGINS_WITH(), IN(), BETWEEN()
## - Comparators: >, <. >=, <= can be used for the "expression" key inside a filter
## - For example, "expression" : "#age > :age" would work on an attribute of type number
## Read more: https://docs.aws.amazon.com/appsync/latest/devguide/resolver-mapping-template-reference-dynamodb.html#aws-appsync-resolver-mapping-template-reference-dynamodb-filter
{
"version" : "2017-02-28",
"operation" : "Query",
"index" : "name-index",
"query" : {
"expression": "#name = :name",
"expressionNames" : {
"#name" : "name"
},
"expressionValues" : {
":name" : {
"S" : $util.dynamodb.toDynamoDBJson($ctx.args.name)
}
}
},
"filter" : {
"expression" : "contains(#city, :city)",
"expressionNames" : {
"#city" : "city"
},
"expressionValues" : {
":city" : $util.dynamodb.toDynamoDBJson($ctx.args.city)
}
}
}
```
* [x] :wave: I may be able to implement this feature request
* [ ] :warning: This feature might incur a breaking change
---
This is a :rocket: Feature Request
Contributor guide
Research direction
Start with the AppSync DynamoDB Query mapping template and the AWS filter documentation linked in the issue. Compare the requested filter block with the existing key-condition handling, then verify that Query mappings can accept an optional filter with the documented expressions and values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- api, cloud
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100