Sign up for Hasura Newsletter
Loading...

todoの更新 - mutation

ここでは、GraphQL Mutationsを使って既存のtodoの完了をマークする方法を学びます。

todosでmutationを行うためのgraphql queryを定義します。

mutation toggleTodo ($id: Int!, $isCompleted: Boolean!) {
update_todos(where: {id: {_eq: $id}}, _set: {is_completed: $isCompleted}) {
affected_rows
}
}

また、variablesに値を渡す必要もあります。

アプリケーションデータベースに対してGraphiQLでこのmutationを試して、どのような応答が得られるかを確認します。

それでは、このgraphql mutationをReactアプリに組み込みましょう。

Did you find this page helpful?
Start with GraphQL on Hasura for Free
  • ArrowBuild apps and APIs 10x faster
  • ArrowBuilt-in authorization and caching
  • Arrow8x more performant than hand-rolled APIs
Promo
footer illustration
Brand logo
© 2024 Hasura Inc. All rights reserved
Github
Titter
Discord
Facebook
Instagram
Youtube
Linkedin