To properly set up IBCJuno to work with PostgreSQL and, at the same time, create a GraphQL endpoint, you need to perform some additional setup.
First of all, install PostgreSQL following the official documentation.
Once you have installed PostgreSQL, you will need to create the IBCJuno database. To do so, follow the below steps.
-
Log into PostgreSQL with root access.
sudo -u postgres psql
-
Configure PostgreSQL to make it accessible to your normal users. Change your_username with your actual user already created on your Ubuntu system.
CREATE ROLE <your_username> WITH SUPERUSER LOGIN ENCRYPTED PASSWORD 'your_password';
-
Exit PostgreSQL
\q
-
Create the IBCJuno database and set your user to be the owner.
createdb ibcjuno -O <your-username>
-
Log in to the IBCJuno database.
psql ibcjuno
-
Create all the required tables.
You can find the SQL schema inside thedb/schema
folder. -
Exit PostgreSQL.
\q
To easily set up the GraphQL APIs, we're going to use Hasura. This project will allow you to run a Docker container that exposes the GraphQL APIs allowing you to perform custom queries without much effort.
To get started with Hasura we need to perform the below steps.
-
Get the Hasura Docker script by executing the following command.
wget https://raw.githubusercontent.com/hasura/graphql-engine/stable/install-manifests/docker-run/docker-run.sh
-
Configure the script by editing its content so that it looks like the following.
Note. Replaceusername
,password
,host
,port
anddbname
with the details to connect to the database you set up during the database creation. -
Make the script executable.
chmod +x ./docker-run.sh
-
Start the script.
./docker-run.sh
If everything works out, you should be able to see the local GraphQL APIs explorer by browsing localhost:8080.
Once Hasura is properly running, you need to perform the last step to make sure it reads the proper data.
To do so, log into Hasura and click on the Data section on the top bar:
Now, from the Untracked tables or views select the tables you want to track:
Once you have selected the views to track you also need to select the foreign keys as well:
Once you have done so, by going inside the GraphiQL section you will be able to compose your query using the left side panel, run it using the Play button, and see the result on the right-side panel: