Skip to content

Commit 07c8b31

Browse files
committed
core,server: changed reponse type for graphman unassign/reassign graphql api
1 parent 3baf78b commit 07c8b31

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

core/graphman/src/commands/deployment/unassign.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ pub fn load_assigned_deployment(
5252
{
5353
Some(_) => Ok(AssignedDeployment { site }),
5454
None => Err(UnassignDeploymentError::AlreadyUnassigned(format!(
55-
"{:?}",
56-
deployment
55+
"{}",
56+
deployment.as_str()
5757
))),
5858
}
5959
}

core/graphman/src/deployment.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ pub enum DeploymentSelector {
3131
All,
3232
}
3333

34+
impl DeploymentSelector {
35+
pub fn as_str(&self) -> String {
36+
match self {
37+
DeploymentSelector::Name(name) => name.clone(),
38+
DeploymentSelector::Subgraph { hash, shard } => {
39+
format!("[Hash:{}, Shard:{:?}]", hash, shard)
40+
}
41+
DeploymentSelector::Schema(schema) => schema.clone(),
42+
DeploymentSelector::All => "All".to_string(),
43+
}
44+
}
45+
}
46+
3447
#[derive(Clone, Debug)]
3548
pub enum DeploymentVersionSelector {
3649
Current,

server/graphman/src/resolvers/deployment_mutation.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use graph_store_postgres::graphman::GraphmanStore;
1111
use crate::entities::DeploymentSelector;
1212
use crate::entities::EmptyResponse;
1313
use crate::entities::ExecutionId;
14+
use crate::entities::Response;
1415
use crate::resolvers::context::GraphmanContext;
1516

1617
mod pause;
@@ -34,7 +35,7 @@ impl DeploymentMutation {
3435

3536
pause::run(&ctx, &deployment)?;
3637

37-
Ok(EmptyResponse::new(None))
38+
Ok(EmptyResponse::new())
3839
}
3940

4041
/// Resumes a deployment that has been previously paused.
@@ -48,7 +49,7 @@ impl DeploymentMutation {
4849

4950
resume::run(&ctx, &deployment)?;
5051

51-
Ok(EmptyResponse::new(None))
52+
Ok(EmptyResponse::new())
5253
}
5354

5455
/// Pauses a deployment and resumes it after a delay.
@@ -75,13 +76,16 @@ impl DeploymentMutation {
7576
&self,
7677
ctx: &Context<'_>,
7778
deployment: DeploymentSelector,
78-
) -> Result<EmptyResponse> {
79+
) -> Result<Response> {
7980
let ctx = GraphmanContext::new(ctx)?;
8081
let deployment = deployment.try_into()?;
8182

8283
unassign::run(&ctx, &deployment)?;
8384

84-
Ok(EmptyResponse::new(None))
85+
Ok(Response::new(
86+
true,
87+
format!("Unassigned {}", deployment.as_str()),
88+
))
8589
}
8690

8791
/// Assign or reassign a deployment
@@ -90,7 +94,7 @@ impl DeploymentMutation {
9094
ctx: &Context<'_>,
9195
deployment: DeploymentSelector,
9296
node: String,
93-
) -> Result<EmptyResponse> {
97+
) -> Result<Response> {
9498
let ctx = GraphmanContext::new(ctx)?;
9599
let deployment = deployment.try_into()?;
96100
let node = NodeId::new(node.clone()).map_err(|()| anyhow!("illegal node id `{}`", node))?;
@@ -99,9 +103,12 @@ impl DeploymentMutation {
99103
let mirror = catalog::Mirror::primary_only(ctx.primary_pool);
100104
let count = mirror.assignments(&node)?.len();
101105
if count == 1 {
102-
Ok(EmptyResponse::new(Some(format!("warning: this is the only deployment assigned to '{}'. Are you sure it is spelled correctly?",node.as_str()))))
106+
Ok(Response::new(true,format!("warning: this is the only deployment assigned to '{}'. Are you sure it is spelled correctly?",node.as_str())))
103107
} else {
104-
Ok(EmptyResponse::new(None))
108+
Ok(Response::new(
109+
true,
110+
format!("Ressigned {} to {}", deployment.as_str(), node.as_str()),
111+
))
105112
}
106113
}
107114
}

0 commit comments

Comments
 (0)