Skip to content

Commit 6f6c0fa

Browse files
committed
graphman: add graphman create command to graphql api
1 parent 415005f commit 6f6c0fa

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

server/graphman/src/resolvers/deployment_mutation.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ use std::sync::Arc;
33
use async_graphql::Context;
44
use async_graphql::Object;
55
use async_graphql::Result;
6+
use graph::prelude::SubgraphName;
67
use graph_store_postgres::graphman::GraphmanStore;
78

89
use crate::entities::DeploymentSelector;
910
use crate::entities::EmptyResponse;
1011
use crate::entities::ExecutionId;
1112
use crate::resolvers::context::GraphmanContext;
1213

14+
mod create;
1315
mod pause;
1416
mod restart;
1517
mod resume;
@@ -65,4 +67,12 @@ impl DeploymentMutation {
6567

6668
restart::run_in_background(ctx, store, deployment, delay_seconds).await
6769
}
70+
71+
/// Create a subgraph
72+
pub async fn create(&self, ctx: &Context<'_>, name: String) -> Result<EmptyResponse> {
73+
let ctx = GraphmanContext::new(ctx)?;
74+
75+
create::run(&ctx, &name);
76+
Ok(EmptyResponse::new())
77+
}
6878
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use anyhow::anyhow;
2+
use graph::prelude::SubgraphName;
3+
use graph_store_postgres::command_support::catalog;
4+
use graphman::GraphmanError;
5+
6+
use crate::resolvers::context::GraphmanContext;
7+
8+
pub fn run(ctx: &GraphmanContext, name: &String) -> Result<(), GraphmanError> {
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+
}
19+
};
20+
21+
catalog_conn.create_subgraph(&name);
22+
23+
Ok(())
24+
}

0 commit comments

Comments
 (0)