Filters, IN comparison operator, toDynamoDBFilterExpression()
Hi,
This is not a question, but a solution to a problem we were having.
Me and my team wanted to filter a query by comparing a field with different values in a list. Something like this:
query listCars{
listCars(filter:{ car_color: {in: ['red', 'black']}}){
car_name
car_color
}
}
Note the in comparison operator.
We found that the resolver for that filter input was calling a function: toDynamoDBFilterExpression(), for example:
{
"version": "2017-02-28",
"operation": "Scan",
"filter": #if($context.args.filter) $util.transform.toDynamoDBFilterExpression($ctx.args.filter) #else null #end,
"limit": $util.defaultIfNull($ctx.args.limit, 20),
"nextToken": $util.toJson($util.defaultIfNullOrEmpty($ctx.args.nextToken, null)),
}
That function transforms the filter input according to the documentation (https://docs.aws.amazon.com/appsync/latest/devguide/resolver-util-reference.html).
Now Appsync autogenerates code for the TableStringFilterInput, but it doesnt include the in operator. The question is, does this function support this operator?
We found that adding the in operator in the schema is sufficient to make it work:
input TableStringFilterInput {
ne: String
eq: String
le: String
lt: String
ge: String
gt: String
in: [String]
contains: String
notContains: String
between: [String]
beginsWith: String
}
Then we could run the query at the beginning of this post.
Thank you for the investigation. If you would like to make this change permanent I know the team is happy to review PRs. It looks like your change could be made permanent if added to the logic rooted here: https://github.com/aws-amplify/amplify-cli/blob/00ed819419a4959a6d62da2fc5477621c046eff0/packages/graphql-dynamodb-transformer/src/definitions.ts#L437.
Relevant questions
Dynamically Change Parameter Values based on Other Parameters
asked 4 months agoCONSTRAINT_VIOLATION: Query exceeded maximum columns or filters.
asked a year agoAssert Error in redshift
Accepted Answerasked 5 years agoLinux VPN Client halts on 'Drive type Network not supported' after upgrade to 3.0.0
asked 2 months agoEFS - files not found sometimes and randomly
asked a month agoHow to get a new solution version using only recent records?
Accepted Answerasked 10 months agoDynamoDB "explore items" showed me an error "Key not found in KeySchema."
asked 3 months agoCan a Quicksight custom query be filtered before running against a database?
asked a day agoDataBrew Filter
asked 2 months agoFilters, IN comparison operator, toDynamoDBFilterExpression()
asked 3 years ago