By using AWS re:Post, you agree to the Terms of Use

Filters, IN comparison operator, toDynamoDBFilterExpression()


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']}}){

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 (
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.

2 Answers

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:

answered 3 years ago

marked thread as answered

Edited by: Chagui on May 27, 2020 9:29 AM

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions