|
1 | 1 | use std::{collections::BTreeMap, sync::Arc};
|
2 | 2 |
|
3 | 3 | use graph::{
|
4 |
| - anyhow::bail, |
5 |
| - components::subgraph::Settings, |
| 4 | + anyhow::{bail, Context}, |
| 5 | + components::subgraph::{Setting, Settings}, |
6 | 6 | endpoint::EndpointMetrics,
|
7 | 7 | env::EnvVars,
|
8 | 8 | itertools::Itertools,
|
9 | 9 | prelude::{
|
10 | 10 | anyhow::{anyhow, Error},
|
11 |
| - MetricsRegistry, NodeId, |
| 11 | + MetricsRegistry, NodeId, SubgraphName, |
12 | 12 | },
|
13 | 13 | slog::Logger,
|
14 | 14 | };
|
@@ -158,3 +158,25 @@ pub async fn provider(
|
158 | 158 | );
|
159 | 159 | Ok(())
|
160 | 160 | }
|
| 161 | + |
| 162 | +pub fn setting(name: &str) -> Result<(), Error> { |
| 163 | + let name = SubgraphName::new(name).map_err(|()| anyhow!("illegal subgraph name `{}`", name))?; |
| 164 | + let env_vars = EnvVars::from_env().unwrap(); |
| 165 | + if let Some(path) = &env_vars.subgraph_settings { |
| 166 | + let settings = Settings::from_file(path) |
| 167 | + .with_context(|| format!("syntax error in subgraph settings `{}`", path))?; |
| 168 | + match settings.for_name(&name) { |
| 169 | + Some(Setting { history_blocks, .. }) => { |
| 170 | + println!("setting for `{name}` will use history_blocks = {history_blocks}"); |
| 171 | + } |
| 172 | + None => { |
| 173 | + println!("no specific setting for `{name}`, defaults will be used"); |
| 174 | + } |
| 175 | + } |
| 176 | + } else { |
| 177 | + println!("No subgraph-specific settings will be applied because"); |
| 178 | + println!("GRAPH_EXPERIMENTAL_SUBGRAPH_SETTINGS is not set"); |
| 179 | + }; |
| 180 | + |
| 181 | + Ok(()) |
| 182 | +} |
0 commit comments