This is a short course that outlines how to install Hasura GraphQL Engine in your local environment using Docker Compose. Mostly this is following the official Hasura Quickstart with Docker instructions.
docker-compose up
You should see a lot of log output. The containers should now be running.
Head to Hasura Console to open the Hasura console.
Click the 'Data' tab at the top and press 'Add Table' button. Create the table with the following structure:
profile (
id INT PRIMARY KEY,
name TEXT
)
Make sure to set id
column as the Primary Key and click save button.
When workig with databases such as Postgres, I like to check the source by connecting directly to the database and having a dig around there. So to do this we can head over to pgAdmin Console.
Connect to the database. The details are in the docker-compose file. Assuming this file has not changed the required connection details are:
- Server: postgres
- Port: 5432
- Database: postgres
- Password: @postgres
Navigate to the table that we have just created by expanding the left navigation tree as follows: servers -> postgres-hasura -> databases -> postgres -> schemas -> public -> Tables -> profile -> columns. You should see the colums id and name.
Now right click on the table name and select from the context menu 'View/Edit Data -> All Rows'. The results should show an empty table. Now add two rows to that table and save the data.
Note it is also possible to insert data via the Hasura Dashboard.
Flip back to the Hasura Console and click on GraphQL tab. Now run the following query:
query {
profile {
id
name
}
}
You will see the results from the database displayed!
With this tutorial you have installed Postgres, Hasura and pgAdmin. You have created a single table with two columns. You have inserted data into this table using pgAdmin and you have queried the database table via Hasura Graph QL engine.