Skip to content

Conversation

teogeb
Copy link
Contributor

@teogeb teogeb commented Jun 11, 2025

Extracted subgraph configs (mainly contract addresses and startBlock values) to a separate subgraph-config.json file. Now the actual subgraph.yaml is generated in build.sh by filling the config options to a Handlebars template.

We don't need separate environment specific subgraph_* yaml files anymore.

Implementation

There is a small fill-handlebars-template.mjs script which reads the config from stdin and outputs the filled template to stdout. There is no custom logic in that script, and alternative we could use some ready-made external Handlebars utility instead of this script.

Config file

The config file was generated from the existing subgraph_*.yaml files by this script:

import { readFileSync } from 'fs'
import yaml from 'js-yaml'

const ENVIRONMENT_IDS = ['dev2', 'polygon', 'polygonAmoy', 'peaq', 'iotex']

const output = {}

for (const environmentId of ENVIRONMENT_IDS) {
    const fileId = (environmentId === 'polygonAmoy') ? 'amoy' : environmentId
    const fileName = `subgraph_${fileId}.yaml`
    const fileContents = readFileSync(fileName, 'utf8')
    const yamlData = yaml.load(fileContents)
    const contracts = {}
    for (const dataSource of yamlData.dataSources) {
        const source = dataSource.source
        const key = (source.abi === 'NodeRegistry') ? 'StorageNodeRegistry' : source.abi
        contracts[key] = {
            address: source.address,
            startBlock: source.startBlock
        }
    }
    const networkId = (environmentId === 'polygon') 
        ? 'matic' : 
            ((environmentId === 'polygonAmoy') ? 'polygon-amoy' : environmentId)
    output[environmentId] = {
        networkId,
        hubContracts: (environmentId !== 'iotex'),
        contracts
    }
}

console.log(JSON.stringify(output, undefined, 4))

Small changes to subgraph.yaml output

The subgraph.yaml output generated by the build.sh matches almost exactly the current files. Exceptions:

  • removed some TODO comments
  • unified quotes to be single quotes
  • unified the description

See three commits in this PR for the exact unifications. There was also test.sh script in commit bda37c6 to check that the outputs match the current files.

Notes about Iotex

Thet addresses in the subgraph-config.json matches the addresses which were used in subgraph_iotex.yaml, but don't match the values of @streamr/config. Therefore this PR doesn't change any functionality. There is a separate PR about this #1010 issue.

Also in that PR or in a follow-up PR we may add hub contracts to iotex config. If we do that we should remove the hubContracts property from the subgraph-configs.json (and the related if statement in subgraph.yaml.hbs) as the value for that is true in environment.s

@teogeb teogeb requested a review from harbu June 11, 2025 12:06
@teogeb teogeb merged commit b575045 into main Jun 12, 2025
3 checks passed
@teogeb teogeb deleted the subgraph-yaml-template branch June 12, 2025 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants