English 中文(简体)
Implementing Transaction or Saga with GraphQL using Hasura Client
原标题:

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.

问题回答

暂无回答




相关问题
WCF Transaction Flow Question

I would like to configure WCF service operations to accept a transaction if my client sends one, but not to create one if none is sent. I think this would be similar to the Supported transaction ...

question about pl/sql exception

the following text is an excerpt of oracle documentation Oracle® Database PL/SQL Language Reference 11g Release 1 (11.1) : Unhandled exceptions can also affect subprograms. If you exit a ...

SQL Server - transactions roll back on error?

We have client app that is running some SQL on a SQL Server 2005 such as the following: BEGIN TRAN; INSERT INTO myTable (myColumns ...) VALUES (myValues ...); INSERT INTO myTable (myColumns ...) ...

Cannot rollback transaction with Entity Framework

I have to do queries on uncommitted changes and I tried to use transactions, but I found that it do not work if there are exceptions. I made a simple example to reproduce the problem. I have a ...

mySQL - Prevent double booking

I am trying to work out the best way to stop double booking in my application. I have a table of unique id s each can be sold only once. My current idea is to use a transaction to check if the ...

热门标签