Skip to content
/ stick Public
forked from kodadot/stick

GraphQL service for Uniques and Assets on Statemine

License

Notifications You must be signed in to change notification settings

roiLeo/stick

 
 

Repository files navigation

stick

KodaDot's Squid based data processor for KodaDot NFT Marketplace.

Prerequisites

  • node 16.x
  • docker
  • npm -- note that yarn package manager is not supported

Quickly running the sample

Example commands below use sqd. Please install it before proceeding.

# 1. Update Squid SDK and install dependencies
npm run update
npm ci

# 2. Start target Postgres database and detach
sqd up

# 3. Build the project and start the processor
sqd process

# 4. 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 a separate terminal
#    and run
sqd serve

Project structure

  • 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 resolvers
  • src/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.

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 or (equivalently) sqd 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         

Available sqd shortcuts:

# Build the project, remove any old migrations, then run `npx squid-typeorm-migration generate`
sqd migration:generate

# Run npx squid-typeorm-migration apply
sqd migration:apply

Dev hacks

  1. fast generate event handlers
pbpaste | cut -d '=' -f 1 | tr -d ' '  | xargs -I_ echo "processor.addEventHandler(Event._, dummy);"
  1. enable debug logs (in .env)
SQD_DEBUG=squid:log
  1. generate metagetters from getters
pbpaste | grep 'export'  | xargs -I_ echo "_  return proc.  }"

About

GraphQL service for Uniques and Assets on Statemine

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 98.4%
  • JavaScript 1.1%
  • Other 0.5%