Skip to content

add graphman config check, place, pools to graphql api #5751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Prev Previous commit
Next Next commit
server: accept only arguments in Opt when loading config in graphql api
  • Loading branch information
shiyasmohd committed Jan 4, 2025
commit 4e7824e93d72b19d7927ea31a3a692ffce18d45d
5 changes: 2 additions & 3 deletions server/graphman/src/resolvers/config_query.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use async_graphql::Context;
use async_graphql::Object;
use async_graphql::Result;

Expand All @@ -10,7 +9,7 @@ pub struct ConfigQuery;
#[Object]
impl ConfigQuery {
/// Check and validate the configuration file
pub async fn check(&self, ctx: &Context<'_>) -> Result<ConfigCheckResponse> {
check::run(ctx)
pub async fn check(&self) -> Result<ConfigCheckResponse> {
check::run()
}
}
66 changes: 60 additions & 6 deletions server/graphman/src/resolvers/config_query/check.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,68 @@
use async_graphql::{Context, Result};
use graphman::commands::config::check::check;
use async_graphql::Result;
use clap::Parser;
use graph::{log::logger, prelude::error};
use graphman::{commands::config::check::check, config::Config, opt::Opt};

use crate::{entities::ConfigCheckResponse, resolvers::context::GraphmanContext};
use crate::entities::ConfigCheckResponse;

pub fn run() -> Result<ConfigCheckResponse> {
let config = fetch_config()?;
let res = check(&config, true)?;

pub fn run(ctx: &Context<'_>) -> Result<ConfigCheckResponse> {
let ctx = GraphmanContext::new(ctx)?;
let res = check(&ctx.config, true)?;
Ok(ConfigCheckResponse::from(
res.validated,
res.validated_subgraph_settings,
res.config_json.unwrap_or_default(),
))
}

pub fn fetch_config() -> Result<Config> {
let args: Vec<String> = std::env::args().collect();
let accepted_flags = vec![
"--config",
"--check-config",
"--subgraph",
"--start-block",
"--postgres-url",
"--postgres-secondary-hosts",
"--postgres-host-weights",
"--ethereum-rpc",
"--ethereum-ws",
"--ethereum-ipc",
"--ipfs",
"--arweave",
"--http-port",
"--index-node-port",
"--ws-port",
"--admin-port",
"--metrics-port",
"--node-id",
"--expensive-queries-filename",
"--debug",
"--elasticsearch-url",
"--elasticsearch-user",
"--elasticsearch-password",
"--disable-block-ingestor",
"--store-connection-pool-size",
"--unsafe-config",
"--debug-fork",
"--fork-base",
"--graphman-port",
];
let mut filtered_args: Vec<String> = vec![args[0].clone()];
for (i, arg) in args.iter().enumerate() {
if accepted_flags.contains(&arg.as_str()) {
filtered_args.push(arg.clone());
filtered_args.push(args[i + 1].clone());
}
}
let opt = Opt::try_parse_from(filtered_args).expect("Failed to parse args");
let logger = logger(opt.debug);
match Config::load(&logger, &opt.clone().into()) {
Ok(config) => Ok(config),
Err(e) => {
error!(logger, "Failed to load config due to: {}", e.to_string());
return Err(e.into());
}
}
}
17 changes: 0 additions & 17 deletions server/graphman/src/resolvers/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,25 @@ use std::sync::Arc;

use async_graphql::Context;
use async_graphql::Result;
use clap::Parser;
use graph::log::logger;
use graph::prelude::error;
use graph_store_postgres::connection_pool::ConnectionPool;
use graph_store_postgres::NotificationSender;
use graph_store_postgres::Store;
use graphman::config::Config;
use graphman::opt::Opt;

pub struct GraphmanContext {
pub primary_pool: ConnectionPool,
pub notification_sender: Arc<NotificationSender>,
pub store: Arc<Store>,
pub config: Config,
}

impl GraphmanContext {
pub fn new(ctx: &Context<'_>) -> Result<GraphmanContext> {
let primary_pool = ctx.data::<ConnectionPool>()?.to_owned();
let notification_sender = ctx.data::<Arc<NotificationSender>>()?.to_owned();
let store = ctx.data::<Arc<Store>>()?.to_owned();
let opt = Opt::parse();
let logger = logger(opt.debug);
let config = match Config::load(&logger, &opt.clone().into()) {
Ok(config) => config,
Err(e) => {
error!(logger, "Failed to load config due to: {}", e.to_string());
return Err(e.into());
}
};

Ok(GraphmanContext {
primary_pool,
notification_sender,
store,
config,
})
}
}