Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
Go to file
Antoine Leblanc 6e574f1bbe harmonize network manager handling
## Description

### I want to speak to the `Manager`

Oh boy. This PR is both fairly straightforward and overreaching, so let's break it down.

For most network access, we need a [`HTTP.Manager`](https://hackage.haskell.org/package/http-client-0.1.0.0/docs/Network-HTTP-Client-Manager.html). It is created only once, at the top level, when starting the engine, and is then threaded through the application to wherever we need to make a network call. As of main, the way we do this is not standardized: most of the GraphQL execution code passes it "manually" as a function argument throughout the code. We also have a custom monad constraint, `HasHttpManagerM`, that describes a monad's ability to provide a manager. And, finally, several parts of the code store the manager in some kind of argument structure, such as `RunT`'s `RunCtx`.

This PR's first goal is to harmonize all of this: we always create the manager at the root, and we already have it when we do our very first `runReaderT`. Wouldn't it make sense for the rest of the code to not manually pass it anywhere, to not store it anywhere, but to always rely on the current monad providing it? This is, in short, what this PR does: it implements a constraint on the base monads, so that they provide the manager, and removes most explicit passing from the code.

### First come, first served

One way this PR goes a tiny bit further than "just" doing the aforementioned harmonization is that it starts the process of implementing the "Services oriented architecture" roughly outlined in this [draft document](https://docs.google.com/document/d/1FAigqrST0juU1WcT4HIxJxe1iEBwTuBZodTaeUvsKqQ/edit?usp=sharing). Instead of using the existing `HasHTTPManagerM`, this PR revamps it into the `ProvidesNetwork` service.

The idea is, again, that we should make all "external" dependencies of the engine, all things that the core of the engine doesn't care about, a "service". This allows us to define clear APIs for features, to choose different implementations based on which version of the engine we're running, harmonizes our many scattered monadic constraints... Which is why this service is called "Network": we can refine it, moving forward, to be the constraint that defines how all network communication is to operate, instead of relying on disparate classes constraint or hardcoded decisions. A comment in the code clarifies this intent.

### Side-effects? In my Haskell?

This PR also unavoidably touches some other aspects of the codebase. One such example: it introduces `Hasura.App.AppContext`, named after `HasuraPro.Context.AppContext`: a name for the reader structure at the base level. It also transforms `Handler` from a type alias to a newtype, as `Handler` is where we actually enforce HTTP limits; but without `Handler` being a distinct type, any code path could simply do a `runExceptT $ runReader` and forget to enforce them.

(As a rule of thumb, i am starting to consider any straggling `runReaderT` or `runExceptT` as a code smell: we should not stack / unstack monads haphazardly, and every layer should be an opaque `newtype` with a corresponding run function.)

## Further work

In several places, i have left TODOs when i have encountered things that suggest that we should do further unrelated cleanups. I'll write down the follow-up steps, either in the aforementioned document or on slack. But, in short, at a glance, in approximate order, we could:

- delete `ExecutionCtx` as it is only a subset of `ServerCtx`, and remove one more `runReaderT` call
- delete `ServerConfigCtx` as it is only a subset of `ServerCtx`, and remove it from `RunCtx`
- remove `ServerCtx` from `HandlerCtx`, and make it part of `AppContext`, or even make it the `AppContext` altogether (since, at least for the OSS version, `AppContext` is there again only a subset)
- remove `CacheBuildParams` and `CacheBuild` altogether, as they're just a distinct stack that is a `ReaderT` on top of `IO` that contains, you guessed it, the same thing as `ServerCtx`
- move `RunT` out of `RQL.Types` and rename it, since after the previous cleanups **it only contains `UserInfo`**; it could be bundled with the authentication service, made a small implementation detail in `Hasura.Server.Auth`
-  rename `PGMetadaStorageT` to something a bit more accurate, such as `App`, and enforce its IO base

This would significantly simply our complex stack. From there, or in parallel, we can start moving existing dependencies as Services. For the purpose of supporting read replicas entitlement, we could move `MonadResolveSource` to a `SourceResolver` service, as attempted in #7653, and transform `UserAuthenticationM` into a `Authentication` service.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7736
GitOrigin-RevId: 68cce710eb9e7d752bda1ba0c49541d24df8209f
2023-02-22 15:55:54 +00:00
.circleci [server] re-add native sql output 2023-01-27 14:38:07 +00:00
.devcontainer/docs docs: add docs devcontainer 2022-12-16 17:39:29 +00:00
.github Improve the tone of the OSS issue templates by removing questions 2022-10-19 02:21:46 +00:00
architecture streaming subscriptions architecture: update try it out instructions 2022-09-29 17:28:01 +00:00
assets updated readme gif 2022-02-24 09:38:54 +00:00
cabal server: dev build modes 2023-02-08 22:43:00 +00:00
cli rename naqi to logimo part 3 - data types 2023-02-22 13:46:54 +00:00
cli-ext Upgrade all package-lock.json files to the v2 format. 2022-09-28 08:15:29 +00:00
community Documentation for One Click Deploy to Hasura 2023-02-07 08:36:07 +00:00
console console: hotfix neon auth back in console 2023-01-30 07:54:46 +00:00
contrib/metadata-types contrib: Metadata V3 types + JSON Schema 2021-11-10 05:37:11 +00:00
dc-agents Add tests for update mutations to the Data Connector agent test suite 2023-02-22 04:19:16 +00:00
docker-compose GDC Mysql integration tests 2023-02-16 06:30:51 +00:00
docs docs: Add a documentation page for BigQuery views. 2023-02-21 12:28:17 +00:00
frontend console: add insert handling for permissions 2023-02-22 15:27:16 +00:00
install-manifests console: gdc permissions bug fixes 2023-02-17 14:35:36 +00:00
metadata-api-types server: commit Metadata OpenAPI spec with CI check, add Typescript client scaffolding 2023-02-15 18:38:38 +00:00
nix [Nix] Adds dc-api overlay. 2023-01-30 08:34:53 +00:00
packaging packaging/cli-migrations: Clean up curl containers. 2023-02-16 19:56:10 +00:00
rfcs feat(console): add import single endpoint from openAPI 2022-11-29 19:09:53 +00:00
scripts rename naqi to logimo part 1 2023-02-21 13:46:44 +00:00
server harmonize network manager handling 2023-02-22 15:55:54 +00:00
translations github md pages: update email address for security team 2022-12-01 17:19:51 +00:00
.dockerignore Create a Docker image specifically for running the Python tests. 2022-09-07 14:29:42 +00:00
.envrc direnv: Default to the Azure SQL Edge image on macOS. 2022-10-24 15:54:41 +00:00
.envrc.local.example Nix: Upgrade to GHC 9.2.4. 2022-10-06 21:05:34 +00:00
.ghcversion ghc 9.2.5 2022-11-15 11:26:42 +00:00
.git-blame-ignore-revs frontend: apply prettier 2023-01-25 20:55:24 +00:00
.gitignore remove .ToSource.hs.swp 2023-02-17 10:19:38 +00:00
.hlint.yaml chore: Fix all outstanding hlint hints 2023-02-20 17:43:28 +00:00
.kodiak.toml ci: don't block merge queue when awaiting review, after #7011 2023-02-07 20:31:27 +00:00
.nvmrc tooling: bump .nvmrc version to 16 2022-09-06 11:23:56 +00:00
.prettierignore Add a missing changelog entry for error message changes to v2.10.0. 2022-09-05 09:41:06 +00:00
cabal.project Add tests for update mutations to the Data Connector agent test suite 2023-02-22 04:19:16 +00:00
cabal.project.freeze server: dev build modes 2023-02-08 22:43:00 +00:00
CHANGELOG.md Kriti Documentation 2022-09-06 15:47:18 +00:00
code-of-conduct.md update code of conduct (#2886) 2019-09-16 14:07:52 +05:30
CONTRIBUTING.md community: update contrib guide (#5866) 2020-10-01 10:03:30 +02:00
docker-compose.yaml server/api-tests: Add a Docker Compose file for the API tests. 2023-01-16 16:44:10 +00:00
event-triggers.md docs: update the hasura sample apps links 2022-02-18 17:06:46 +00:00
flake.lock [Nix] Set nixpkgs to 22.11 and update flake lock. 2022-11-30 09:46:48 +00:00
flake.nix [Nix] Adds aeson-ordered overlay. 2023-01-26 21:55:23 +00:00
LICENSE Change license for core GraphQL Engine to Apache 2.0 (#1821) 2019-03-19 16:23:36 +05:30
LICENSE-community add community boilerplates and examples (#430) 2018-09-13 12:00:07 +05:30
Makefile server: commit Metadata OpenAPI spec with CI check, add Typescript client scaffolding 2023-02-15 18:38:38 +00:00
metadata.openapi.json rename naqi to logimo part 3 - data types 2023-02-22 13:46:54 +00:00
package-lock.json console: Update Cypress to v10 and run the migration guide 2022-07-05 08:51:35 +00:00
README.md docs: add Hasura logo (fix #5934 ) 2022-12-21 04:03:48 +00:00
remote-schemas.md update docs link to avoid redirects 2021-03-01 18:51:18 +00:00
sample.hie.yaml [ci] test the libraries in server/lib 2023-02-02 17:32:48 +00:00
SECURITY.md github md pages: update email address for security team 2022-12-01 17:19:51 +00:00
shell.nix Push the Nix dependency management configuration to the OSS repository. 2022-10-11 15:33:22 +00:00
weeder.dhall remove homebrew NESeq, use vendored 2022-07-19 08:42:28 +00:00

Hasura GraphQL Engine

Latest release Docs

Hasura is an open-source product that accelerates API development by 10x by giving you GraphQL or REST APIs with built-in authorization on your data, instantly.

Read more at hasura.io and the docs.


Hasura GraphQL Engine Demo


Hasura GraphQL Engine Realtime Demo


Features

  • Make powerful queries: Built-in filtering, pagination, pattern search, bulk insert, update, delete mutations
  • Works with existing, live databases: Point it to an existing database to instantly get a ready-to-use GraphQL API
  • Realtime: Convert any GraphQL query to a live query by using subscriptions
  • Merge remote schemas: Access custom GraphQL schemas for business logic via a single GraphQL Engine endpoint. Read more.
  • Extend with Actions: Write REST APIs to extend Hasuras schema with custom business logic.
  • Trigger webhooks or serverless functions: On Postgres insert/update/delete events (read more)
  • Scheduled Triggers: Execute custom business logic at specific points in time using a cron config or a one-off event.
  • Fine-grained access control: Dynamic access control that integrates with your auth system (eg: auth0, firebase-auth)
  • Admin UI & Migrations: Admin UI & Rails-inspired schema migrations
  • Supported Databases: Supports PostgreSQL (and its flavors), MS SQL Server and Big Query. Support for more databases coming soon.

Read more at hasura.io and the docs.

Table of contents

Table of Contents

Quickstart:

One-click deployment on Hasura Cloud

The fastest and easiest way to try Hasura out is via Hasura Cloud.

  1. Click on the following button to deploy GraphQL engine on Hasura Cloud including Postgres add-on or using an existing Postgres database:

    Deploy to Hasura Cloud

  2. Open the Hasura console

    Click on the button "Launch console" to open the Hasura console.

  3. Make your first GraphQL query

    Create a table and instantly run your first query. Follow this simple guide.

Other one-click deployment options

Check out the instructions for the following one-click deployment options:

Infra provider One-click link Additional information
Heroku Deploy to Heroku docs
DigitalOcean Deploy to DigitalOcean docs
Azure Deploy to Azure docs
Render Deploy to Render docs

Other deployment methods

For Docker-based deployment and advanced configuration options, see deployment guides or install manifests.

Architecture

The Hasura GraphQL Engine fronts a Postgres database instance and can accept GraphQL requests from your client apps. It can be configured to work with your existing auth system and can handle access control using field-level rules with dynamic variables from your auth system.

You can also merge remote GraphQL schemas and provide a unified GraphQL API.

Hasura GraphQL Engine architecture

Client-side tooling

Hasura works with any GraphQL client. See awesome-graphql for a list of clients. Our frontend tutorial series also have integrations with GraphQL clients for different frameworks.

Add business logic

GraphQL Engine provides easy-to-reason, scalable and performant methods for adding custom business logic to your backend:

Remote schemas

Add custom resolvers in a remote schema in addition to Hasura's database-based GraphQL schema. Ideal for use-cases like implementing a payment API, or querying data that is not in your database - read more.

Actions

Actions are a way to extend Hasuras schema with custom business logic using custom queries and mutations. Actions can be added to Hasura to handle various use cases such as data validation, data enrichment from external sources and any other complex business logic - read more

Trigger webhooks on database events

Add asynchronous business logic that is triggered based on database events. Ideal for notifications, data-pipelines from Postgres or asynchronous processing - read more.

Derived data or data transformations

Transform data in Postgres or run business logic on it to derive another dataset that can be queried using GraphQL Engine - read more.

Demos

Check out all the example applications in the community/sample-apps directory.

Realtime applications

  • Group Chat application built with React, includes a typing indicator, online users & new message notifications.

  • Live location tracking app that shows a running vehicle changing the current GPS coordinates moving on a map.

  • A real-time dashboard for data aggregations on continuously changing data.

Videos

Support & Troubleshooting

The documentation and community will help you troubleshoot most issues. If you have encountered a bug or need to get in touch with us, you can contact us using one of the following channels:

We are committed to fostering an open and welcoming environment in the community. Please see the Code of Conduct.

If you want to report a security issue, please read this.

Stay up to date

We release new features every month. Sign up for our newsletter by using the link below. We send newsletters only once a month. https://hasura.io/newsletter/

Contributing

Check out our contributing guide for more details.

Brand assets

Hasura brand assets (logos, the Hasura mascot, powered by badges etc.) can be found in the assets/brand folder. Feel free to use them in your application/website etc. We'd be thrilled if you add the "Powered by Hasura" badge to your applications built using Hasura. ❤️

<!-- For light backgrounds -->
<a href="https://hasura.io">
  <img width="150px" src="https://graphql-engine-cdn.hasura.io/img/powered_by_hasura_primary_darkbg.svg" />
</a>

<!-- For dark backgrounds -->
<a href="https://hasura.io">
  <img width="150px" src="https://graphql-engine-cdn.hasura.io/img/powered_by_hasura_primary_lightbg.svg" />
</a>

License

The core GraphQL Engine is available under the Apache License 2.0 (Apache-2.0).

All other contents (except those in server, cli and console directories) are available under the MIT License. This includes everything in the docs and community directories.

Translations

This readme is available in the following translations:

Translations for other files can be found here.