Browse Source

query-node: update package.json

metmirr 4 years ago
parent
commit
734a923333
2 changed files with 94 additions and 63 deletions
  1. 44 19
      query-node/README.md
  2. 50 44
      query-node/package.json

+ 44 - 19
query-node/README.md

@@ -1,36 +1,61 @@
-# query-node
+# Query node
 
-The query-node project contains an input schema (schema.graphql) and mappings for the Joystream `content-directory` runtime module.
+This is a query-node project generated by `hydra-cli`. Experiment by modifying `schema.graphql` and the mappings in the `mappings` folder, defined in `manifest.yml`.
 
-## Code generation
+## 1. Bootstrap
 
-We use Hydra-cli to generate a graphql server and a block indexer for joystream chain:
+Run
 
 ```bash
-$ cd query-node
-$ yarn build
+yarn && yarn bootstrap
 ```
 
-## Starting services
+and generate the model files as defined in `schema.graphql`, create the database and run all the necessary migrations in one shot.
 
-To start services defined in the project docker-compose.yml, you should run docker-compose from the project root folder to use the correct .env file
+NB! Don't use in production, as it will delete all the existing records.
 
-## Run mapping processor
 
-Before running mappings make sure indexer(`yarn indexer:start`) and indexer-api-server (mappings get the chain data from this graphql server) are both running:
+## 2. Generate Types for events and extrinsics
+
+A separate tool Hydra Typegen can be used for generating Typescript classes for the event handlers (the _mappings_).  
+Run
 
 ```bash
-yarn processor:start
+yarn typegen
+```
+to run the [typegen](https://github.com/Joystream/hydra/tree/master/packages/hydra-typegen/README.md) for events and extrinsics defined in `manifest.yml` (it fetches the metadata from an RPC endpoint and blockhash defined there). 
+
+
+## 3. Build Mappings
+
+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
+
+```bash
+yarn mappings:build
 ```
 
-## Query data
+## 4. Run the processor and the GraphQL server
 
-Once processor start to store event data you will be able to query this data from `http://localhost:4002/graphql`.
+Then run the processor:
 
-```graphql
-query {
-  channels {
-    handle
-  }
-}
+```bash
+yarn processor:start
 ```
+
+Afterwards start the GraphQL server in a separate terminal (opens a GraphQL playground at localhost by default):
+
+```bash
+yarn query-node:start:dev
+```
+
+## 5. Locally hosted indexer
+
+The 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](https://github.com/Joystream/hydra/tree/master/packages/hydra-indexer/README.md) service and [indexer-api-gateway](https://github.com/Joystream/hydra/tree/master/packages/hydra-indexer-gateway/README.md).

+ 50 - 44
query-node/package.json

@@ -1,48 +1,54 @@
 {
-	"name": "query-node-root",
-	"version": "1.0.0",
-	"description": "GraphQL server and Substrate indexer. Generated with ♥ by Hydra-CLI",
-	"scripts": {
-		"build": "./build.sh",
-		"test": "echo \"Error: no test specified\" && exit 1",
-		"clean": "rm -rf ./generated",
-		"processor:start": "hydra-processor run -m manifest.yml -e ../.env",
-		"server:start:dev": "(cd ./generated/graphql-server && yarn start:dev)",
-		"server:start:prod": "(cd ./generated/graphql-server && yarn start:prod)",
-		"configure": "(cd ./generated/graphql-server && yarn config:dev)",
-		"db:up": "(cd ../ && docker-compose up -d db)",
-		"db:drop": "(cd ./generated/graphql-server && yarn db:drop)",
-		"db:prepare": "(cd ./generated/graphql-server && yarn db:create && yarn db:sync)",
-		"db:processor:migrate": "hydra-processor migrate --env ../.env",
-		"db:migrate": "./db-migrate.sh",
-		"bootstrap": "hydra-cli codegen --createDb",
-		"codegen:all": "hydra-cli codegen",
-		"db:schema:migrate": "(cd ./generated/graphql-server && yarn db:create && yarn db:sync && yarn db:migrate)",
-		"db:indexer:migrate": "(cd ./generated/indexer && yarn db:migrate)",
-		"codegen:server": "yarn hydra-cli codegen --no-install --no-processor",
-		"integration-tests": "./run-tests.sh",
-		"docker:build": "docker build . -f docker/Dockerfile.hydra -t hydra-kit:latest",
-		"docker:db:up": "docker-compose up -d db",
-		"docker:db:migrate": "docker run --env-file .env --env DB_HOST=db --env TYPEORM_HOST=db --network container:${PWD##*/}_db_1 hydra-kit:latest yarn db:migrate",
-		"docker:up": "docker-compose up -d"
-	},
-	"author": "",
-	"license": "ISC",
-	"devDependencies": {
-		"@dzlzv/hydra-cli": "2.0.0-beta",
-		"@dzlzv/hydra-processor": "0.1.1",
-		"@dzlzv/hydra-typegen": "0.0.3-1"
-	},
-	"dependencies": {
-		"@joystream/types": "^0.14.0",
-		"@types/bn.js": "^4.11.6",
-		"@types/debug": "^4.1.5",
-		"bn.js": "^5.1.2",
-		"debug": "^4.2.0",
-		"dotenvi": "^0.9.1",
-		"tslib": "^2.0.0"
-	},
-	"volta": {
+  "name": "query-node-root",
+  "private": "true",
+  "version": "0.0.0",
+  "description": "GraphQL server and mappings. Generated with \u2665 by Hydra-CLI",
+  "workspaces": [
+    "./generated/*",
+    "./mappings"
+  ],
+  "scripts": {
+    "build": "yarn clean && yarn codegen",
+    "rebuild": "yarn db:drop && yarn clean:query-node && yarn codegen:query-node && yarn db:prepare && yarn db:migrate",
+    "lint": "echo \"Skippinng\"",
+    "clean": "rm -rf ./generated",
+    "clean:query-node": "rm -rf ./generated/graphql-server",
+    "processor:start": "DEBUG=${DEBUG} hydra-processor run -e ../.env",
+    "query-node:start:dev": "yarn workspace query-node start:dev",
+    "query-node:start:prod": "yarn workspace query-node start:prod",
+    "query-node:configure": "yarn workspace query-node config:dev",
+    "db:up": "yarn docker:db:up",
+    "db:create": "yarn workspace query-node db:create",
+    "db:drop": "yarn workspace query-node db:drop",
+    "db:prepare": "yarn workspace query-node db:create && yarn workspace query-node db:sync",
+    "db:schema:migrate": "yarn workspace query-node db:migrate",
+    "db:processor:migrate": "hydra-processor migrate --env ../.env",
+    "db:migrate": "yarn db:schema:migrate && yarn db:processor:migrate",
+    "db:bootstrap": "yarn db:create && yarn db:prepare && yarn db:migrate",
+    "bootstrap": "yarn codegen && yarn db:drop && yarn db:bootstrap",
+    "codegen": "hydra-cli codegen",
+    "codegen:noinstall": "hydra-cli codegen --no-install",
+    "typegen:configure": "NODE_URL=${NODE_URL:-ws://localhost:9000} envsub typegen.template.yml typegen.yml",
+    "typegen": "rm -rf ./mappings/generated && hydra-typegen typegen manifest.yml --debug",
+    "mappings:build": "yarn workspace query-node-mappings build",
+    "docker:build": "docker build . -f docker/Dockerfile.hydra -t hydra-kit:latest",
+    "docker:db:up": "(cd ../ && docker-compose up -d db)",
+    "docker:db:migrate": "docker run --env-file .env --env DB_HOST=db --env TYPEORM_HOST=db --network container:${PWD##*/}_db_1 hydra-kit:latest yarn db:migrate",
+    "docker:up": "docker-compose up -d"
+  },
+  "author": "",
+  "license": "ISC",
+  "dependencies": {
+    "tslib": "^2.0.0",
+    "@types/bn.js": "^4.11.6",
+    "bn.js": "^5.1.2"
+  },
+  "devDependencies": {
+    "@dzlzv/hydra-cli": "2.0.0-beta",
+    "@dzlzv/hydra-processor": "0.1.1",
+    "@dzlzv/hydra-typegen": "0.0.3-1"
+  },
+  "volta": {
 		"extends": "../package.json"
 	}
 }