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"
1
4 Answers
This is not yet supported
Look at this issue / feature request
There’s a workaround suggested, adding the _deleted
in the filter input of the graphql schema.
input ModelTodoFilterInput {
id: ModelIDInput
name: ModelStringInput
description: ModelStringInput
and: [ModelTodoFilterInput]
or: [ModelTodoFilterInput]
not: ModelTodoFilterInput
_deleted: ModelBooleanInput
}
2
-
Do you know where to add this configuration? If I do it in the AppSync Console (in the Schema section) the code gets overwritten on my next push. If I do it in my front end (
amplify/backend/api/<my app name>/schema.graphql
then I need to copy dozens of lines of code from my console schema. For example, schema types for ModelIDInput, ModelStringInput, ModelStringInput, etc. Or is there a better way to do this that I don't understand?– JimmyTheCodeNov 1, 2022 at 10:35
-
1
@JimmyTheCode I don't know a better way than to copy the schema definition for the model inputs. I finally decided to use DataStore, which filters out the deleted items, and is working good for me. Copying the autogenerated code of the schema it's also annoying because you need to update it when you update your schema. I'm finally filtering the _deleted in the frontend for the few calls I do by graphql.
– BrunoLoopsNov 4, 2022 at 14:38
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.
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
DynamoDB triggers are almost real time so this works really well even with 128MB Lambda
any updates on this?
Dec 15, 2021 at 4:23