Example commands below use make(1). Please, have a look at commands in Makefile if your platform doesn't support it. On Windows we recommend to use WSL.
# 1. Install dependencies
npm ci
# 2. Compile typescript files
make build
# 3. Start target Postgres database and detach
make up
# 4. Apply database migrations from db/migrations
make migrate
# 5. Start the processor
make process
# 6. The command above will block the terminal
# being busy with fetching the chain data,
# transforming and storing it in the target database.
#
# To start the graphql server open the separate terminal
# and run
make serve
# 7. Now you can see the resuls by visiting the localhost:4350/graphql
Hydra tools expect a certain directory layout:
src/generated
- model/server definitions created by codegen
. Do not alter the contents of this directory manually.src/server-extension
- module with custom type-graphql
based resolverssrc/types
- data type definitions for chain events and extrinsics created by typegen
.src/mappings
- mapping module.lib
- compiled js files. The structure of this directory must reflect src
..env
- hydra tools are heavily driven by environment variables defined here or supplied by a shell.If you do not plan to extend GraphQl server you can delete server-extension
module and then remove
type-graphql
and class-validator
dependencies.
Start development by defining the schema of the target database via schema.graphql
.
Schema definition consists of regular graphql type declarations annotated with custom directives.
Full description of schema.graphql
dialect is available here.
Mapping developers use TypeORM entities
to interact with the target database during data processing. All necessary entity classes are
generated by the squid framework from schema.graphql
. This is done by running npx squid-typeorm-codegen
command.
All database changes are applied through migration files located at db/migrations
.
squid-typeorm-migration(1)
tool provides several commands to drive the process.
It is all TypeORM under the hood.
# Connect to database, analyze its state and generate migration to match the target schema.
# The target schema is derived from entity classes generated earlier.
# Don't forget to compile your entity classes beforehand!
npx squid-typeorm-migration generate
# Create template file for custom database changes
npx squid-typeorm-migration create
# Apply database migrations from `db/migrations`
npx squid-typeorm-migration apply
# Revert the last performed migration
npx squid-typeorm-migration revert
In case you just want to extend resolvers you don't index the whole project and just import the postgres database (last data 29.03.2023):
docker-compose up db
docker exec -it rubick-db-1 psql -U postgres -d postgres -c "CREATE DATABASE squid;"
docker exec -i rubick-db-1 psql -U postgres -d squid < rubick.sql
⚠️ In case the command does not work, check if the container is called rubick-db-1
.
For more details, please check out https://docs.subsquid.io.