'AWS amplify graphql appsync - do not return deleted items?

I am using AWS amplify with graphql and appsync. When I do a standard list query, appsync includes deleted items in the list of items it returns.

What can I do to make it return only items that are not deleted?

I tried this query, but it throws an error:

query MyQuery($filter: ModelFrameFilterInput = {_deleted: {ne: true}}) {
  listFrames(filter: $filter) {
    items {
      _deleted
      name
      id
    }
  }
}

Here is the error message:

 "message": "Validation error of type BadValueForDefaultArg: Bad default value ObjectValue{objectFields=[ObjectField{name='_deleted', value=ObjectValue{objectFields=[ObjectField{name='ne', value=BooleanValue{value=true}}]}}]} for type ModelFrameFilterInput"


Solution 1:[1]

One thing you can do is to disable Conflict Resolver, if it's not necessary for you, "after deleting elements that are using ConflictResolution, they are not immediately deleted from the database. Instead, two flags are being added: _deleted is set to true and _ttl is set to expire the object in 30 days." see: Error "Conflict resolver rejects mutation." when Delete in Amplify

To disable it, run amplify update api, and you will be prompt to a choice to disable conflict resolver

But if you are using DataStore, then it is must to enable conflict resolver. in that case, I don't know how to solve it.

Solution 2:[2]

This is a known issue when using ConflictResolution. I have also faced this issue in the past. My solution was to use DynomoDB Streams Trigger with AWS Amplify to listen for DynamoDB update events and then delete the record via Lambda.

Here's the official documentation for AWS Amplify GraphQL Lambda Triggers

https://docs.amplify.aws/cli/usage/lambda-triggers/#as-a-part-of-the-graphql-api-types-with-model-annotation

DynamoDB triggers are almost real time so this works really well even with 128MB Lambda

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 pavlos163
Solution 2 Sam - OnePunchManTwo