Open3

HasuraでGraphQL再入門

きょんきょん

Writing data - Mutations

Graphiqlで動作確認

Basic mutation

mutation {
  insert_todos(objects: [{title: "new todo"}]) {
    returning {
      id
      title
      is_completed
      is_public
      created_at
    }
  }
}
  • returningで指定したfieldsのみ帰ってくる

動的なmutation

# The parameterised GraphQL mutation
mutation($todo: todos_insert_input!){
  insert_todos(objects: [$todo]) {
    returning {
      id
    }
  }
}
# As a query variable
{
  "todo": {
    "title": "A new dynamic todo"
  }
}

Reference

https://hasura.io/learn/graphql/typescript-react-apollo/intro-to-graphql/3-writing-data-mutations/

きょんきょん

Watching data - Subscriptions

  • 問い合わせではなく、サーバからのpushでdataを受け取ることができる
subscription {
  online_users {
    id
    last_seen
    user {
      name
    }
  }
}