Open
Description
Summary
So far we only support Ethereum contracts as data sources and event handlers as mappings. As a consequence, the code that wires up subgraphs for indexing is kind of special-cased (e.g. everything is based on the block stream). We aim to extend subgraphs to support other data sources like IPFS files and make it easier to add more data source types over time.
This issue describes the requirements for supporting multiple data source types and the changes proposed to implement them.
Requirements
- Need to support multiple data source types (e.g.
ethereum/contract
,ipfs/file
etc.). - Supported data source types have some fields in common (like
kind
,name
andmapping
); other fields are unique to the data source type. - Data sources of all types are started and stopped with the subgraph deployment.
- Data sources require their own state.
- The overall progress of a subgraph needs to be calculated from all of its data sources.
Proposed Changes
I propose that the implementation takes place in two phases. First, implement block streaming, state management and progress information per data source rather than per subgraph. Then, extend the system to supporting generic (potentially different) data sources.
Phase 1
- Make
SubgraphInstanceManager
andSubgraphInstance
instantiate aDataSourceInstance
for every data source. - Add a
DataSourceIndexer
trait that is responsible for indexing a particular type of data source. Add anEthereumContractInstance
version that operates based on a block stream. - Add
Store
helper to read the state of a data source of a subgraph as aFrom<serde_json::Value>
or similar. - Change block pointers to be for a data source instead a subgraph.
Phase 2
- Extend the GraphQL schema for the subgraph of subgraphs to support data sources of different types, either through interfaces or unions.
- Turn data sources and mappings in
SubgraphManifest
into either an enum or come up with builder-style pattern for creatingDataSourceInstance
s from data sources. - Make
SubgraphRegistrar
write different types of data sources to the store.