Query Data with GraphQL

After loading the sample database to YugabyteDB, you can benefit from the GraphQL API layer provided by Hasura. In this and the following final sections, you will use GraphQL queries and mutations to process the data stored in the YugabyteDB cluster.

Expose Tables to GraphQL Layer

Even though Hasura automatically detects structural changes on the database side, you still need to specify explicitly what tables can be queried with GraphQL APIs.

Expose the Users and Todos tables to the GraphQL layer:

  • Open the Data & Schema Management tab of the Hasura Console.
  • Click the Track All button to be able to work with both Users and Todos via GraphQL APIs.

Query Users

Next, read records of the Users table with GraphQL:

  1. Open the API Explorer tab of the Hasura Console:

  1. Execute the GraphQL query below:
query {
users {
id
name
created_at
last_seen
}
}
  1. Confirm the output is as follows:
{
"data": {
"users": [
{
"id": 1,
"name": "Mark",
"created_at": "2022-02-02T18:49:45.092247",
"last_seen": null
},
{
"id": 2,
"name": "Jenny",
"created_at": "2022-02-02T18:49:45.092247",
"last_seen": null
}
]
}
}

As you see, your Hasura instance successfully receives the query, translates it to a Postgres-compliant SQL request, and executes over YugabyteDB data.

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