I am working on a project where I need to execute multiple GraphQL mutations in a single transaction using the Hasura client. I m also interested in a saga transaction implementation if possible. However, I am having trouble achieving this and would appreciate some guidance or best practices suggestions.
Let me give a bit more context with a simple scenario. Consider the following GraphQL mutation:
mutation reset_author {
delete_article (
where: {author_id: {_eq: 6}}
) {
affected_rows
}
update_author (
where: {id: {_eq: 6}} _set: {name: "Cory"}
) {
returning {
id
name
}
}
}
In this mutation, I m first deleting all articles associated with a specific author (author_id: 6), then I m updating the name of the author to "Cory".
I d like to know if there is a way to use the affected_rows result from the delete_article mutation as part of the where or _set conditions in the update_author mutation that follows? Based on my research, this doesn t seem to be directly supported, but perhaps there s a workaround?
Additionally, I m wondering how I could wrap these two mutations into a single transaction, ensuring that either both succeed or both fail. In essence, what I m looking for is an approach to create a saga transaction using GraphQL and Hasura.
Any guidance or direction on this would be greatly appreciated.