yahoo/elide

Does Elide GraphQL support cascading delete?

QubitPi opened this issue · 3 comments

Hi Elide team, we have a question on DELETE/REMOVE operation in GraphQL API:

If say we have an Author/Book relationship, where 1 author links to multiple books. When we create an author with 3 books and later delete that author by specifying author ID only, will all 3 books be deleted as well? If so, does data model needs to be annotated with some JPA annotation? We read through the documentation but failed to find the answer.

Thanks,

Jack

Thank you. That worked. Please let me know if you would like this to be included in elide documentation and I'm happy to do it

Elide itself doesn’t cascade deletes but JPA can. You have to a note the model with JPA annotations.

Here is an example in Yavin:

@OneToMany(mappedBy = "dashboard", cascade = [CascadeType.REMOVE], orphanRemoval = true)
var widgets: MutableSet<DashboardWidget> = mutableSetOf()

https://github.com/yavin-dev/framework/blob/cd2b41054f723789600f5de4ae7d4f16f11584b5/packages/webservice/models/src/main/kotlin/com/yahoo/navi/ws/models/beans/Dashboard.kt#L54-L55