Explore todos on GraphQL API

Similar to the users table, the todos table created in the previous step would have an auto-generated GraphQL API for us to explore.

Let's go ahead and start exploring the GraphQL API for todos table.

Mutation

Head over to Console -> API -> GraphiQL tab and insert a todo using GraphQL Mutations.

mutation {
insert_todos(objects:[{title: "My First Todo", user_id: "1"}]) {
affected_rows
}
}

Click on the Play button on the GraphiQL interface to execute the query.

You should get a response looking something like this:

Todo Mutation

Query

Now let's go ahead and query the data that we just inserted.

query {
todos {
id
title
is_public
is_completed
user_id
}
}

You should get a response looking something like this:

Todo Query

Note that some columns like is_public and is_completed have default values, even though you did not insert them during the mutation.

Subscription

Let's run a subscription query over todos table to watch for changes to the table. In the above GraphQL query, replace query with subscription

subscription {
todos {
id
title
is_public
is_completed
user_id
}
}

Initially, the subscription query will return the existing results in the response.

Now let's insert new data into the todos table and see the changes appearing in the response.

In a new tab, Head over to Console -> DATA tab -> todos -> Insert Row and insert another row.

Insert new todo

And switch to the previous API tab and see the subscription response returning 2 results.

Todo Subscription

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