amplify-swift icon indicating copy to clipboard operation
amplify-swift copied to clipboard

GraphQL API Cascade Deletion

Open dan-codes1 opened this issue 2 years ago • 7 comments

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

dan-codes1 avatar Jun 15 '23 20:06 dan-codes1

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 avatar Jun 22 '23 16:06 royjit

@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.

dan-codes1 avatar Jul 05 '23 18:07 dan-codes1

Cascade delete is supported only in Datastore and not in API GraphQL, you have to delete each item individually.

royjit avatar Jul 07 '23 18:07 royjit

Noted. Can this be made a feature request? @royjit

dan-codes1 avatar Jul 11 '23 00:07 dan-codes1

Marking this as a feature request, will update here when we have more info to share.

royjit avatar Jul 14 '23 16:07 royjit

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!

github-actions[bot] avatar Jul 14 '23 16:07 github-actions[bot]

@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

dan-codes1 avatar Jul 14 '23 19:07 dan-codes1

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.

github-actions[bot] avatar May 07 '24 05:05 github-actions[bot]