Skip to content

Commit d79d8d1

Browse files
committed
graphman: add graphman remove command to graphql api
1 parent 6f6c0fa commit d79d8d1

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

server/graphman/src/resolvers/deployment_mutation.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::sync::Arc;
33
use async_graphql::Context;
44
use async_graphql::Object;
55
use async_graphql::Result;
6-
use graph::prelude::SubgraphName;
76
use graph_store_postgres::graphman::GraphmanStore;
87

98
use crate::entities::DeploymentSelector;
@@ -13,6 +12,7 @@ use crate::resolvers::context::GraphmanContext;
1312

1413
mod create;
1514
mod pause;
15+
mod remove;
1616
mod restart;
1717
mod resume;
1818

@@ -71,8 +71,14 @@ impl DeploymentMutation {
7171
/// Create a subgraph
7272
pub async fn create(&self, ctx: &Context<'_>, name: String) -> Result<EmptyResponse> {
7373
let ctx = GraphmanContext::new(ctx)?;
74+
create::run(&ctx, &name)?;
75+
Ok(EmptyResponse::new())
76+
}
7477

75-
create::run(&ctx, &name);
78+
/// Remove a subgraph
79+
pub async fn remove(&self, ctx: &Context<'_>, name: String) -> Result<EmptyResponse> {
80+
let ctx = GraphmanContext::new(ctx)?;
81+
remove::run(&ctx, &name)?;
7682
Ok(EmptyResponse::new())
7783
}
7884
}
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
use crate::resolvers::context::GraphmanContext;
12
use anyhow::anyhow;
3+
use async_graphql::Result;
24
use graph::prelude::SubgraphName;
35
use graph_store_postgres::command_support::catalog;
46
use graphman::GraphmanError;
57

6-
use crate::resolvers::context::GraphmanContext;
7-
8-
pub fn run(ctx: &GraphmanContext, name: &String) -> Result<(), GraphmanError> {
8+
pub fn run(ctx: &GraphmanContext, name: &String) -> Result<()> {
99
let primary_pool = ctx.primary_pool.get().map_err(GraphmanError::from)?;
1010
let mut catalog_conn = catalog::Connection::new(primary_pool);
1111

@@ -14,11 +14,12 @@ pub fn run(ctx: &GraphmanContext, name: &String) -> Result<(), GraphmanError> {
1414
Err(_) => {
1515
return Err(GraphmanError::Store(anyhow!(
1616
"Subgraph name must contain only a-z, A-Z, 0-9, '-' and '_'"
17-
)));
17+
))
18+
.try_into()?)
1819
}
1920
};
2021

21-
catalog_conn.create_subgraph(&name);
22+
catalog_conn.create_subgraph(&name)?;
2223

2324
Ok(())
2425
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use crate::resolvers::context::GraphmanContext;
2+
use anyhow::anyhow;
3+
use async_graphql::Result;
4+
use graph::prelude::{StoreEvent, SubgraphName};
5+
use graph_store_postgres::command_support::catalog;
6+
use graphman::GraphmanError;
7+
8+
pub fn run(ctx: &GraphmanContext, name: &String) -> Result<()> {
9+
let primary_pool = ctx.primary_pool.get().map_err(GraphmanError::from)?;
10+
let mut catalog_conn = catalog::Connection::new(primary_pool);
11+
12+
let name = match SubgraphName::new(name) {
13+
Ok(name) => name,
14+
Err(_) => {
15+
return Err(GraphmanError::Store(anyhow!(
16+
"Subgraph name must contain only a-z, A-Z, 0-9, '-' and '_'"
17+
))
18+
.try_into()?)
19+
}
20+
};
21+
22+
let changes = catalog_conn.remove_subgraph(name)?;
23+
catalog_conn.send_store_event(&ctx.notification_sender, &StoreEvent::new(changes))?;
24+
25+
Ok(())
26+
}

0 commit comments

Comments
 (0)