Experiment by modifying schema.graphql and the mappings in the mappings folder, defined in manifest.yml.
Run
yarn && yarn bootstrapand generate the model files as defined in schema.graphql, create the database and run all the necessary migrations in one shot.
NB! Don't use in production, as it will delete all the existing records.
A separate tool Hydra Typegen can be used for generating Typescript classes for the event handlers (the mappings).
Run
yarn typegento run the typegen for events and extrinsics defined in manifest.yml (it fetches the metadata from an RPC endpoint and blockhash defined there).
Mappings is a separated TypeScript module created in the mappings folder. The handlers exported by the module should match the ones defined in manifest.yml in the mappings section. Once the necessary files are generated, build it with
yarn workspace sample-mappings install
yarn mappings:buildThen run the processor:
yarn processor:startAfterwards start the GraphQL server in a separate terminal (opens a GraphQL playground at localhost by default):
yarn query-node:start:devThe Hydra Indexer endpoint used by Hydra processor is defined as environment variable INDEXER_ENDPOINT_URL sourced from .env. There are publicly available Hydra indexers for Polkadot and Subsocial. For other chains, a self-hosted indexer should be used.
The simplest way to run an indexer locally is to run docker-compose-indexer.yml with docker-compose. The following environment variables must be provided:
- Database connection settings: DB_NAME, DB_HOST, DB_PORT, DB_USER, DB_PASS
- Chain RPC endpoint: WS_PROVIDER_ENDPOINT_URI
- If non-standard types are being used by the Substrate runtime, map type definitions in the json format as an external volume
Follow the links for more information about the indexer service and indexer-api-gateway.
Docker files are located in ./docker. First, build the builder image:
$ docker build . -f docker/Dockerfile.builder -t builderImages for the GraphQL query node and the processor depend on the builder image which is now available.
Build with
$ docker build . -f docker/Dockerfile.query-node -t query-node:latest
$ docker build . -f docker/Dockerfile.processor -t processor:latestIn order to run the docker-compose stack, we need to create the schema and run the database migrations.
$ docker-compose up -d db
$ yarn docker:db:migrateThe last command runs yarn db:bootstrap in the builder image. A similar setup strategy may be used for Kubernetes (with builder as a starter container).
Now everything is ready:
$ docker-compose up