-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GraphQL should not return _deleted items in response #12933
Comments
Hello, @osehmathias 👋 and thank you for opening this issue. Want to see if I can help provide some guidance on what you're experiencing and see if there's a way to get the desired outcome you're looking for. It's expected behavior for the soft-deleted records to be included when performing GraphQL operations against a sync-enabled API. As of 05/02/23 when this PR was merged into the Can you clarify if you might be using an older version of the CLI and/or if you haven't potentially pushed a change to your API (via the |
My amplify version is as follows:
I started the project after the release date of said feature, and have been constantly pushing updates the API. I started with GraphQL and later added DataStore. My problem is not with DataStore. When I delete a record through the GraphQL API, e.g.
The response comes back with a Unfortunately, I was not able to update the resolver as I can't filter on a non-indexed field, unless I define it in the schema, and even then, I don't think you can use boolean filters in Amplify. I ended up just filtering out all deleted records on the frontend after the query. It's not ideal because of pagination. |
@osehmathias This is expected behavior. You should be able to filter on the If you look at the input ModelPostFilterInput {
id: ModelIDInput
title: ModelStringInput
and: [ModelPostFilterInput]
or: [ModelPostFilterInput]
not: ModelPostFilterInput
_deleted: ModelBooleanInput
blogPostsId: ModelIDInput
} you can then filter in your query like this: query MyQuery {
listPosts(filter: {_deleted: {attributeExists: false}}) {
items {
id
title
_deleted
}
} OR query MyQuery {
listPosts(filter: {_deleted: {ne: true}}) {
items {
id
title
_deleted
}
} Closing this issue as it is expected behavior and probably not going to change after the _deleted field has been exposed via the filter input. We can re-open if you experience issues with filtering. We don't recommend mixing DataStore and the API GraphQL client in the same app but if you have to: |
The I know using GraphQL API and DataStore together is not recommended, but in this instance I can't use DataStore in the web version. |
I'm mixing it too as many other devs, since there is no DataStore client for the backend 🤷 The front-end would be a pita without it, and the front-end is pita without custom queries in Lambda (backend). Regarding the workaround with the filter, it wouldn't work for a simple case of getting the latest stored item (schema has index with sortKeyFields of time created)
Unless DDB expiration is set to a value much lower than the frequency of the access pattern. |
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
GraphQL API, DataStore
Amplify Version
v6
Amplify Categories
auth, storage, function, api, analytics, hosting, notifications
Backend
Amplify CLI
Environment information
Not relevant.
Describe the bug
DataStore is fantastic. GraphQL is fantastic. When they work together, they are not fantastic.
Sometimes, you need to use both together. For example, when you have a React app that uses GraphQL, where it is not appropriate to use DataStore because it syncs all the user's data to the device, unencrypted, which is not allowed for health applications. For example, when you have a Flutter app that uses DataStore, where it is fine to use DataStore because the app instance is encrypted, but not appropriate to use GraphQL given the latency issues in fetching data do not make for a great mobile experience.
These two systems should be able to work together closely.
There are two major problems.
_deleted
- this one is REALLY bad. You can't filter on the field, and even if you delete an item, it has no effect on the GraphQL api which really should not be returning deleted items. I believe this is a relatively simple fix for the team. In lieu, I have to update the resolvers or add some funky frontend stuff with a custom field. It's not great.Expected behavior
_deleted
records do not get fetched with the GraphQL API.Reproduction steps
The text was updated successfully, but these errors were encountered: