GraphQL API Cascade Deletion
Describe the bug
Hi, I'd like to clarify something. I noticed that when I delete the source model of relational data using GraphQL, its relationships still stay in the database. Is this normal behaviour? I'd expect that if a model is deleted (especially the source model), all its other relationships should get deleted as well and not be queried. I'm currently having to delete each of it's relational data at the moment. I just thought to clarify / raise this.
Steps To Reproduce
Steps to reproduce the behavior:
1. Create a schema with relational data.
2. Try to delete it.
3. The main data deletes, but leaves its other relational data.
Expected behavior
To delete the data and all its relations automatically.
Amplify Framework Version
2.8.0
Amplify Categories
API
Dependency manager
Swift PM
Swift version
5
CLI version
11.1.1
Xcode version
14
Relevant log output
<details>
<summary>Log Messages</summary>
INSERT LOG MESSAGES HERE
```
Is this a regression?
Yes
Regression additional context
No response
Device
iPhone 14
iOS Version
15
Specific to simulators
No response
Additional context
No response
Hi @dan-codes1 Thank you for reaching us. Could you please clarify on what you mean by delete source model of relational data using GraphQL ? Are you deleting the an item by calling Amplify.Datastore.delete or are you going to AppSync console and invoking a delete operation?
As per this https://github.com/aws-amplify/amplify-swift/issues/933 deleting a parent should delete all the child items.
@royjit for example, let us say we have Post and Comment models. A Post can have many Comment (@hasMany relationship).
If I call try await Amplify.API.mutate(request: .delete(Post)), it deletes the post model, but leaves all the comments that belong to the post undeleted.
This is what I mean. I expect that if a Post is deleted, then all the Comment that belongs to the post get deleted as well.
Cascade delete is supported only in Datastore and not in API GraphQL, you have to delete each item individually.
Noted. Can this be made a feature request? @royjit
Marking this as a feature request, will update here when we have more info to share.
This has been identified as a feature request. If this feature is important to you, we strongly encourage you to give a 👍 reaction on the request. This helps us prioritize new features most important to you. Thank you!
@royjit just realized this is already also a feature request in the category-api repo: https://github.com/aws-amplify/amplify-category-api/issues/273
This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.