Update subgraph watcher demo readme (#480)

* Update subgraph watcher demo readme

* Pass extra block data required in subgraph block handler (#486)

* Use codegen config directory name instead of file path

* Get block data from extra event data

* Add extra event data in processBlockAfterEvents

---------

Co-authored-by: neeraj <neeraj.rtly@gmail.com>

* Update example subgraph mapping code for graph-cli upgrade

* Return 0 value for block size in ipld-eth-client

---------

Co-authored-by: neeraj <neeraj.rtly@gmail.com>
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
This commit is contained in:
2023-11-24 11:13:40 +05:30
committed by GitHub
co-authored by neeraj prathamesh
parent 937aed139f
commit 6decf61d4c
8 changed files with 38 additions and 38 deletions
@@ -499,10 +499,10 @@ export class Indexer implements IndexerInterface {
}
{{#if (subgraphPath)}}
async processBlockAfterEvents (blockHash: string, blockNumber: number): Promise<void> {
async processBlockAfterEvents (blockHash: string, blockNumber: number, extraData: ExtraEventData): Promise<void> {
console.time('time:indexer#processBlockAfterEvents-mapping_code');
// Call subgraph handler for block.
await this._graphWatcher.handleBlock(blockHash, blockNumber);
await this._graphWatcher.handleBlock(blockHash, blockNumber, extraData);
console.timeEnd('time:indexer#processBlockAfterEvents-mapping_code');
console.time('time:indexer#processBlockAfterEvents-dump_subgraph_state');
+4 -3
View File
@@ -69,7 +69,8 @@ export async function buildSubgraph (
network?: string
}
): Promise<void> {
const subgraphDirectory = path.resolve(codegenConfigPath, subgraphConfig.directory);
const codegenConfigDirName = path.dirname(codegenConfigPath);
const subgraphDirectory = path.resolve(codegenConfigDirName, subgraphConfig.directory);
const codegenWorkingDir = process.cwd();
// Change directory to subgraph repo
shell.cd(subgraphDirectory);
@@ -102,7 +103,7 @@ export async function buildSubgraph (
const { code: installCode } = shell.exec(`${packageManager} install --force`);
assert(installCode === 0, 'Installing dependencies exited with error');
const subgraphConfigPath = path.resolve(codegenConfigPath, subgraphConfig.configFile);
const subgraphConfigPath = path.resolve(codegenConfigDirName, subgraphConfig.configFile);
// Run graph-cli codegen
const { code: codegenCode } = shell.exec(`${packageManager === 'npm' ? 'npx' : packageManager} graph codegen ${subgraphConfigPath}`);
@@ -112,7 +113,7 @@ export async function buildSubgraph (
let buildCommand = `${packageManager === 'npm' ? 'npx' : packageManager} graph build ${subgraphConfigPath}`;
if (subgraphConfig.networkFilePath) {
const subgraphNetworkFilePath = path.resolve(codegenConfigPath, subgraphConfig.networkFilePath);
const subgraphNetworkFilePath = path.resolve(codegenConfigDirName, subgraphConfig.networkFilePath);
assert(subgraphConfig.network, 'Config subgraph.network should be set if using networkFilePath');
const subgraphNetwork = subgraphConfig.network;
buildCommand = `${buildCommand} --network-file ${subgraphNetworkFilePath} --network ${subgraphNetwork}`;
+12 -22
View File
@@ -16,10 +16,6 @@
* For this demo, an [example subgraph](../graph-node/test/subgraph/example1) will be used
* In [package.json](../graph-node/test/subgraph/example1/package.json), the graph-ts and graph-cli dependencies are replaced by their respective cerc-io forked dependencies
* This needs to be done for running any subgraph project with watcher-ts
* In watcher-ts [packages/graph-node](../graph-node/), deploy an `Example` contract:
```bash
@@ -32,13 +28,7 @@
export EXAMPLE_ADDRESS=<EXAMPLE_ADDRESS>
```
* In [packages/graph-node/test/subgraph/example1/subgraph.yaml](../graph-node/test/subgraph/example1/subgraph.yaml), set the source address for `Example1` datasource to the `EXAMPLE_ADDRESS`. Then in [packages/graph-node](../graph-node/) run:
```bash
yarn build:example
```
* This will run `yarn && yarn codegen && yarn build` script in the example subgraph directory
* In [packages/graph-node/test/subgraph/example1/subgraph.yaml](../graph-node/test/subgraph/example1/subgraph.yaml), set the source address for `Example1` datasource to the `EXAMPLE_ADDRESS`
* In [packages/codegen](./), create a `config.yaml` file:
@@ -63,10 +53,16 @@
# Flatten the input contract file(s) [true | false] (default: true).
flatten: true
# Path to the subgraph build (optional).
# Can set empty contracts array when using subgraphPath.
# Subgraph WASM files should be compiled using @cerc-io/graph-cli
subgraphPath: ../graph-node/test/subgraph/example1/build
# Config for subgraph
subgraph:
# Path to subgraph repo directory containing package.json
directory: ../graph-node/test/subgraph/example1
# Package manager that is used in subgraph repo for dependencies
packageManager: yarn
# Path to subgraph manifest/config file
configFile: ../graph-node/test/subgraph/example1/subgraph.yaml
```
* Run codegen to generate watcher:
@@ -116,13 +112,7 @@
yarn && yarn build
```
* In `packages/test-watcher`, run fill for the subgraph start block:
```bash
yarn fill --start-block 10 --end-block 10
```
* Subgraph start block is the lowest `startBlock` in example [subgraph.yaml](../graph-node/test/subgraph/example1/subgraph.yaml)
* Configure the upstream GQL and RPC endpoints
* Run the job-runner: