...

GraphQL has fundamentally changed the way developers interact with APIs, offering a more efficient, intuitive, and powerful alternative to traditional REST APIs. When paired with Hasura, a high-performance GraphQL engine, developers can instantly expose a real-time, fully functional GraphQL API over a PostgreSQL database with minimal backend work.

This guide dives into how GraphQL works, how Hasura streamlines API development, and how you can leverage Hasura’s features to build modern, scalable applications with ease.

What is GraphQL?

GraphQL is a query language and runtime for APIs developed by Facebook. Unlike REST, which requires multiple endpoints for different resources, GraphQL provides a single endpoint where clients can request exactly the data they need, nothing more, nothing less.

Core Concepts of GraphQL

  • Queries: Fetch data.
  • Mutations: Modify data (create, update, delete).
  • Subscriptions: Receive real-time updates when data changes.

Advantages of GraphQL

  • Exact Data Fetching – Clients define the structure of the response, avoiding over-fetching or under-fetching.
  • Hierarchical Structure – Queries mirror the nested shape of the data ideal for relational datasets.
  • Strongly Typed Schema – The API is defined by a type system. Each field has a clear type, allowing for validation, introspection, and auto-generated documentation.
  • Introspective by Design – Clients can query the schema itself. This enables tools like GraphiQL, autocomplete features in IDEs and automated code generation.
  • Backend Agnostic – GraphQL is not tied to a database. It’s a protocol. You can use it over SQL, NoSQL, microservices, or any combination.

What is Hasura?

Hasura is an open-source GraphQL engine that sits on top of a PostgreSQL database and automatically generates a GraphQL API based on the database schema. It requires zero boilerplate code to get started, and within minutes, you can begin querying your data with GraphQL.

Key Features of Hasura

  • Instant GraphQL API – Connect Hasura to your Postgres DB, and it auto-generates a GraphQL schema.
  • Real-time Capabilities with Subscriptions – Built-in support for live queries and event-driven systems.
  • Fine-grained Access Control – Define role-based permissions at a row, column, and operation level.
  • Remote Schemas & Actions – Extend Hasura with custom resolvers and business logic written in your language of choice.
  • SQL-style Pagination – Use limit, offset, and order by parameters like SQL, which is great for frontend developers familiar with database queries.

Hasura’s GraphQL Schema Design

Hasura maps your Postgres tables and views to GraphQL types and fields automatically. Here’s how Hasura structures the schema:

  • Queries and Mutations are organized under the database schema (unless in the default public schema).
  • Table names become queryable types (e.g., kiosk_kioskmapping).
  • Relationships (foreign keys) become nested fields, allowing deep, connected queries.

Schema Prefixing

Hasura prefixes each query with the database schema name, like:

GraphQL APIs with Hasura

This spacing helps prevent conflicts when dealing with multiple schemas. However, it can be verbose and confusing, especially for front-end developers unfamiliar with the database structure.

Limitations:

  • No current way to disable or customize the schema prefixing unless you deploy separate Hasura instances per schema.
  • Best suited for internal tools or applications where database structure is transparent to the development team

Working with Hasura

The kiosk_kioskmapping query accepts serialNumber as a parameter. In the example below, we’re retrieving the mapping details in response. It’s simple and familiar, just like SQL, which is common in both REST and GraphQL APIs. Also, we can apply sorting and handling pagination using offset and limit.

  • Querying a Table
GraphQL with Hasura
GraphQL with Hasura
  • Where: Filters the records.
  • Result: Only the requested fields are returned efficiently and predictably.

  • Nested Request and Response
GraphQL APIs with Hasura

Nested mutation: patient summary and its related mapping in one go

  • Pagination and Sorting
  • order by: Sorts results.
  • limit / offset: Controls pagination.

This SQL-like syntax is intuitive for backend and frontend developers alike.

  • Mutation with Nested Input
GraphQL APIs
  • Nested mutation: Insert a kiosk and its related mapping in one go.
  • Hasura understands the relationship and handles it automatically.

When Should You Use Hasura?

Hasura is a great fit when:

  • You want a rapid GraphQL API over an existing PostgreSQL database.
  • Your app needs real-time data, especially for dashboards, CRMs, or analytics tools.
  • You want powerful RBAC and permissioning built in.
  • You want to prototype fast without writing backend code.

But you might reconsider if:

  • You require fully custom business logic in every query.
  • You need total control over the schema Hasura’s auto-generation can be restrictive in deeply customized APIs.
  • You’re using a non-Postgres database (though Hasura now supports some other data sources with limitations).

Conclusion

GraphQL combined with Hasura gives developers a powerful toolkit to build modern, scalable APIs with speed and precision. You gain the flexibility and expressiveness of GraphQL, along with Hasura’s auto-generation, real-time capabilities, and robust access control, all while reducing boilerplate and improving productivity.

Hasura works best when the database schema is clean, relational, and designed with Hasura’s conventions in mind. For many use cases, especially internal tools, dashboards, and admin panels, it’s hard to beat the time-to-value Hasura offers.