Skip to content

Commit 9e18be6

Browse files
Add subgraph GitHub workflow and update the Readme (#780)
* First try Signed-off-by: Maksim Dimitrov <[email protected]> * Generate package-lock.json. Update workflow Signed-off-by: Maksim Dimitrov <[email protected]> * Try to set default working dir Signed-off-by: Maksim Dimitrov <[email protected]> * Add create .env file step Signed-off-by: Maksim Dimitrov <[email protected]> * Run hedera-local in detached Signed-off-by: Maksim Dimitrov <[email protected]> * Update packages and workflow Signed-off-by: Maksim Dimitrov <[email protected]> * Add sleep step Signed-off-by: Maksim Dimitrov <[email protected]> * Change npx to npm Signed-off-by: Maksim Dimitrov <[email protected]> * Remove step Signed-off-by: Maksim Dimitrov <[email protected]> * Try without retry Signed-off-by: Maksim Dimitrov <[email protected]> * Try without retry v2 Signed-off-by: Maksim Dimitrov <[email protected]> * Try without retry v3 Signed-off-by: Maksim Dimitrov <[email protected]> * Add loadash.isequal Signed-off-by: Maksim Dimitrov <[email protected]> * Use lodash Signed-off-by: Maksim Dimitrov <[email protected]> * Load isEqual from lodash Signed-off-by: Maksim Dimitrov <[email protected]> * Use npm ci Signed-off-by: Maksim Dimitrov <[email protected]> * Fix typo Signed-off-by: Maksim Dimitrov <[email protected]> * Reduce the wait time, update the readme Signed-off-by: Maksim Dimitrov <[email protected]> * Update Readme Signed-off-by: Maksim Dimitrov <[email protected]> * More Readme updates Signed-off-by: Maksim Dimitrov <[email protected]> * Update Readme again Signed-off-by: Maksim Dimitrov <[email protected]> * Update relay and mirror-node version in readme Signed-off-by: Maksim Dimitrov <[email protected]> Signed-off-by: Maksim Dimitrov <[email protected]>
1 parent 0aa3c5a commit 9e18be6

File tree

7 files changed

+55872
-61
lines changed

7 files changed

+55872
-61
lines changed

.github/workflows/subgraph.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Subgraph Tests
2+
3+
on:
4+
pull_request:
5+
branches: [main, release/**]
6+
push:
7+
branches: [main, release/**]
8+
tags: [v*]
9+
10+
jobs:
11+
subgraph-workflow:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
defaults:
16+
run:
17+
working-directory: ./tools/subgraph-example/
18+
steps:
19+
- name: Setup node
20+
uses: actions/setup-node@v2
21+
with:
22+
node-version: 16
23+
24+
- name: Checkout repo
25+
uses: actions/checkout@v2
26+
27+
- name: Install dependencies
28+
run: npm ci
29+
30+
- name: Create .env file
31+
run: cp .env.example .env
32+
33+
- name: Run local node
34+
run: npx hedera start --network local-test --detached
35+
36+
- name: Deploy and interact with contracts
37+
run: npx hardhat prepare
38+
39+
- name: Start local graph-node
40+
run: npm run graph-local -- --detach
41+
42+
- name: Sleep for 10 seconds
43+
run: sleep 10s
44+
shell: bash
45+
46+
- name: Create subgraph
47+
run: npm run create-local
48+
49+
- name: Deploy subgraph
50+
run: npm run deploy-local -- --network local --version-label 0.0.1
51+
52+
- name: Run the tests
53+
run: npx hardhat test

tools/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
| Support for multiple dataSources ||
1313
| Support for dynamic dataSource templates ||
1414
| Block Handlers WITHOUT filters ||
15+
| Can index anonymous events ||
1516
| Block Handlers WITH filters | ❌ | Requires Parity's [trace_filter](https://openethereum.github.io/JSONRPC-trace-module#trace_filter)
1617
| Call Handlers | ❌ | Requires Parity's [trace_filter](https://openethereum.github.io/JSONRPC-trace-module#trace_filter)
1718
| Capture HTS transfers through HTS precompile | ❌ | Depends on [4127](https://github.com/hashgraph/hedera-services/issues/4127)
1819
| Capture HTS token transfers through HAPI | ❌ | Depends on [4337](https://github.com/hashgraph/hedera-mirror-node/issues/4337), [4738](https://github.com/hashgraph/hedera-mirror-node/issues/4738)
19-
| Can index anonymous events | ❔ | Depends on [667](https://github.com/hashgraph/hedera-json-rpc-relay/issues/667)
2020

2121
### Supported tools
2222
| | web3js | Truffle | ethers | Hardhat |

tools/subgraph-example/README.md

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Subgraph example
22

3+
## Description:
4+
35
Hardhat based project containing example subgraph indexing the following contracts and events:
46

57
ExampleERC721 -> Transfer
@@ -10,29 +12,37 @@ GravatarRegistry -> GravatarCreated and GravatarUpdated
1012

1113
For more information on subgraphs, check the official TheGraph documentation https://thegraph.com/docs/en/
1214

13-
## Prerequisites:
15+
## Introduction:
16+
17+
1. [What is TheGraph](https://thegraph.com/docs/en/about)
18+
2. [How to create a subgraph](https://thegraph.com/docs/en/developing/creating-a-subgraph/)
19+
3. [The AssemblyScript API](https://thegraph.com/docs/en/developing/assemblyscript-api/)
20+
21+
## Try it out:
22+
23+
### Prerequisites:
1424

15-
Note: Currently this example needs to be executed against older relay and mirror-node versions, until all fixes have been released.
25+
Note: Currently this example needs to be executed against older relay (v0.10.0) and mirror-node (v0.67.0-rc1) versions, until all fixes have been released.
1626

17-
### Install the dependencies:
27+
The full hedera local-node config can be found [here](./configs/local-test.json)
28+
29+
#### Install the dependencies:
1830

1931
Run `npm install` or `yarn [install]`
2032

21-
### Run Hedera local node:
33+
#### Run Hedera local node:
2234

2335
To start a Hedera local node by running `npx hedera start --network local-test`. Note that when the containers are up, you'll need to stop the `json-rpc-relay` container and start a local relay server.
2436

25-
### JSON-RPC Relay configurations:
26-
27-
Note: Currently you'll have to start the relay from the main branch in this repo, because it contains important bugfixes. This doc will be updated when a new version containing all the fixes is released.
37+
#### JSON-RPC Relay configurations:
2838

29-
The graph node is configured to run against a local instance of the json-rpc-relay. Be sure to set the following options in your json-rpc .env file:
39+
If the graph node is configured to run against a local instance of the json-rpc-relay. Be sure to set the following env variables in your json-rpc-relay .env file:
3040
```
3141
ETH_GET_LOGS_BLOCK_RANGE_LIMIT=2000
3242
RATE_LIMIT_DISABLED = true
3343
```
3444

35-
### Set .env vars
45+
#### Set .env vars
3646

3747
Rename `.env.example` to `.env`
3848

@@ -53,7 +63,7 @@ Rename `.env.example` to `.env`
5363

5464
`npx hardhat createGravatar`
5565

56-
NOTE: This example uses the [hardhat-graph](https://github.com/graphprotocol/hardhat-graph) hardhat plugin. After every contract deploy, the plugin will update the networks.json file with the contract address (and the startBlock), so you don't have to manually update it in the `subgraph.yaml` file.
66+
_NOTE: This example uses the [hardhat-graph](https://github.com/graphprotocol/hardhat-graph) plugin. After every contract deploy, the plugin will update the networks.json file with the contract address (and the startBlock), this way you can use the `--network <network_name>` option of the `deploy` command, which will automatically update the address (and startBlock) in the `subgraph.yaml` file to the last contract deployment._
5767

5868
### Generate the types:
5969

@@ -63,34 +73,49 @@ Run `npm run graph-codegen` or `yarn graph-codegen`
6373

6474
Run `npm run graph-local` or `yarn graph-local`
6575

66-
Note: If you run the graph-node against a local Hedera node and see this error in the graph-node console:
76+
_NOTE: If you run the graph-node against a local Hedera node and see this error in the graph-node console:_
77+
6778
```
6879
Trying again after eth_getBlockByNumber(0, false) RPC call failed (attempt #10) with result Err(Ethereum node could not find genesis block), provider: local-rpc-0
6980
```
7081

71-
Uncomment [this](./docker-compose.yml#L24) line and restart the node.
82+
_Add [this](./docker-compose.yml#L24) line to your `docker-compose.yml` and restart the node._
7283

73-
Every time you restart the hedera-node it is recommended to do a clean-up of the graph-node. To do this run `npm run graph-local-clean` or `yarn graph-local-clean`
84+
_NOTE: Every time you restart the hedera-node it is recommended to do a clean-up of the graph-node. To do this run `npm run graph-local-clean` or `yarn graph-local-clean`_
7485

7586
### Deploy the subgraph to the local graph-node:
7687

77-
Before deploying the subgraph, be sure to update the address (and startBlock) in `subgraph.yaml` to the address of the deployed Greeter contract.
78-
7988
To deploy the subgraph:
8089

8190
1. Run `npm run create-local` or `yarn create-local`
8291
2. Run `npm run deploy-local -- --network local` or `yarn deploy-local --network local`
8392
3. Follow the instructions
8493
4. After the subgraph is successfully deployed open the [GraphQL playground](http://127.0.0.1:8000/subgraphs/name/subgraph-example/graphql?query=%7B+%0A++gravatars+%7B%0A++++id%0A++++owner%0A++++displayName%0A++++imageUrl%0A++%7D%0A++erc20S+%7B%0A++++id%0A++++supply%0A++++type%0A++++transfers+%7B%0A++++++from%0A++++++to%0A++++++amount%0A++++%7D%0A++%7D%0A++erc721S+%7B%0A++++id%0A++++owner%0A++++type%0A++++tokenId%0A++++transfers+%7B%0A++++++from%0A++++++to%0A++++%7D%0A++%7D%0A%7D%0A) where you can execute queries and fetch indexed data.
8594

86-
### Running the tests:
95+
## Running the tests:
8796

88-
Note: At this time the whole test workflow can't be proficiently automated, so you'll need to perform some manual steps:
97+
_NOTE: At this time the whole test workflow can't be proficiently automated, so you'll need to perform some manual steps:_
8998

9099
1. Be sure to start a clean local hedera node. If the node is currently running stop it.
91-
- Run `npx hedera stop` to be sure that all containers are stopped and the temp files and volumes have been removed.
92-
- Run `npx hedera start --network local-test` to start a new clean node.
100+
1. Run `npx hedera stop` to be sure that all containers are stopped and the temp files and volumes have been removed.
101+
2. Run `npx hedera start --network local-test` to start a new clean node.
93102
2. After the node has started, execute `npx hardhat prepare` task, which will deploy and interact with the contracts.
94103
3. Be sure to start a clean graph-node by executing `yarn/npm run graph-local-clean` and then `yarn/npm run graph-local`
95104
4. Create and deploy the subgraph by executing `yarn/npm run create-local` and `yarn deploy-local --network local` or `npx run deploy-local -- --network local` and follow the instructions
96105
5. Execute `npx hardhat test`
106+
107+
108+
## HOW TOs:
109+
110+
### Run a private graph-node against testnet, previewnet and mainnet:
111+
112+
The easiest way to run a local `graph-node` against `testnet`, `previewnet` or `mainnet` is using the [docker-compose](https://github.com/graphprotocol/graph-node/tree/master/docker#docker-compose) setup.
113+
114+
1. Copy the content of the provided [docker-compose.yml](https://github.com/graphprotocol/graph-node/blob/master/docker/docker-compose.yml) file, or use the one from the [subgraph-example](./docker-compose.yml)
115+
2. Replace `'mainnet:http://host.docker.internal:8545'` on [this](https://github.com/graphprotocol/graph-node/blob/master/docker/docker-compose.yml#L22) line with:
116+
1. `'mainnet:https://mainnet.hashio.io/api'` for `mainnet`
117+
2. `'testnet:https://testnet.hashio.io/api'` for `testnet`
118+
3. `'previewnet:https://previewnet.hashio.io/api'` for `testnet`
119+
3. In the `subgraph.yaml` file change the dataSources network with to the network you want to index. Also don't forget to update the address (and the startBlock).
120+
121+
Advanced info on how to set up an indexer could be found in [The Graph Docs](https://thegraph.com/docs/en/indexing/operating-graph-node/) and the [official graph-node GitHub repository](https://github.com/graphprotocol/graph-node)

tools/subgraph-example/configs/latest.json

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)