From 59da2ddd027cd8509a608d66810228663078040d Mon Sep 17 00:00:00 2001 From: shiyasmohd Date: Sat, 28 Dec 2024 07:31:25 +0530 Subject: [PATCH 1/2] node: fix subgraph creation logic to prevent errors when subgraph does not exist --- node/src/manager/commands/deploy.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/node/src/manager/commands/deploy.rs b/node/src/manager/commands/deploy.rs index 5fa187615a5..e8ed3bcc711 100644 --- a/node/src/manager/commands/deploy.rs +++ b/node/src/manager/commands/deploy.rs @@ -80,20 +80,22 @@ pub async fn run( _ => bail!("The `name` must be a valid subgraph name"), }; - if create { - println!("Creating subgraph `{}`", name); - let subgraph_name = - SubgraphName::new(name.clone()).map_err(|_| anyhow!("Invalid subgraph name"))?; + let subgraph_name = + SubgraphName::new(name.clone()).map_err(|_| anyhow!("Invalid subgraph name"))?; - let exists = subgraph_store.subgraph_exists(&subgraph_name)?; + let exists = subgraph_store.subgraph_exists(&subgraph_name)?; - if exists { - bail!("Subgraph with name `{}` already exists", name); - } + if create && !exists { + println!("Creating subgraph `{}`", name); // Send the subgraph_create request send_create_request(&name, &url).await?; println!("Subgraph `{}` created", name); + } else if !create && !exists { + bail!( + "Subgraph with name `{}` does not exist. Use the `--create` flag to create it", + name + ); } // Send the subgraph_deploy request From 28c1544ed097a0fab51113951cd80c933005f3c5 Mon Sep 17 00:00:00 2001 From: shiyasmohd Date: Thu, 27 Mar 2025 06:49:43 +0530 Subject: [PATCH 2/2] node: remove create flag from graphman deploy --- node/src/bin/manager.rs | 7 +------ node/src/manager/commands/deploy.rs | 8 +------- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/node/src/bin/manager.rs b/node/src/bin/manager.rs index afc09403357..4de4a13a8cb 100644 --- a/node/src/bin/manager.rs +++ b/node/src/bin/manager.rs @@ -359,10 +359,6 @@ pub enum Command { /// The url of the graph-node #[clap(long, short, default_value = "http://localhost:8020")] url: String, - - /// Create the subgraph name if it does not exist - #[clap(long, short)] - create: bool, }, } @@ -1637,12 +1633,11 @@ async fn main() -> anyhow::Result<()> { deployment, name, url, - create, } => { let store = ctx.store(); let subgraph_store = store.subgraph_store(); - commands::deploy::run(subgraph_store, deployment, name, url, create).await + commands::deploy::run(subgraph_store, deployment, name, url).await } } } diff --git a/node/src/manager/commands/deploy.rs b/node/src/manager/commands/deploy.rs index e8ed3bcc711..34391e94544 100644 --- a/node/src/manager/commands/deploy.rs +++ b/node/src/manager/commands/deploy.rs @@ -68,7 +68,6 @@ pub async fn run( deployment: DeploymentSearch, search: DeploymentSearch, url: String, - create: bool, ) -> Result<()> { let hash = match deployment { DeploymentSearch::Hash { hash, shard: _ } => hash, @@ -85,17 +84,12 @@ pub async fn run( let exists = subgraph_store.subgraph_exists(&subgraph_name)?; - if create && !exists { + if !exists { println!("Creating subgraph `{}`", name); // Send the subgraph_create request send_create_request(&name, &url).await?; println!("Subgraph `{}` created", name); - } else if !create && !exists { - bail!( - "Subgraph with name `{}` does not exist. Use the `--create` flag to create it", - name - ); } // Send the subgraph_deploy request