Including _version in delete requests, unable to filter _deleted items from list response.
See original GitHub issueWhich Category is your question related to? Using AWS Amplify API to delete items through AWS Appsync
Amplify CLI Version 4.18.1
What AWS Services are you utilizing? AWS Appsync, DynamoDB
Provide additional details e.g. code snippets While using API.graphql to delete items from my database I have 2 following issue:
Issue # 1:
Here is my request to delete a photo from the frontend:
API.graphql(graphqlOperation(mutations.deletePhoto, {
input: {
id: photoId,
_version: 1,
}
})) as unknown as {
data: DeletePhotoMutation
}
Currently, there’s no way for me delete an item without including the _version
of the item without running into an error:
errorType: "ConflictUnhandled"
message: "Conflict resolver rejects mutation."
Is this intended? Or am I missing something.
Issue # 2 :
When I successfully deleted the item using the API by adding in the _version
attributes, I verified that the deleted
attributes in DynamoDB is false
,
When I list all the items again, I couldn’t find a way to filter out deleted
items from server side. The generated types for the filter is like so:
export type ModelPhotoFilterInput = {
id?: ModelIDInput | null,
albumId?: ModelIDInput | null,
bucket?: ModelStringInput | null,
and?: Array< ModelPhotoFilterInput | null > | null,
or?: Array< ModelPhotoFilterInput | null > | null,
not?: ModelPhotoFilterInput | null,
};
So now I have to fetch all items from serverside and filter deleted items out on the front end like so
const listPhotosByAlbum = async (input: ListPhotosByAlbumQueryVariables): Promise<any> => {
const response = await API.graphql(graphqlOperation(queries.listPhotosByAlbum, input)) as unknown as {
data: ListPhotosByAlbumQuery
};
return response.data.listPhotosByAlbum.items.filter(item => item._deleted !== true);
};
which isn’t ideal considering the number of deleted items can grow indefinitely and slow down the response.
Appreciate if anyone can share their experience.
Issue Analytics
- State:
- Created 3 years ago
- Comments:19 (5 by maintainers)
Same issue, shouldn’t Appsync Resolvers filter out
_deleted=true
?I have to agree with Mentioum & drixta, seems like an unnecessary pain to have filter out deleted items on the client side, and not enable a query of non-deleted items from the server. I’m running into this same issue, and it’s too bad that I can’t filter or do something to query out the _deleted items server side via : listBlogs(filter: {type: {notContains: “_deleted”}}), I guess I will look at creating my own field “trash”, move the item to the “trash”, delete it, and then filter it out non trash from my main queries, but that seems like lot of extra unnecessary steps.