Explore users on GraphQL API

Hasura gives you Instant GraphQL APIs over Postgres, among other databases. Therefore, it can be tested on the table that we just created.

Let's go ahead and start exploring the GraphQL API for users table. We are going to use GraphiQL to explore the API. GraphiQL is the GraphQL integrated development environment (IDE). It's a powerful tool we'll use to interact with the API.

You can access GraphiQL by heading over to Console -> API -> GraphiQL tab.

Mutation

Let's add a user using a GraphQL Mutation. Copy the following code into the GraphiQL interface.

mutation {
insert_users(objects:[{id: "1", name:"Praveen"}]) {
affected_rows
}
}

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

You should get a response looking something like this:

User Mutation

Great! You have now consumed the mutation query for the users table that you just created.

Tip: You can use the Explorer on the GraphiQL interface to generate the mutation in a few clicks.

Query

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

query {
users {
id
name
created_at
}
}

You should get a response looking something like this:

User Query

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

Subscription

Let's run a subscription query over users table to watch for changes to the table.

subscription {
users {
id
name
created_at
}
}

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

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

In a new browser tab, Head over to Console -> DATA tab -> default -> public -> users -> Insert Row and insert another row.

Insert new user

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

User Subscription

An active subscription query will keep returning the latest set of results depending on the query.

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. โœŒ๏ธ