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 -> 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, 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 GRAPHIQL tab and see the subscription response returning 2 results.

Todo Subscription

Close

Get Started with GraphQL Now

Hasura Cloud gives you a fully managed, production ready GraphQL API as a service to help you build modern apps faster.
Ready to get started?
Start for free on Hasura Cloud or you could contact our sales team for a detailed walk-through on how Hasura may benefit your business.
Stay in the know
Sign up for full access to our community highlights, new features, and occasional baby animal gifs! Oh, and we have a strict no-spam rule. ✌️