File tree Expand file tree Collapse file tree 19 files changed +1691
-62
lines changed
multiple-subgraph-datasources Expand file tree Collapse file tree 19 files changed +1691
-62
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "name" : " multiple-subgraph-datasources" ,
3+ "version" : " 0.1.0" ,
4+ "scripts" : {
5+ "build-contracts" : " ../../common/build-contracts.sh" ,
6+ "codegen" : " graph codegen subgraph.yaml --skip-migrations" ,
7+ "test" : " yarn build-contracts && truffle test --compile-none --network test" ,
8+ "create:test" : " graph create test/multiple-subgraph-datasources --node $GRAPH_NODE_ADMIN_URI" ,
9+ "deploy:test" : " graph deploy test/multiple-subgraph-datasources --version-label v0.0.1 --ipfs $IPFS_URI --node $GRAPH_NODE_ADMIN_URI"
10+ },
11+ "devDependencies" : {
12+ "@graphprotocol/graph-cli" : " 0.93.4-alpha-20250105163501-f401d0c57c4ba1f1af95a928d447efd63a56ecdc" ,
13+ "@graphprotocol/graph-ts" : " 0.36.0-alpha-20241129215038-b75cda9" ,
14+ "solc" : " ^0.8.2"
15+ },
16+ "dependencies" : {
17+ "@truffle/contract" : " ^4.3" ,
18+ "@truffle/hdwallet-provider" : " ^1.2" ,
19+ "apollo-fetch" : " ^0.7.0" ,
20+ "babel-polyfill" : " ^6.26.0" ,
21+ "babel-register" : " ^6.26.0" ,
22+ "gluegun" : " ^4.6.1" ,
23+ "truffle" : " ^5.2"
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ type AggregatedData @entity {
2+ id : ID !
3+ sourceA : String
4+ sourceB : String
5+ }
Original file line number Diff line number Diff line change 1+ import { dataSource , EntityTrigger } from '@graphprotocol/graph-ts'
2+ import { AggregatedData } from '../generated/schema'
3+ import { SourceAData } from '../generated/subgraph-QmU35YwAsv59gJxhejp3qqUrSFMaoBXuskNLX7wJHNUzyA'
4+ import { SourceBData } from '../generated/subgraph-QmXjHeC7j5iWF49oEngV3tqFrHvb4NhkFpAdJYVJ1SFPNk'
5+
6+ export function handleSourceAData ( data : EntityTrigger < SourceAData > ) : void {
7+ let aggregated = AggregatedData . load ( '1' )
8+ if ( ! aggregated ) {
9+ aggregated = new AggregatedData ( '1' )
10+ aggregated . sourceA = data . data . data
11+ } else {
12+ aggregated . sourceA = data . data . data
13+ }
14+ aggregated . save ( )
15+ }
16+
17+ export function handleSourceBData ( data : EntityTrigger < SourceBData > ) : void {
18+ let aggregated = AggregatedData . load ( '1' )
19+ if ( ! aggregated ) {
20+ aggregated = new AggregatedData ( '1' )
21+ aggregated . sourceB = data . data . data
22+ } else {
23+ aggregated . sourceB = data . data . data
24+ }
25+ aggregated . save ( )
26+ }
Original file line number Diff line number Diff line change 1+ specVersion : 1.3.0
2+ schema :
3+ file : ./schema.graphql
4+ dataSources :
5+ - kind : subgraph
6+ name : SourceA
7+ network : test
8+ source :
9+ address : ' QmU35YwAsv59gJxhejp3qqUrSFMaoBXuskNLX7wJHNUzyA'
10+ startBlock : 0
11+ mapping :
12+ apiVersion : 0.0.7
13+ language : wasm/assemblyscript
14+ entities :
15+ - AggregatedData
16+ handlers :
17+ - handler : handleSourceAData
18+ entity : SourceAData
19+ file : ./src/mapping.ts
20+
21+ - kind : subgraph
22+ name : SourceB
23+ network : test
24+ source :
25+ address : ' QmXjHeC7j5iWF49oEngV3tqFrHvb4NhkFpAdJYVJ1SFPNk'
26+ startBlock : 0
27+ mapping :
28+ apiVersion : 0.0.7
29+ language : wasm/assemblyscript
30+ entities :
31+ - AggregatedData
32+ handlers :
33+ - handler : handleSourceBData
34+ entity : SourceBData
35+ file : ./src/mapping.ts
Original file line number Diff line number Diff line change 1+ [
2+ {
3+ "inputs": [],
4+ "stateMutability": "nonpayable",
5+ "type": "constructor"
6+ },
7+ {
8+ "anonymous": false,
9+ "inputs": [
10+ {
11+ "indexed": false,
12+ "internalType": "uint16",
13+ "name": "x",
14+ "type": "uint16"
15+ }
16+ ],
17+ "name": "Trigger",
18+ "type": "event"
19+ },
20+ {
21+ "inputs": [
22+ {
23+ "internalType": "uint16",
24+ "name": "x",
25+ "type": "uint16"
26+ }
27+ ],
28+ "name": "emitTrigger",
29+ "outputs": [],
30+ "stateMutability": "nonpayable",
31+ "type": "function"
32+ }
33+ ]
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " source-subgraph-a" ,
3+ "version" : " 0.1.0" ,
4+ "scripts" : {
5+ "build-contracts" : " ../../common/build-contracts.sh" ,
6+ "codegen" : " graph codegen --skip-migrations" ,
7+ "test" : " yarn build-contracts && truffle test --compile-none --network test" ,
8+ "create:test" : " graph create test/source-subgraph-a --node $GRAPH_NODE_ADMIN_URI" ,
9+ "deploy:test" : " graph deploy test/source-subgraph-a --version-label v0.0.1 --ipfs $IPFS_URI --node $GRAPH_NODE_ADMIN_URI"
10+ },
11+ "devDependencies" : {
12+ "@graphprotocol/graph-cli" : " 0.69.0" ,
13+ "@graphprotocol/graph-ts" : " 0.34.0" ,
14+ "solc" : " ^0.8.2"
15+ },
16+ "dependencies" : {
17+ "@truffle/contract" : " ^4.3" ,
18+ "@truffle/hdwallet-provider" : " ^1.2" ,
19+ "apollo-fetch" : " ^0.7.0" ,
20+ "babel-polyfill" : " ^6.26.0" ,
21+ "babel-register" : " ^6.26.0" ,
22+ "gluegun" : " ^4.6.1" ,
23+ "truffle" : " ^5.2"
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ type SourceAData @entity {
2+ id : ID !
3+ data : String !
4+ timestamp : BigInt !
5+ }
Original file line number Diff line number Diff line change 1+ import { ethereum } from '@graphprotocol/graph-ts'
2+ import { SourceAData } from '../generated/schema'
3+
4+ export function handleBlock ( block : ethereum . Block ) : void {
5+ let entity = new SourceAData ( '1' )
6+ entity . data = 'from source A'
7+ entity . timestamp = block . timestamp
8+ entity . save ( )
9+ }
Original file line number Diff line number Diff line change 1+ specVersion : 0.0.4
2+ description : Source Subgraph A
3+ repository : https://github.com/graphprotocol/graph-node
4+ schema :
5+ file : ./schema.graphql
6+ dataSources :
7+ - kind : ethereum/contract
8+ name : SimpleContract
9+ network : test
10+ source :
11+ address : " 0x5FbDB2315678afecb367f032d93F642f64180aa3"
12+ abi : SimpleContract
13+ startBlock : 0
14+ mapping :
15+ kind : ethereum/events
16+ apiVersion : 0.0.6
17+ language : wasm/assemblyscript
18+ entities :
19+ - SourceAData
20+ abis :
21+ - name : SimpleContract
22+ file : ./abis/Contract.abi
23+ blockHandlers :
24+ - handler : handleBlock
25+ file : ./src/mapping.ts
Original file line number Diff line number Diff line change 1+ [
2+ {
3+ "inputs": [],
4+ "stateMutability": "nonpayable",
5+ "type": "constructor"
6+ },
7+ {
8+ "anonymous": false,
9+ "inputs": [
10+ {
11+ "indexed": false,
12+ "internalType": "uint16",
13+ "name": "x",
14+ "type": "uint16"
15+ }
16+ ],
17+ "name": "Trigger",
18+ "type": "event"
19+ },
20+ {
21+ "inputs": [
22+ {
23+ "internalType": "uint16",
24+ "name": "x",
25+ "type": "uint16"
26+ }
27+ ],
28+ "name": "emitTrigger",
29+ "outputs": [],
30+ "stateMutability": "nonpayable",
31+ "type": "function"
32+ }
33+ ]
You can’t perform that action at this time.
0 commit comments