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: add graphman config place command to graphql api
  • Loading branch information
shiyasmohd committed Jan 5, 2025
commit dcd0ca9ff5bce097a15f1c26d33f28465f88fd0e
1 change: 1 addition & 0 deletions core/graphman/src/commands/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod check;
pub mod place;
32 changes: 32 additions & 0 deletions core/graphman/src/commands/config/place.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use anyhow::{anyhow, Error as AnyError};
use graph_store_postgres::DeploymentPlacer;
use thiserror::Error;

pub struct PlaceResult {
pub shards: Vec<String>,
pub nodes: Vec<String>,
}

#[derive(Debug, Error)]
pub enum PlaceError {
#[error("No matching placement rule; default placement from JSON RPC call would be used")]
NoPlacementRule,

#[error(transparent)]
Common(#[from] AnyError),
}

pub fn place(
placer: &dyn DeploymentPlacer,
name: &str,
network: &str,
) -> Result<PlaceResult, PlaceError> {
match placer.place(name, network).map_err(|s| anyhow!(s))? {
None => Err(PlaceError::NoPlacementRule),
Some((shards, nodes)) => {
let nodes: Vec<_> = nodes.into_iter().map(|n| n.to_string()).collect();
let shards: Vec<_> = shards.into_iter().map(|s| s.to_string()).collect();
Ok(PlaceResult { shards, nodes })
}
}
}
2 changes: 1 addition & 1 deletion node/src/bin/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ async fn main() -> anyhow::Result<()> {
Ok(())
}
Place { name, network } => {
commands::config::place(&ctx.config.deployment, &name, &network)
commands::config_cmd::place::run(&ctx.config.deployment, &name, &network)
}
Check { print } => commands::config_cmd::check::run(&ctx.config, print),
Pools { nodes, shard } => commands::config::pools(&ctx.config, nodes, shard),
Expand Down
1 change: 1 addition & 0 deletions node/src/manager/commands/config_cmd/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod check;
pub mod place;
22 changes: 22 additions & 0 deletions node/src/manager/commands/config_cmd/place.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use anyhow::Error;
use graph_store_postgres::DeploymentPlacer;
use graphman::commands::config::place::{place, PlaceError};

pub fn run(placer: &dyn DeploymentPlacer, name: &String, network: &String) -> Result<(), Error> {
let res = place(placer, name, network);
match res {
Ok(result) => {
println!("subgraph: {}", name);
println!("network: {}", network);
println!("shard: {}", result.shards.join(", "));
println!("nodes: {}", result.nodes.join(", "));
}
Err(PlaceError::NoPlacementRule) => {
println!("{}", PlaceError::NoPlacementRule);
}
Err(PlaceError::Common(e)) => {
println!("Error: {}", e.to_string());
}
};
Ok(())
}
2 changes: 2 additions & 0 deletions server/graphman/src/entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod deployment_version_selector;
mod empty_response;
mod execution;
mod execution_id;
mod place_response;
mod subgraph_health;

pub use self::block_hash::BlockHash;
Expand All @@ -24,4 +25,5 @@ pub use self::deployment_version_selector::DeploymentVersionSelector;
pub use self::empty_response::EmptyResponse;
pub use self::execution::Execution;
pub use self::execution_id::ExecutionId;
pub use self::place_response::PlaceResponse;
pub use self::subgraph_health::SubgraphHealth;
25 changes: 25 additions & 0 deletions server/graphman/src/entities/place_response.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use async_graphql::SimpleObject;

#[derive(Clone, Debug, SimpleObject)]
pub struct PlaceResponse {
subgraph: String,
network: String,
shards: Vec<String>,
nodes: Vec<String>,
}

impl PlaceResponse {
pub fn from(
subgraph: String,
network: String,
shards: Vec<String>,
nodes: Vec<String>,
) -> Self {
Self {
subgraph,
network,
shards,
nodes,
}
}
}
11 changes: 11 additions & 0 deletions server/graphman/src/resolvers/config_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ use async_graphql::Object;
use async_graphql::Result;

use crate::entities::ConfigCheckResponse;
use crate::entities::PlaceResponse;

mod check;
mod place;
pub struct ConfigQuery;

#[Object]
Expand All @@ -12,4 +14,13 @@ impl ConfigQuery {
pub async fn check(&self) -> Result<ConfigCheckResponse> {
check::run()
}

/// Returns how a specific subgraph would be placed
pub async fn place(
&self,
#[graphql(desc = "Subgraph name")] subgraph: String,
#[graphql(desc = "Network name")] network: String,
) -> Result<PlaceResponse> {
place::run(subgraph, network).await
}
}
15 changes: 15 additions & 0 deletions server/graphman/src/resolvers/config_query/place.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use async_graphql::Result;
use graphman::commands::config::place::place;

use crate::entities::PlaceResponse;

use super::check::fetch_config;

pub async fn run(subgraph: String, network: String) -> Result<PlaceResponse> {
let config = fetch_config()?;
let res = place(&config.deployment, &subgraph, &network)?;

Ok(PlaceResponse::from(
subgraph, network, res.shards, res.nodes,
))
}
Loading