{% hint style="info" %}
Before starting, make surehydra-cli
is installed on your machine together with all the prerequisites.
{% endhint %}
Start off by setting up a project folder
mkdir hello-hydra && cd hello-hydra
Next, run the scaffold command, which generates all the required files:
hydra-cli scaffold
Answer the prompts and the scaffolder will generate a sample backbone for our Hydra project. This includes:
schema.graphql
describing proposals in the Kusama networkmapping
folder translating substrate events into the Proposal
entity CRUD operationsdocker-compose.yml
for running a Postgres instance locally as a Docker service..env
with all the necessary environment variablesNow all is set for generating the Graphql server and the indexer for Kusama proposals:
hydra-cli codegen:all
The codegen command creates two separate projects:
./generated/graphql-server
: this is a GraphQL for querying the proposals./generated/indexer
: this is a background indexer tool that fetches the blocks from the Substrate chain (in this case the public Kusama network) and updates the database calling the mapping scripts.Now it's time to set up the database:
hydra-cli db:start
This command simply spins up a Postgres Docker image.
hydra-cli db:bootstrap
This creates a DB schema for our data model described in schema.graphql
.
Finally, we're ready to run the indexer and the GraphQL server:
hydra-cli indexer:start
Keep an eye on the output to keep track of the indexer's progress.
In a separate terminal window:
hydra-cli server:start:dev
The last command starts the server in the dev mode and you will see a GraphQL playground opening in your browser (if not, navigate manually to localhost:4000/graphql
). It's time to explore all the GraphQL queries supported out-of-the-box! Note, that depending on the starting block it may take a considerable time for the indexer to catch up with the Kusama network, and until then queries may return empty results.
Among other things, the scaffolder generates a top-level package.json
with a bunch of convenient yarn
targets. For example, putting your Hydra Indexer and GraphQL server is easy as running the following targets:
yarn docker:indexer:build
yarn docker:server:build
This will create Docker images named hydra-indexer
and hydra-graphql-server
schema.graphql