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
core,node,server: move opt to core and add graphman config check to g…
…raphql api
  • Loading branch information
shiyasmohd committed Jan 1, 2025
commit eab550d155b110981827013b56c9b625fc9ec456
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions core/graphman/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ edition.workspace = true

[dependencies]
anyhow = { workspace = true }
async-graphql = { workspace = true }
clap = { workspace = true }
diesel = { workspace = true }
git-testament = "0.2"
graph = { workspace = true }
graph-store-postgres = { workspace = true }
graphman-store = { workspace = true }
itertools = { workspace = true }
lazy_static = "1.5.0"
thiserror = { workspace = true }
tokio = { workspace = true }
graph-chain-ethereum = { path = "../../chain/ethereum" }
Expand Down
1 change: 1 addition & 0 deletions core/graphman/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod commands;
pub mod config;
pub mod deployment;
pub mod execution_tracker;
pub mod opt;

pub use self::error::GraphmanError;
pub use self::execution_tracker::GraphmanExecutionTracker;
2 changes: 1 addition & 1 deletion node/src/opt.rs → core/graphman/src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use clap::Parser;
use git_testament::{git_testament, render_testament};
use lazy_static::lazy_static;

use graphman::config;
use crate::config;

git_testament!(TESTAMENT);
lazy_static! {
Expand Down
1 change: 0 additions & 1 deletion node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ extern crate diesel;

pub mod chain;
pub mod network_setup;
pub mod opt;
pub mod store_builder;

pub mod manager;
Expand Down
2 changes: 1 addition & 1 deletion node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use graph_core::{
};
use graph_graphql::prelude::GraphQlRunner;
use graph_node::network_setup::Networks;
use graph_node::opt;
use graph_node::store_builder::StoreBuilder;
use graph_server_http::GraphQLServer as GraphQLQueryServer;
use graph_server_index_node::IndexNodeServer;
Expand All @@ -32,6 +31,7 @@ use graph_store_postgres::connection_pool::ConnectionPool;
use graph_store_postgres::Store;
use graph_store_postgres::{register_jobs as register_store_jobs, NotificationSender};
use graphman::config::Config;
use graphman::opt;
use graphman_server::GraphmanServer;
use graphman_server::GraphmanServerConfig;
use std::io::{BufRead, BufReader};
Expand Down
1 change: 1 addition & 0 deletions server/graphman/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ async-graphql = { workspace = true }
async-graphql-axum = { workspace = true }
axum = { workspace = true }
chrono = { workspace = true }
clap = { workspace = true }
graph = { workspace = true }
graph-store-postgres = { workspace = true }
graphman = { workspace = true }
Expand Down
21 changes: 21 additions & 0 deletions server/graphman/src/entities/config_check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use async_graphql::SimpleObject;

#[derive(Clone, Debug, SimpleObject)]
pub struct ConfigCheckResponse {
/// Checks if the config file is validated.
pub config_validated: bool,
/// Checks if the subgraph settings config set by GRAPH_EXPERIMENTAL_SUBGRAPH_SETTINGS are validated.
pub subgraph_settings_validated: bool,
/// Returns the Config file as a string.
pub config: String,
}

impl ConfigCheckResponse {
pub fn from(config_validated: bool, subgraph_settings_validated: bool, config: String) -> Self {
Self {
config_validated,
subgraph_settings_validated,
config,
}
}
}
2 changes: 2 additions & 0 deletions server/graphman/src/entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod block_hash;
mod block_number;
mod block_ptr;
mod command_kind;
mod config_check;
mod deployment_info;
mod deployment_selector;
mod deployment_status;
Expand All @@ -15,6 +16,7 @@ pub use self::block_hash::BlockHash;
pub use self::block_number::BlockNumber;
pub use self::block_ptr::BlockPtr;
pub use self::command_kind::CommandKind;
pub use self::config_check::ConfigCheckResponse;
pub use self::deployment_info::DeploymentInfo;
pub use self::deployment_selector::DeploymentSelector;
pub use self::deployment_status::DeploymentStatus;
Expand Down
16 changes: 16 additions & 0 deletions server/graphman/src/resolvers/config_query.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use async_graphql::Context;
use async_graphql::Object;
use async_graphql::Result;

use crate::entities::ConfigCheckResponse;

mod check;
pub struct ConfigQuery;

#[Object]
impl ConfigQuery {
/// Check and validate the configuration file
pub async fn check(&self, ctx: &Context<'_>) -> Result<ConfigCheckResponse> {
check::run(ctx)
}
}
14 changes: 14 additions & 0 deletions server/graphman/src/resolvers/config_query/check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use async_graphql::{Context, Result};
use graphman::commands::config::check::check;

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

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(),
))
}
16 changes: 16 additions & 0 deletions server/graphman/src/resolvers/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,42 @@ 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,
})
}
}
2 changes: 2 additions & 0 deletions server/graphman/src/resolvers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
mod config_query;
mod context;
mod deployment_mutation;
mod deployment_query;
mod execution_query;
mod mutation_root;
mod query_root;

pub use self::config_query::ConfigQuery;
pub use self::deployment_mutation::DeploymentMutation;
pub use self::deployment_query::DeploymentQuery;
pub use self::execution_query::ExecutionQuery;
Expand Down
6 changes: 6 additions & 0 deletions server/graphman/src/resolvers/query_root.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use async_graphql::Object;

use crate::resolvers::ConfigQuery;
use crate::resolvers::DeploymentQuery;
use crate::resolvers::ExecutionQuery;

Expand All @@ -13,6 +14,11 @@ impl QueryRoot {
DeploymentQuery {}
}

/// Queries related to Config.
pub async fn config(&self) -> ConfigQuery {
ConfigQuery {}
}

/// Queries related to command executions.
pub async fn execution(&self) -> ExecutionQuery {
ExecutionQuery {}
Expand Down
Loading