Giter Site home page Giter Site logo

omidasadpour / subsocial-graphql Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dappforce/subsocial-graphql

0.0 0.0 0.0 1.31 MB

Sample project showcasing Hydra for Subsocial substrate chain

Shell 3.01% TypeScript 90.04% Dockerfile 1.60% JavaScript 5.35%

subsocial-graphql's Introduction

Sample Hydra Project

This is a sample project generated by hydra-cli scaffold. Experiment by modifying schema.graphql and the mappings in the mappings folder.

Prerequisites

  • Node v14x
  • Docker

Bootstrap

# The dependencies setup relies on de-duplication, use `ci` to get everything right
npm ci

# Start a postgres instance
docker-compose up db # add optional -d flag to detach from terminal

# Apply migrations related to the processor's state keeping tables
npm run processor:migrate

# Apply the project's migrations
npm run db:migrate

# Now you can start processing chain data
npm run processor:start

# The above command will block
# Open a separate terminal and launch the graphql server to query the processed data
npm run query-node:start

Project structure

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 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.

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

Development flow

If you modified schema.graphql:

# Run codegen to re-generate model/server files
npm run codegen

# Analyze database state and create a new migration to match generated models
npm run db:create-migration # add -n "myName" to skip the migration name prompt

# Apply the migrations
npm run db:migrate

You might want update the Initial migration instead of creating a new one (e.g. during the development phase when the production database is not yet set up). In that case it convenient to reset the database schema and start afresh:

rm db/migrations/LastUnappliedMigration.ts
npm run db:reset
npm run db:create-migration
npm run db:migrate

To generate new type definitions for chain events and extrinsics:

# Review typegen section of manifest.yml (https://docs.subsquid.io/hydra-typegen)

# Delete old definitions
rm -rf src/types

# Run typegen tool
npm run typegen

Self-hosted indexer

It is recommended to use a readily set up indexer if available. It takes some time for a freshly started indexer to get in sync with chain and catch the events.

Have a look at ./indexer/docker-compose.yml for an example of how you can set up a self-hosted version.

Misc

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

subsocial-graphql's People

Contributors

samchuk-vlad avatar f3joule avatar dzhelezov avatar siman avatar olehmell avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.