Workflows for pulling data from The Graph indexer with scheduled cron triggers. These workflows demonstrate the pull pattern where the workflow initiates and fetches data on a schedule.
Directory Structure
building-blocks/indexer-fetch/
โโโ README.md (this file)
โโโ indexer-fetch-go/ (Go-based workflow)
โ โโโ my-workflow/
โ โโโ workflow.go
โ โโโ main.go
โ โโโ config.staging.json
โ โโโ config.production.json
โ โโโ workflow.yaml
โโโ indexer-fetch-ts/ (TypeScript-based workflow)
โโโ workflow/
โโโ main.ts
โโโ config.staging.json
โโโ config.production.json
โโโ package.json
โโโ workflow.yaml
Overview
These workflows demonstrate how to:
- Query The Graph indexer using GraphQL
- Use cron triggers to schedule periodic data fetching
- Process and return JSON-formatted indexer data
- Implement the same functionality in both Go and TypeScript
Both workflows query the Uniswap V4 subgraph on The Graph and fetch:
- Pool manager statistics (pool count, transaction count, total volume)
- ETH price data from bundles
Workflows
1 indexer-fetch-go (Go Implementation)
Language: Go
Features:
- Uses
http.SendRequestpattern from CRE Go SDK - Implements
ConsensusIdenticalAggregationfor deterministic data - Returns formatted JSON with timestamp and endpoint info
Running the workflow:
cd building-blocks/indexer-fetch/indexer-fetch-go
cre workflow simulate my-workflow --target staging-settings
2 indexer-fetch-ts (TypeScript Implementation)
Language: TypeScript
Features:
- Uses
runInNodeModepattern from CRE TypeScript SDK - Implements custom first-result aggregation for deterministic data
- Returns formatted JSON with timestamp and endpoint info
Running the workflow:
cd building-blocks/indexer-fetch/indexer-fetch-ts
cre workflow simulate workflow --target staging-settings
Configuration
Both workflows use the same configuration structure in their respective config.staging.json files:
{
"schedule": "0 * * * * *",
"graphqlEndpoint": "https://gateway.thegraph.com/api/bca58895bc60dcb319e3cbdfd989b964/subgraphs/id/Gqm2b5J85n1bhCyDMpGbtbVn4935EvvdyHdHrx3dibyj",
"query": "{ poolManagers(first: 5) { id poolCount txCount totalVolumeUSD } bundles(first: 5) { id ethPriceUSD } }",
"variables": {}
}
Configuration Options
-
schedule: Cron expression in 6-field format (second minute hour day month weekday)
"0 * * * * *"- Every minute at second 0"*/30 * * * * *"- Every 30 seconds"0 */5 * * * *"- Every 5 minutes at second 0
-
graphqlEndpoint: The Graph API endpoint URL
- Gateway endpoint:
https://gateway.thegraph.com/api/{api-key}/subgraphs/id/{subgraph-id} - Studio endpoint:
https://api.studio.thegraph.com/query/{id}/{name}/version/latest
- Gateway endpoint:
-
query: GraphQL query string
- Simple queries without variables work best
- See The Graph documentation for query syntax
-
variables: Object with variables for the GraphQL query (optional)
Setup and Testing
1 Prerequisites
For Go workflow:
- Install CRE CLI
- Login:
cre login - Install Go
For TypeScript workflow:
- Install CRE CLI
- Login:
cre login - Install Bun (or Node.js)
- Run
bun installin the workflow directory
2 Running the Workflows
Go Workflow:
cd building-blocks/indexer-fetch/indexer-fetch-go
cre workflow simulate workflow --target staging-settings
TypeScript Workflow:
cd building-blocks/indexer-fetch/indexer-fetch-ts
cre workflow simulate workflow --target staging-settings
3 Example Output
Both workflows return JSON output like:
{
"timestamp": "2025-11-18T18:43:08.452Z",
"endpoint": "https://gateway.thegraph.com/api/.../subgraphs/id/...",
"data": {
"bundles": [
{
"ethPriceUSD": "3157.000458184067393927942592490315",
"id": "1"
}
],
"poolManagers": [
{
"id": "0x498581ff718922c3f8e6a244956af099b2652b2b",
"poolCount": "5123368",
"totalVolumeUSD": "5611562100.854190095192400782985064",
"txCount": "480580367"
}
]
}
}
Example Use Cases
1. Monitoring Uniswap V4 Pools
Query pool statistics every minute:
{
"schedule": "0 * * * * *",
"graphqlEndpoint": "https://gateway.thegraph.com/api/{key}/subgraphs/id/{id}",
"query": "{ poolManagers(first: 5) { id poolCount totalVolumeUSD } }",
"variables": {}
}
2. Tracking Token Prices
Monitor token prices every 30 seconds:
{
"schedule": "*/30 * * * * *",
"graphqlEndpoint": "https://gateway.thegraph.com/api/{key}/subgraphs/id/{id}",
"query": "{ tokens(first: 10, orderBy: volumeUSD, orderDirection: desc) { id symbol volumeUSD } }",
"variables": {}
}
3. DeFi Protocol Metrics
Check protocol statistics every 5 minutes:
{
"schedule": "0 */5 * * * *",
"graphqlEndpoint": "https://gateway.thegraph.com/api/{key}/subgraphs/id/{id}",
"query": "{ protocols(first: 1) { totalValueLockedUSD totalVolumeUSD txCount } }",
"variables": {}
}
CREATED BY CHAINLINK LABS