Grafting (Advanced)

You will learn how to build and deploy new subgraphs by grafting existing subgraphs.
For larger subgraphs or when continuously deploying smart contracts as part of a project, developers often encounter challenges when indexing a subgraph from its inception, which can lead to resource inefficiency and time consumption.
For more experienced developers, there is the option to utilize the Grafting feature. Grafting involves reusing data from a compatible existing subgraph and initiating indexing from a custom-defined later block. This approach can prove beneficial for testing new features within the underlying smart contract or subgraph entity, particularly when indexing from scratch would be excessively time-consuming. Additionally, Grafting can help swiftly address simple mapping errors during development or temporarily restore the functionality of an existing subgraph that has encountered issues. The new grafted subgraph does not have to have an identical GraphQL schema as the old base subgraph. It only needs to be compatible with it. It may deviate from the base subgraph's schema in the following ways:
  • Adding or removing entity types.
  • Removing attributes from entity types.
  • Adding nullable attributes to entity types.
  • Turning non-nullable attributes into nullable attributes.
  • Adding values to enums.
  • Adding or removing interfaces.
  • Changing for which entity types an interface is implemented.
The Official Graph Documentation offers in depth tutorial and documentations on how Grafting can be performed on a subgraph. https://thegraph.com/docs/en/developing/creating-a-subgraph/#grafting-onto-existing-subgraphs https://thegraph.com/docs/en/cookbook/grafting/#important-note-on-grafting-when-upgrading-to-the-network​
Last modified 3mo ago