Skip to content

Commit d27efb2

Browse files
committed
server: add CompletedWithWarnings return type
1 parent 2d86b13 commit d27efb2

File tree

7 files changed

+35
-49
lines changed

7 files changed

+35
-49
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn reassign_deployment(
8282

8383
if changes.is_empty() {
8484
return Err(ReassignDeploymentError::AlreadyAssigned(
85-
deployment.locator.hash.to_string(),
85+
deployment.locator.to_string(),
8686
node.to_string(),
8787
));
8888
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ pub fn load_assigned_deployment(
5151
.map_err(GraphmanError::from)?
5252
{
5353
Some(_) => Ok(AssignedDeployment { site }),
54-
None => Err(UnassignDeploymentError::AlreadyUnassigned(format!(
55-
"{}",
56-
deployment.as_str()
57-
))),
54+
None => Err(UnassignDeploymentError::AlreadyUnassigned(
55+
locator.to_string(),
56+
)),
5857
}
5958
}
6059

core/graphman/src/deployment.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,6 @@ 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-
4734
#[derive(Clone, Debug)]
4835
pub enum DeploymentVersionSelector {
4936
Current,

server/graphman/src/entities/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ mod deployment_version_selector;
99
mod empty_response;
1010
mod execution;
1111
mod execution_id;
12-
mod response;
1312
mod subgraph_health;
13+
mod warning_response;
1414

1515
pub use self::block_hash::BlockHash;
1616
pub use self::block_number::BlockNumber;
@@ -23,5 +23,5 @@ pub use self::deployment_version_selector::DeploymentVersionSelector;
2323
pub use self::empty_response::EmptyResponse;
2424
pub use self::execution::Execution;
2525
pub use self::execution_id::ExecutionId;
26-
pub use self::response::Response;
2726
pub use self::subgraph_health::SubgraphHealth;
27+
pub use self::warning_response::CompletedWithWarnings;

server/graphman/src/entities/response.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use async_graphql::SimpleObject;
2+
3+
#[derive(Clone, Debug, SimpleObject)]
4+
pub struct CompletedWithWarnings {
5+
pub warnings: Vec<String>,
6+
}
7+
8+
impl CompletedWithWarnings {
9+
/// Returns a response with success & message.
10+
pub fn new(msg: Vec<String>) -> Self {
11+
Self { warnings: msg }
12+
}
13+
}

server/graphman/src/resolvers/deployment_mutation.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ use anyhow::anyhow;
44
use async_graphql::Context;
55
use async_graphql::Object;
66
use async_graphql::Result;
7+
use async_graphql::Union;
78
use graph::prelude::NodeId;
89
use graph_store_postgres::command_support::catalog;
910
use graph_store_postgres::graphman::GraphmanStore;
1011

12+
use crate::entities::CompletedWithWarnings;
1113
use crate::entities::DeploymentSelector;
1214
use crate::entities::EmptyResponse;
1315
use crate::entities::ExecutionId;
14-
use crate::entities::Response;
1516
use crate::resolvers::context::GraphmanContext;
1617

1718
mod create;
@@ -24,6 +25,12 @@ mod unassign;
2425

2526
pub struct DeploymentMutation;
2627

28+
#[derive(Clone, Debug, Union)]
29+
pub enum ReassignResponse {
30+
EmptyResponse(EmptyResponse),
31+
CompletedWithWarnings(CompletedWithWarnings),
32+
}
33+
2734
/// Mutations related to one or multiple deployments.
2835
#[Object]
2936
impl DeploymentMutation {
@@ -93,16 +100,13 @@ impl DeploymentMutation {
93100
&self,
94101
ctx: &Context<'_>,
95102
deployment: DeploymentSelector,
96-
) -> Result<Response> {
103+
) -> Result<EmptyResponse> {
97104
let ctx = GraphmanContext::new(ctx)?;
98105
let deployment = deployment.try_into()?;
99106

100107
unassign::run(&ctx, &deployment)?;
101108

102-
Ok(Response::new(
103-
true,
104-
format!("Unassigned {}", deployment.as_str()),
105-
))
109+
Ok(EmptyResponse::new())
106110
}
107111

108112
/// Assign or reassign a deployment
@@ -111,7 +115,7 @@ impl DeploymentMutation {
111115
ctx: &Context<'_>,
112116
deployment: DeploymentSelector,
113117
node: String,
114-
) -> Result<Response> {
118+
) -> Result<ReassignResponse> {
115119
let ctx = GraphmanContext::new(ctx)?;
116120
let deployment = deployment.try_into()?;
117121
let node = NodeId::new(node.clone()).map_err(|()| anyhow!("illegal node id `{}`", node))?;
@@ -120,12 +124,12 @@ impl DeploymentMutation {
120124
let mirror = catalog::Mirror::primary_only(ctx.primary_pool);
121125
let count = mirror.assignments(&node)?.len();
122126
if count == 1 {
123-
Ok(Response::new(true,format!("warning: this is the only deployment assigned to '{}'. Are you sure it is spelled correctly?",node.as_str())))
124-
} else {
125-
Ok(Response::new(
126-
true,
127-
format!("Ressigned {} to {}", deployment.as_str(), node.as_str()),
127+
let warning_msg = format!("warning: this is the only deployment assigned to '{}'. Are you sure it is spelled correctly?",node.as_str());
128+
Ok(ReassignResponse::CompletedWithWarnings(
129+
CompletedWithWarnings::new(vec![warning_msg]),
128130
))
131+
} else {
132+
Ok(ReassignResponse::EmptyResponse(EmptyResponse::new()))
129133
}
130134
}
131135
}

0 commit comments

Comments
 (0)