Skip to content

Commit 2d86b13

Browse files
committed
core,server: changed reponse type for graphman unassign/reassign graphql api
1 parent 6a56efb commit 2d86b13

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 create;
@@ -37,7 +38,7 @@ impl DeploymentMutation {
3738

3839
pause::run(&ctx, &deployment)?;
3940

40-
Ok(EmptyResponse::new(None))
41+
Ok(EmptyResponse::new())
4142
}
4243

4344
/// Resumes a deployment that has been previously paused.
@@ -51,7 +52,7 @@ impl DeploymentMutation {
5152

5253
resume::run(&ctx, &deployment)?;
5354

54-
Ok(EmptyResponse::new(None))
55+
Ok(EmptyResponse::new())
5556
}
5657

5758
/// Pauses a deployment and resumes it after a delay.
@@ -92,13 +93,16 @@ impl DeploymentMutation {
9293
&self,
9394
ctx: &Context<'_>,
9495
deployment: DeploymentSelector,
95-
) -> Result<EmptyResponse> {
96+
) -> Result<Response> {
9697
let ctx = GraphmanContext::new(ctx)?;
9798
let deployment = deployment.try_into()?;
9899

99100
unassign::run(&ctx, &deployment)?;
100101

101-
Ok(EmptyResponse::new(None))
102+
Ok(Response::new(
103+
true,
104+
format!("Unassigned {}", deployment.as_str()),
105+
))
102106
}
103107

104108
/// Assign or reassign a deployment
@@ -107,7 +111,7 @@ impl DeploymentMutation {
107111
ctx: &Context<'_>,
108112
deployment: DeploymentSelector,
109113
node: String,
110-
) -> Result<EmptyResponse> {
114+
) -> Result<Response> {
111115
let ctx = GraphmanContext::new(ctx)?;
112116
let deployment = deployment.try_into()?;
113117
let node = NodeId::new(node.clone()).map_err(|()| anyhow!("illegal node id `{}`", node))?;
@@ -116,9 +120,12 @@ impl DeploymentMutation {
116120
let mirror = catalog::Mirror::primary_only(ctx.primary_pool);
117121
let count = mirror.assignments(&node)?.len();
118122
if count == 1 {
119-
Ok(EmptyResponse::new(Some(format!("warning: this is the only deployment assigned to '{}'. Are you sure it is spelled correctly?",node.as_str()))))
123+
Ok(Response::new(true,format!("warning: this is the only deployment assigned to '{}'. Are you sure it is spelled correctly?",node.as_str())))
120124
} else {
121-
Ok(EmptyResponse::new(None))
125+
Ok(Response::new(
126+
true,
127+
format!("Ressigned {} to {}", deployment.as_str(), node.as_str()),
128+
))
122129
}
123130
}
124131
}

0 commit comments

Comments
 (0)