Skip to content

Commit 4e7824e

Browse files
committed
server: accept only arguments in Opt when loading config in graphql api
1 parent f6018be commit 4e7824e

File tree

3 files changed

+62
-26
lines changed

3 files changed

+62
-26
lines changed

server/graphman/src/resolvers/config_query.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use async_graphql::Context;
21
use async_graphql::Object;
32
use async_graphql::Result;
43

@@ -10,7 +9,7 @@ pub struct ConfigQuery;
109
#[Object]
1110
impl ConfigQuery {
1211
/// Check and validate the configuration file
13-
pub async fn check(&self, ctx: &Context<'_>) -> Result<ConfigCheckResponse> {
14-
check::run(ctx)
12+
pub async fn check(&self) -> Result<ConfigCheckResponse> {
13+
check::run()
1514
}
1615
}
Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,68 @@
1-
use async_graphql::{Context, Result};
2-
use graphman::commands::config::check::check;
1+
use async_graphql::Result;
2+
use clap::Parser;
3+
use graph::{log::logger, prelude::error};
4+
use graphman::{commands::config::check::check, config::Config, opt::Opt};
35

4-
use crate::{entities::ConfigCheckResponse, resolvers::context::GraphmanContext};
6+
use crate::entities::ConfigCheckResponse;
7+
8+
pub fn run() -> Result<ConfigCheckResponse> {
9+
let config = fetch_config()?;
10+
let res = check(&config, true)?;
511

6-
pub fn run(ctx: &Context<'_>) -> Result<ConfigCheckResponse> {
7-
let ctx = GraphmanContext::new(ctx)?;
8-
let res = check(&ctx.config, true)?;
912
Ok(ConfigCheckResponse::from(
1013
res.validated,
1114
res.validated_subgraph_settings,
1215
res.config_json.unwrap_or_default(),
1316
))
1417
}
18+
19+
pub fn fetch_config() -> Result<Config> {
20+
let args: Vec<String> = std::env::args().collect();
21+
let accepted_flags = vec![
22+
"--config",
23+
"--check-config",
24+
"--subgraph",
25+
"--start-block",
26+
"--postgres-url",
27+
"--postgres-secondary-hosts",
28+
"--postgres-host-weights",
29+
"--ethereum-rpc",
30+
"--ethereum-ws",
31+
"--ethereum-ipc",
32+
"--ipfs",
33+
"--arweave",
34+
"--http-port",
35+
"--index-node-port",
36+
"--ws-port",
37+
"--admin-port",
38+
"--metrics-port",
39+
"--node-id",
40+
"--expensive-queries-filename",
41+
"--debug",
42+
"--elasticsearch-url",
43+
"--elasticsearch-user",
44+
"--elasticsearch-password",
45+
"--disable-block-ingestor",
46+
"--store-connection-pool-size",
47+
"--unsafe-config",
48+
"--debug-fork",
49+
"--fork-base",
50+
"--graphman-port",
51+
];
52+
let mut filtered_args: Vec<String> = vec![args[0].clone()];
53+
for (i, arg) in args.iter().enumerate() {
54+
if accepted_flags.contains(&arg.as_str()) {
55+
filtered_args.push(arg.clone());
56+
filtered_args.push(args[i + 1].clone());
57+
}
58+
}
59+
let opt = Opt::try_parse_from(filtered_args).expect("Failed to parse args");
60+
let logger = logger(opt.debug);
61+
match Config::load(&logger, &opt.clone().into()) {
62+
Ok(config) => Ok(config),
63+
Err(e) => {
64+
error!(logger, "Failed to load config due to: {}", e.to_string());
65+
return Err(e.into());
66+
}
67+
}
68+
}

server/graphman/src/resolvers/context.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,25 @@ use std::sync::Arc;
22

33
use async_graphql::Context;
44
use async_graphql::Result;
5-
use clap::Parser;
6-
use graph::log::logger;
7-
use graph::prelude::error;
85
use graph_store_postgres::connection_pool::ConnectionPool;
96
use graph_store_postgres::NotificationSender;
107
use graph_store_postgres::Store;
11-
use graphman::config::Config;
12-
use graphman::opt::Opt;
138

149
pub struct GraphmanContext {
1510
pub primary_pool: ConnectionPool,
1611
pub notification_sender: Arc<NotificationSender>,
1712
pub store: Arc<Store>,
18-
pub config: Config,
1913
}
2014

2115
impl GraphmanContext {
2216
pub fn new(ctx: &Context<'_>) -> Result<GraphmanContext> {
2317
let primary_pool = ctx.data::<ConnectionPool>()?.to_owned();
2418
let notification_sender = ctx.data::<Arc<NotificationSender>>()?.to_owned();
2519
let store = ctx.data::<Arc<Store>>()?.to_owned();
26-
let opt = Opt::parse();
27-
let logger = logger(opt.debug);
28-
let config = match Config::load(&logger, &opt.clone().into()) {
29-
Ok(config) => config,
30-
Err(e) => {
31-
error!(logger, "Failed to load config due to: {}", e.to_string());
32-
return Err(e.into());
33-
}
34-
};
35-
3620
Ok(GraphmanContext {
3721
primary_pool,
3822
notification_sender,
3923
store,
40-
config,
4124
})
4225
}
4326
}

0 commit comments

Comments
 (0)