Left patternRight pattern

Build modern apps & APIs with Hasura & GraphQL

Hasura gives you instant GraphQL APIs on your data by removing the pain of building and maintaining your own GraphQL servers.

Hasura is a fully automated, GraphQL spec compliant server that connects to databases & services to provide a secure, scalable and unified GraphQL API.

GraphQL in a snapshot

What is GraphQL?

GraphQL is a specification (query language) of how to talk to an API. It’s typically used over HTTP where the key idea is to POST a “query” to an HTTP endpoint, instead of hitting different HTTP endpoints for different resources. GraphQL is designed for developers of web/mobile apps to be able to make API calls to fetch exactly the data they need from their backend APIs.

GraphQL is made for modern web and mobile clients. GraphQL defines a standard grammar for a query language to read/write data. With GraphQL you can fetch exactly what you want from your app’s backend. It kind of looks like a neater JSON with just the keys and allows you to pass arbitrary parameters in the query.

Why GraphQL?

Developers love using GraphQL because it’s the most convenient API for JSON data. GraphQL is easy to read and debug, and has a rich ecosystem of community tooling. GraphQL is database agnostic and can be used with any language or framework.

GraphQL Schema and Type System contract enables frontend and backend developers to collaborate and work independently.
Tanmai Gopal
Tanmai Gopal
Cofounder & CEO
Hasura, Inc.
Watch Tanmai’s talk introducing GraphQL >

Breaking down GraphQL

  • GraphQL Server
  • GraphQL Client
  • GraphQL Spec
To serve a GraphQL API to your client, you need a GraphQL server. Hasura is a web application server that instantly generates GraphQL APIs out of the box, such that you don’t need to build a GraphQL server.

Hasura auto generates a GraphQL API on your databases & services and lets you extend the graph using Hasura Actions.

You can bring in existing GraphQL servers and stitch them together with Hasura using the Remote Schemas feature, and join data across your database & services using Remote Joins.

Hasura as a high-performance GraphQL Server

Hasura compiles a GraphQL query of any length to a single SQL query. Internally Hasura enriches the GraphQL AST with user given permissions & maps rules to create an SQL AST.

Hasura also caches your GraphQL query plan and makes highly optimised database calls. It also provides out of the box GraphQL subscriptions that can be consumed at scale.

What is the N+1 Problem with GraphQL

GraphQL query execution typically involves executing a resolver for each field. Say we're fetching authors and their articles. Now for each author record in the database, we would invoke a function to fetch their N articles, So total round trips become N+1 and this could become a huge performance bottleneck. The number of queries grows exponentially with the depth of the query.

Hasura mitigates the N+1 problem as at its core, the server is a compiler. All your GraphQL queries to fetch data are compiled to a single SQL query that reduces the number of hits to the database, thereby improving performance.

N+1 Problem with GraphQL
GraphQL requests can be made using your favorite HTTP clients since the underlying request/response format is usually JSON. But there’s more to a GraphQL client than just making HTTP requests, from caching to making realtime apps easy, Hasura provides support for all GraphQL Clients, including Relay (preview). There’s a rich ecosystem of GraphQL clients.

Benefits of GraphQL Clients

GraphQL Subscriptions & websockets:

Consuming a realtime API over websockets usually requires a lot of setup. GraphQL Clients like Apollo, Urql make it easy to set it up.

GraphQL Fragments & data co-location:

Relay uses Fragments to declare data requirements for components and compose data requirements together. All data dependencies live alongside component definitions and make it easier to reason about requirements for UIs.

GraphQL Caching:

The schema and introspection features of GraphQL enables a client to cache responses on the frontend.

GraphQL breakdown

GraphQL Schema and Type System

In REST APIs, there isn't a concept of a schema or type system. On the other hand, GraphQL has a strong type system to define what the API looks like. A schema is defined with fields mapped to types and serves as a contract between the client and the server.
The schema contract lets frontend and backend devs work independently with guarantees that data requirements are always met. In REST APIs though, there's no strict contract. Following the OpenAPI spec will get you closer to GraphQL in terms of documentation. Community tooling around the OpenAPI spec gives an idea about the various endpoints and data payloads for REST APIs.

GraphQL Queries

A GraphQL query allows you to fetch data. Ask what you want and get your results in the same shape. Fetch multiple resources at a time. Pagination, filter and sort using arguments for more granular data fetching.
GraphQL Queries

GraphQL Mutations

A GraphQL Mutation allows you to manipulate data. Update single or multiple objects with any level of nesting, conditional updates or deletes using arguments. Make upsert operations on conflicts to simplify app logic and return data back to the client post the mutation.
Mutation

GraphQL Subscriptions

A GraphQL Subscription allows you to subscribe to realtime data from a GraphQL server. The subscription API is exposed over websockets that can be easily consumed on the client. Hasura has in-built support from GraphQL subscriptions and lets you turn any query to a subscription.
Subscription

What is the difference in using GraphQL and REST?

GraphQL Rest
With the advent of GraphQL, we're changing the way we think about API calls. Instead of making different API calls to different URLs to fetch data, we're making ad-hoc queries to a "single URL endpoint" that returns data based on the query.

A GraphQL server gives you a single endpoint as opposed to having to use multiple endpoints while working with REST.
GraphQL has a schema and type system. REST doesn’t enforce any type system. Since the schema is flexible, GraphQL encourages clients to make a single query instead of multiple roundtrips over HTTP. The schema and types allow the front end client to enable caching better than REST APIs. You will also avoid over-fetching with GraphQL by specifying exactly what fields are needed.

Application Architectures with GraphQL and Hasura

GraphQL API for your microservices: Using Hasura Remote Schemas & Remote Joins

Microservices

Hasura can connect to databases, upstream “mid-tier” microservices, external SaaS APIs and event-driven business logic to expose a unified GraphQL API.

Hasura is designed to integrate with the emerging cloud-native patterns for building services. The future of business logic workflows in APIs or serverless functions is going to be event driven, and Hasura makes that easy. Hasura provides an authorization engine that allows for securing the unified GraphQL API, including a powerful role, attribute and rule based access control.

GraphQL with Serverless: Hasura serves as a data layer for serverless applications

GraphQL Serverless

In Hasura, business logic workflows in APIs or serverless functions are event driven. Hasura also provides a way to create custom GraphQL mutations which are internally converted to events and delivered to serverless functions in an event-driven way. This makes it possible to integrate and migrate to event-driven business logic seamlessly.

Hasura Cloud gives you a scalable, highly available, globally distributed, secure GraphQL API over your data sources.

What is GraphQL Federation?

GraphQL Federation
GraphQL Federation is an approach that lets you consolidate multiple schemas and APIs into a unified API. Hasura enables data federation between GraphQL and REST services, as well as databases. The unified API might be required for a team that has multiple sources of data for their application or might be a unified GraphQL API across various teams maintained by a central data API team in the organisation.

What applications can I build with GraphQL?

Facebook built the initial GraphQL spec to optimise data fetching in mobile applications. GraphQL became open source in 2015 and the tools around it have improved since then. GraphQL can be used both server side and client side. On the server side, the GraphQL API can fetch data from multiple data sources (like rest apis, existing data in db) through any programming language. The client can connect to GraphQL servers and request for results in JSON. This could be any front end client on mobile / web, enabling developers to build any production ready app quickly.

We’d love to connect with you at one of our many global events.

Event
HasuraCon 2021HasuraCon 2021Community call
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.
Get monthly product updates
Sign up for full access to our product and community highlights, new features, and occasional baby animal gifs! Oh, and we have a strict no-spam rule. ✌️