Skip to content

Instantly share code, notes, and snippets.

@undefobj
Created February 7, 2022 07:34
Show Gist options
  • Save undefobj/0c21cf58f5b0c931a31f90a5bcff534a to your computer and use it in GitHub Desktop.
Save undefobj/0c21cf58f5b0c931a31f90a5bcff534a to your computer and use it in GitHub Desktop.
Filter deleted
This is an example with a simple TODO schema:
```graphql
type Todo @model {
id: ID!
name: String!
description: String
}
```
From there run `amplify push` and then `amplify console api` -> Select GraphQL and go to the AppSync console.
Find the `input ModelTodoFilterInput { ... }` and add `_deleted: ModelBooleanInput` to it so it looks similar to this:
```graphql
input ModelTodoFilterInput {
id: ModelIDInput
name: ModelStringInput
description: ModelStringInput
and: [ModelTodoFilterInput]
or: [ModelTodoFilterInput]
not: ModelTodoFilterInput
_deleted: ModelBooleanInput
}
```
Now you should be able to run a GraphQL query and not return the items which have been soft deleted:
```graphql
query q {
listTodos (filter: {
_deleted : {
ne: true
}
}) {
items {
id
name
description
_deleted
}
}
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment