kodadot / rubick

Implementation SubSquid indexer for Kusama NFTs
https://github.com/kodadot/rubick
9 stars 15 forks source link
graphql hacktoberfest indexing kusama nft polkadot polkadot-js rmrk subsquid

Rubick

Prerequisites

Quickly running the sample

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

Project structure

Hydra tools expect a certain directory layout:

If you do not plan to extend GraphQl server you can delete server-extension module and then remove type-graphql and class-validator dependencies.

Dev flow

1. Define database schema

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.

2. Generate TypeORM classes

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.

3. Generate database migration

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         

Setting up the project for resolvers

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):

  1. Contact @vikiival on Discord
  2. docker-compose up db
  3. docker exec -it rubick-db-1 psql -U postgres -d postgres -c "CREATE DATABASE squid;"
  4. 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.

Misc

For more details, please check out https://docs.subsquid.io.