2020-01-14 15:57:45 +03:00
|
|
|
|
.. meta::
|
|
|
|
|
:description: How Hasura GraphQL engine works
|
|
|
|
|
:keywords: hasura, docs, graphql engine, how it works
|
|
|
|
|
|
2020-03-11 22:42:36 +03:00
|
|
|
|
.. _how_it_works:
|
|
|
|
|
|
2019-01-04 20:25:48 +03:00
|
|
|
|
How Hasura GraphQL engine works
|
|
|
|
|
===============================
|
|
|
|
|
|
|
|
|
|
.. contents:: Table of contents
|
|
|
|
|
:backlinks: none
|
|
|
|
|
:depth: 1
|
|
|
|
|
:local:
|
|
|
|
|
|
2019-09-11 10:17:14 +03:00
|
|
|
|
Given a Postgres database, the Hasura GraphQL engine can automatically generate a GraphQL schema and process GraphQL
|
|
|
|
|
queries, subscriptions and mutations. Here’s what the Hasura GraphQL engine does under the hood.
|
2019-01-04 20:25:48 +03:00
|
|
|
|
|
|
|
|
|
Schema generation
|
|
|
|
|
-----------------
|
|
|
|
|
|
2019-09-11 10:17:14 +03:00
|
|
|
|
The Hasura GraphQL engine automatically generates GraphQL schema components when you track a
|
2019-01-04 20:25:48 +03:00
|
|
|
|
Postgres table/view in Hasura and create relationships between them.
|
|
|
|
|
|
|
|
|
|
Tables
|
|
|
|
|
^^^^^^
|
|
|
|
|
|
2019-09-11 10:17:14 +03:00
|
|
|
|
When you track a Postgres table in the Hasura GraphQL engine, it automatically generates the following for it:
|
2019-01-04 20:25:48 +03:00
|
|
|
|
|
|
|
|
|
- A GraphQL type definition for the table
|
2019-09-11 10:17:14 +03:00
|
|
|
|
- A query field with ``where``, ``order_by``, ``limit`` and ``offset`` arguments
|
|
|
|
|
- A subscription field with ``where``, ``order_by``, ``limit`` and ``offset`` arguments
|
|
|
|
|
- An insert mutation field with ``on_conflict`` argument that supports upsert and bulk inserts
|
|
|
|
|
- An update mutation field with ``where`` argument that supports bulk updates
|
|
|
|
|
- A delete mutation field with ``where`` argument that supports bulk deletes
|
2019-01-04 20:25:48 +03:00
|
|
|
|
|
|
|
|
|
Views
|
|
|
|
|
^^^^^
|
|
|
|
|
|
|
|
|
|
When you track a Postgres view in Hasura GraphQL engine, it automatically generates the following for it:
|
|
|
|
|
|
|
|
|
|
- A GraphQL type definition for the view
|
2019-09-11 10:17:14 +03:00
|
|
|
|
- A query field with ``where``, ``order_by``, ``limit`` and ``offset`` arguments
|
|
|
|
|
- A subscription field with ``where``, ``order_by``, ``limit`` and ``offset`` arguments
|
2019-01-04 20:25:48 +03:00
|
|
|
|
|
2019-09-11 10:17:14 +03:00
|
|
|
|
Essentially the Hasura GraphQL engine does the same thing it would do for a table, but without creating the insert, update
|
2019-01-04 20:25:48 +03:00
|
|
|
|
and delete mutations.
|
|
|
|
|
|
|
|
|
|
Relationships
|
|
|
|
|
^^^^^^^^^^^^^
|
2019-09-11 10:17:14 +03:00
|
|
|
|
When you create a relationship between a table/view with another table/view in the Hasura GraphQL engine, it does the
|
2019-01-04 20:25:48 +03:00
|
|
|
|
following:
|
|
|
|
|
|
|
|
|
|
- Augments the type of the table/view by adding a reference to the nested type to allow fetching nested objects.
|
|
|
|
|
- Augments the ``where`` and ``order_by`` clauses to allow filtering and sorting based on nested objects.
|
|
|
|
|
|
|
|
|
|
Resolvers
|
|
|
|
|
---------
|
|
|
|
|
|
2019-09-11 10:17:14 +03:00
|
|
|
|
The Hasura GraphQL engine does not have any resolvers. The Hasura GraphQL engine is actually a compiler that compiles
|
|
|
|
|
your GraphQL query into an efficient SQL query.
|
2019-01-04 20:25:48 +03:00
|
|
|
|
|
|
|
|
|
Hasura's GraphQL syntax is also optimized to expose the power of the underlying SQL so that you can make powerful
|
|
|
|
|
queries via GraphQL.
|
|
|
|
|
|
|
|
|
|
Metadata
|
|
|
|
|
--------
|
|
|
|
|
|
2019-10-17 15:02:01 +03:00
|
|
|
|
All the information required for schema generation is stored by the Hasura GraphQL engine as metadata in its "catalogue"
|
|
|
|
|
which is essentially a special Postgres schema in the database.
|
|
|
|
|
|
2020-03-11 22:42:36 +03:00
|
|
|
|
See :ref:`metadata catalogue <hasura_metadata_schema>` for more details.
|
2019-01-04 20:25:48 +03:00
|
|
|
|
|
|
|
|
|
.. toctree::
|
|
|
|
|
:maxdepth: 1
|
|
|
|
|
:hidden:
|
|
|
|
|
|
2019-10-17 15:02:01 +03:00
|
|
|
|
Metadata catalogue <metadata-schema>
|