Introduction of Hasura GraphQL Enginе

Introduction of Hasura GraphQL Engine

The Hasura GraphQL engine is an open-source tool that provides an instant and real-time GraphQL API on top of your existing PostgreSQL databases. It simplifies the process of building GraphQL APIs by automating much of the work typically involved.

Hasura is particularly useful for building GraphQL applications backed by PostgreSQL and for gradually migrating existing projects to use GraphQL.

In this tutorial, we’ll explore two examples of installing the Hasura GraphQL engine on the AccuWeb.Cloud platform.

Hasura GraphQL Engine

Steps to Install Hasura GraphQL Engine On AccuWeb.Cloud.

Automatic Deployment with Local PostgreSQL Database

This approach involves setting up Hasura with a PostgreSQL database hosted locally within the same environment. It is a streamlined process where both Hasura and the PostgreSQL database are deployed together and simplifying configuration and management.

Manual Deployment with external PostgreSQL Database

This method involves manually setting up Hasura to connect with an externally hosted PostgreSQL database. It provides more flexibility and is useful when you want to integrate Hasura with an existing PostgreSQL database located outside or inside the AccuWeb.Cloud environment.

Method 1. Automatic Deployment with Local PostgreSQL Database on AccuWeb.Cloud

Deploying the Hasura GraphQL engine with a local PostgreSQL database on AccuWeb.Cloud is a straightforward process. Follow these steps to get your environment up and running in no time:

Step 1. First, log in to your AccuWeb.Cloud account. Once logged in and locate the Marketplace option at the top left corner of the dashboard and click on it.

Marketplace

Step 2. In the Marketplace, search for the Docker engine Ce package. Select this package and initiate its installation process.

 Docker engine Ce package

Step 3.To automatically create a Hasura GraphQL engine and PostgreSQL database within the same container, follow these steps:

Once you have configured these fields according to your neds, click Install.

Configure Field

Step 4. After a successful installation, you can access the Hasura console by http://{envDomain}:8080/ console to verify that everything is working correctly. The console provides a user friendly interface for managing your database and API.

Access Hasura Console

You successfully deployed the Hasura GraphQL engine with a local PostgreSQL database on AccuWeb.Cloud.

Now you can start adding data to your database via the Data tab and experimenting with GraphQL queries to se your setup in action.

Method 2. Manual Deployment with external PostgreSQL Database

If you already have a PostgreSQL database, you can connect it to the Hasura GraphQL engine with a few manual steps. Here’s how to do it:

Step 1. First, create a clean standalone Docker engine Ce via the AccuWeb.Cloud platform Marketplace.

Log in to your AccuWeb.Cloud dashboard and click on the Marketplace option at the top left corner. Find the Docker engine Ce package and initiate its installation.

Docker Engine CE

Now, Select “Create a clean standalone Docker engine CE”, enter the environment name, Display Name, and select Region. Once done, click on Install.

Create Standalone Docker Engine CE

Step 2. After the Docker engine is set up and connect to the container via Web SSH.

Web SSH

Create a shell script file (e.g. and docker run.sh) with the following content:

docker run -d –restart=always -p 80:8080 \
-e HASURA_GRAPHQL_DATABASe_URL=postgres://{username}:{password}@{host}/{dbname} \
-e HASURA_GRAPHQL_eNABLe_CONSOLe=true \
-e HASURA_GRAPHQL_ADMIN_SeCReT=myadminsecretkey \
hasura/graphql-engine:v1.0.0

Create Docker run File

Detailed Command Explanation

  • d: Runs services in the background.
  • restart=always: ensures the daemon restarts automatically after container restarts.
  • p 80:8080: Redirects port 80 on the Docker engine container to port 8080 on the Hasura image
  • e: Sets environment variables. ( Read this for more details)

HASURA_GRAPHQL_DATABASe_URL: Connection string to your PostgreSQL database.

HASURA_GRAPHQL_eNABLe_CONSOLe: enables the Hasura console.

HASURA_GRAPHQL_ADMIN_SeCReT: Sets the admin secret key for console access (myadminsecretkey in this example).

hasura/graphql engine:v1.0.0: Specifies the Docker image for Hasura.

Step 3. execute the Script to Create Hasura Docker Container

Make the script executable and run it to create the Hasura Docker container:


chmod +x docker-run.sh
./docker-run.sh

Verify the Installation: Run docker ps to ensure the Hasura service is up and running.

Run file to Hasura Docker

Step 4. In the AccuWeb.Cloud dashboard, click Open in Browser next to your environment for an automatic redirect.

Open in Browser

Provide the admin secret key (myadminsecretkey) to access the console.

Access Console

Step 5. You can now start working with your database using the GraphQL API. Use the GraphiQL tab in the Hasura console for testing queries.

If there are existing tables you ned to manage with Hasura, go to the Data tab and enable tracking for the required tables.

Enable Tracking to Require Node

Alternatively, use the GraphQL endpoint specified at the top of the page to create POST requests to the database using your preferred tools or scripts.

GraphQL

By following these steps, you can manually deploy the Hasura GraphQL engine to connect with an external PostgreSQL database, allowing you to leverage the powerful features of Hasura for your GraphQL applications.

Conclusion

Whether you choose automatic deployment with a local PostgreSQL database or manual deployment with an external PostgreSQL database, Hasura on AccuWeb.Cloud offers a flexible and efficient way to set up a GraphQL API.

The automatic deployment method is quick and easy, suitable for new projects or when you ned a fast setup. The manual deployment method provides greater control and is ideal for integrating with existing databases.

Both methods ensure you can leverage Hasura’s powerful features for managing and querying your data.