-
Notifications
You must be signed in to change notification settings - Fork 155
Three Source Example #889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Three Source Example #889
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bb8a5ac
Three Source Example
idalithb c63874b
Updating Copy
idalithb 9da75df
Delete outdated duplicates
benface 04ccf09
Update website/src/pages/en/subgraphs/cookbook/subgraph-composition-t…
MichaelMacaulay 6a4a940
Update website/src/pages/en/subgraphs/cookbook/subgraph-composition-t…
MichaelMacaulay 332e1f1
Update website/src/pages/en/subgraphs/cookbook/subgraph-composition-t…
MichaelMacaulay 886474c
Update website/src/pages/en/subgraphs/cookbook/subgraph-composition-t…
MichaelMacaulay 1b83f28
Update website/src/pages/en/subgraphs/cookbook/subgraph-composition-t…
MichaelMacaulay 87c9d08
Update website/src/pages/en/subgraphs/cookbook/subgraph-composition-t…
MichaelMacaulay 0d03bd4
Update website/src/pages/en/subgraphs/cookbook/subgraph-composition-t…
MichaelMacaulay 28979b1
Update website/src/pages/en/subgraphs/cookbook/subgraph-composition-t…
MichaelMacaulay d5cd007
Final feedback
MichaelMacaulay c8b974a
Final feedback
MichaelMacaulay 45ee1c5
Update website/src/pages/en/subgraphs/cookbook/subgraph-composition-t…
MichaelMacaulay 2686fc7
Merge branch 'main' into source-example
MichaelMacaulay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'subgraph-composition-three-sources': '', | ||
'subgraph-debug-forking': '', | ||
near: '', | ||
arweave: '', | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'subgraph-composition-three-sources': '', | ||
'subgraph-debug-forking': '', | ||
near: '', | ||
arweave: '', | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'subgraph-composition-three-sources': '', | ||
'subgraph-debug-forking': '', | ||
near: '', | ||
arweave: '', | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'subgraph-composition-three-sources': '', | ||
'subgraph-debug-forking': '', | ||
near: '', | ||
arweave: '', | ||
|
98 changes: 98 additions & 0 deletions
98
website/src/pages/en/subgraphs/cookbook/subgraph-composition-three-sources.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
--- | ||
title: Aggregate Data Using Subgraph Composition | ||
sidebarTitle: 'Build a Composable Subgraph with Multiple Subgraphs' | ||
--- | ||
|
||
Optimize your Subgraph by merging data from three independent, source Subgraphs into a single composable Subgraph to enhance data aggregation. | ||
|
||
> Important Reminders: | ||
> | ||
> - Subgraph composition is built into the CLI, and you can deploy with [Subgraph Studio](https://thegraph.com/studio/). | ||
> - This feature requires `specVersion` 1.3.0. | ||
|
||
## Overview | ||
|
||
Subgraph composition empowers you use one Subgraph as a data source for another, allowing it to consume and respond to entity changes. Instead of fetching on-chain data directly, a Subgraph can listen for updates from another Subgraph and react to changes. This is useful for aggregating data from multiple Subgraphs or triggering actions based on external updates. | ||
|
||
## Prerequisites | ||
|
||
To deploy **all** Subgraphs locally, you must have the following: | ||
|
||
- A [graph-node](https://github.com/graphprotocol/graph-node) instance running locally | ||
MichaelMacaulay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
- An [IPFS](https://docs.ipfs.tech/) instance running locally | ||
- [Node.js](https://nodejs.org) and npm | ||
|
||
## Get Started | ||
|
||
The following guide provides examples for defining three source Subgraphs to create one powerful composed Subgraph. | ||
|
||
### Specifics | ||
|
||
- To keep this example simple, all source Subgraphs use only block handlers. However, in a real environment, each source Subgraph will use data from different smart contracts. | ||
- The examples below show how to import and extend the schema of another Subgraph to enhance its functionality. | ||
- Each source Subgraph is optimized with a specific entity. | ||
- All the commands listed install the necessary dependencies, generate code based on the GraphQL schema, build the Subgraph, and deploy it to your local Graph Node instance. | ||
|
||
### Step 1. Deploy Block Time Source Subgraph | ||
|
||
This first source Subgraph calculates the block time for each block. | ||
|
||
- It imports schemas from other Subgraphs and adds a `block` entity with a `timestamp` field, representing the time each block was mined. | ||
- It listens to time-related blockchain events (e.g., block timestamps) and processes this data to update the Subgraph's entities accordingly. | ||
|
||
To deploy this Subgraph locally, run the following commands: | ||
|
||
```bash | ||
npm install | ||
npm run codegen | ||
npm run build | ||
npm run create-local | ||
npm run deploy-local | ||
``` | ||
|
||
### Step 2. Deploy Block Cost Source Subgraph | ||
|
||
This second source Subgraph indexes the cost of each block. | ||
|
||
#### Key Functions | ||
|
||
- It imports schemas from other Subgraphs and adds a `block` entity with cost-related fields. | ||
- It listens to blockchain events related to costs (e.g. gas fees, transaction costs) and processes this data to update the Subgraph's entities accordingly. | ||
|
||
To deploy this Subgraph locally, run the same commands as above. | ||
|
||
### Step 3. Define Block Size in Source Subgraph | ||
|
||
This third source Subgraph indexes the size of each block. | ||
|
||
#### Key Functions | ||
|
||
- It imports existing schemas from other Subgraphs and adds a `block` entity with a `size` field representing each block's size. | ||
- It listens to blockchain events related to block sizes (e.g., storage or volume) and processes this data to update the Subgraph's entities accordingly. | ||
MichaelMacaulay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Step 4. Combine Into Block Stats Subgraph | ||
|
||
This composed Subgraph combines and aggregates the information from the three source Subgraphs above, providing a unified view of block statistics. | ||
|
||
> Note: | ||
> | ||
> - Any change to a source Subgraph will likely generate a new deployment ID. | ||
> - Be sure to update the deployment ID in the data source address of the Subgraph manifest to take advantage of the latest changes. | ||
> - All source Subgraphs should be deployed before the composed Subgraph is deployed. | ||
|
||
#### Key Functions | ||
|
||
- It provides a consolidated data model that encompasses all relevant block metrics. | ||
- It combines data from three source Subgraphs, and provides a comprehensive view of block statistics, enabling more complex queries and analyses. | ||
|
||
## Key Takeaways | ||
|
||
- This powerful tool will scale your Subgraph development and allow you to combine multiple Subgraphs. | ||
- The setup includes the deployment of three source Subgraphs and one final deployment of the composed Subgraph. | ||
- This feature unlocks scalability, simplifying both development and maintenance efficiency. | ||
|
||
## Additional Resources | ||
|
||
- Check out all the code for this example in [this GitHub repo](https://github.com/isum/subgraph-composition-example). | ||
- Add advanced features in your Subgraph. Check out [Subgraph advanced features](/developing/creating/advanced/). | ||
MichaelMacaulay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
- To learn more about aggregations, check out [Timeseries and Aggregations](/subgraphs/developing/creating/advanced/#timeseries-and-aggregations). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'subgraph-composition-three-sources': '', | ||
'subgraph-debug-forking': '', | ||
near: '', | ||
arweave: '', | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'subgraph-composition-three-sources': '', | ||
'subgraph-debug-forking': '', | ||
near: '', | ||
arweave: '', | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'subgraph-composition-three-sources': '', | ||
'subgraph-debug-forking': '', | ||
near: '', | ||
arweave: '', | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'subgraph-composition-three-sources': '', | ||
'subgraph-debug-forking': '', | ||
near: '', | ||
arweave: '', | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'subgraph-composition-three-sources': '', | ||
'subgraph-debug-forking': '', | ||
near: '', | ||
arweave: '', | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'subgraph-composition-three-sources': '', | ||
'subgraph-debug-forking': '', | ||
near: '', | ||
arweave: '', | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'subgraph-composition-three-sources': '', | ||
'subgraph-debug-forking': '', | ||
near: '', | ||
arweave: '', | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'subgraph-composition-three-sources': '', | ||
'subgraph-debug-forking': '', | ||
near: '', | ||
arweave: '', | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'subgraph-composition-three-sources': '', | ||
'subgraph-debug-forking': '', | ||
near: '', | ||
arweave: '', | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'subgraph-composition-three-sources': '', | ||
'subgraph-debug-forking': '', | ||
near: '', | ||
arweave: '', | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'subgraph-composition-three-sources': '', | ||
'subgraph-debug-forking': '', | ||
near: '', | ||
arweave: '', | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'subgraph-composition-three-sources': '', | ||
'subgraph-debug-forking': '', | ||
near: '', | ||
arweave: '', | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'subgraph-composition-three-sources': '', | ||
'subgraph-debug-forking': '', | ||
near: '', | ||
arweave: '', | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'subgraph-composition-three-sources': '', | ||
'subgraph-debug-forking': '', | ||
near: '', | ||
arweave: '', | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'subgraph-composition-three-sources': '', | ||
'subgraph-debug-forking': '', | ||
near: '', | ||
arweave: '', | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'subgraph-composition-three-sources': '', | ||
'subgraph-debug-forking': '', | ||
near: '', | ||
arweave: '', | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'subgraph-composition-three-sources': '', | ||
'subgraph-debug-forking': '', | ||
near: '', | ||
arweave: '', | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'subgraph-composition-three-sources': '', | ||
'subgraph-debug-forking': '', | ||
near: '', | ||
arweave: '', | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.