diff --git a/crates/rover-client/src/operations/graph/publish/runner.rs b/crates/rover-client/src/operations/graph/publish/runner.rs index eafc988b9f..e9a807ff0b 100644 --- a/crates/rover-client/src/operations/graph/publish/runner.rs +++ b/crates/rover-client/src/operations/graph/publish/runner.rs @@ -93,7 +93,7 @@ fn build_response( }; Ok(GraphPublishResponse { - schema_hash: hash, + api_schema_hash: hash, change_summary, }) } @@ -207,7 +207,7 @@ mod tests { assert_eq!( output.unwrap(), GraphPublishResponse { - schema_hash: "123456".to_string(), + api_schema_hash: "123456".to_string(), change_summary: ChangeSummary::none(), } ); diff --git a/crates/rover-client/src/operations/graph/publish/types.rs b/crates/rover-client/src/operations/graph/publish/types.rs index 05ff59c1d7..e39c6c2649 100644 --- a/crates/rover-client/src/operations/graph/publish/types.rs +++ b/crates/rover-client/src/operations/graph/publish/types.rs @@ -39,7 +39,7 @@ impl From for GraphPublishContextInput { #[derive(Clone, Serialize, Debug, PartialEq)] pub struct GraphPublishResponse { - pub schema_hash: String, + pub api_schema_hash: String, #[serde(flatten)] pub change_summary: ChangeSummary, } @@ -57,17 +57,15 @@ impl ChangeSummary { type_changes: TypeChanges::none(), } } + + pub(crate) fn is_none(&self) -> bool { + self.field_changes.is_none() && self.type_changes.is_none() + } } impl fmt::Display for ChangeSummary { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - if self.field_changes.additions == 0 - && self.field_changes.removals == 0 - && self.field_changes.edits == 0 - && self.type_changes.additions == 0 - && self.type_changes.removals == 0 - && self.type_changes.edits == 0 - { + if self.is_none() { write!(f, "[No Changes]") } else { write!(f, "[{}, {}]", &self.field_changes, &self.type_changes) @@ -90,6 +88,10 @@ impl FieldChanges { edits: 0, } } + + pub(crate) fn is_none(&self) -> bool { + self.additions == 0 && self.removals == 0 && self.edits == 0 + } } impl fmt::Display for FieldChanges { @@ -117,6 +119,10 @@ impl TypeChanges { edits: 0, } } + + pub(crate) fn is_none(&self) -> bool { + self.additions == 0 && self.removals == 0 && self.edits == 0 + } } impl fmt::Display for TypeChanges { diff --git a/crates/rover-client/src/operations/subgraph/publish/runner.rs b/crates/rover-client/src/operations/subgraph/publish/runner.rs index 1284a7e8f4..800ee06e89 100644 --- a/crates/rover-client/src/operations/subgraph/publish/runner.rs +++ b/crates/rover-client/src/operations/subgraph/publish/runner.rs @@ -72,7 +72,7 @@ fn build_response(publish_response: UpdateResponse) -> SubgraphPublishResponse { .collect(); SubgraphPublishResponse { - schema_hash: match publish_response.composition_config { + api_schema_hash: match publish_response.composition_config { Some(config) => Some(config.schema_hash), None => None, }, @@ -110,7 +110,7 @@ mod tests { assert_eq!( output, SubgraphPublishResponse { - schema_hash: Some("5gf564".to_string()), + api_schema_hash: Some("5gf564".to_string()), composition_errors: vec![ CompositionError { message: "[Accounts] User -> composition error".to_string(), @@ -142,7 +142,7 @@ mod tests { assert_eq!( output, SubgraphPublishResponse { - schema_hash: Some("5gf564".to_string()), + api_schema_hash: Some("5gf564".to_string()), composition_errors: CompositionErrors::new(), supergraph_was_updated: true, subgraph_was_created: true, @@ -169,7 +169,7 @@ mod tests { assert_eq!( output, SubgraphPublishResponse { - schema_hash: None, + api_schema_hash: None, composition_errors: vec![CompositionError { message: "[Accounts] -> Things went really wrong".to_string(), code: None diff --git a/crates/rover-client/src/operations/subgraph/publish/types.rs b/crates/rover-client/src/operations/subgraph/publish/types.rs index d735e306ab..319d4c059d 100644 --- a/crates/rover-client/src/operations/subgraph/publish/types.rs +++ b/crates/rover-client/src/operations/subgraph/publish/types.rs @@ -23,7 +23,7 @@ pub struct SubgraphPublishInput { #[derive(Debug, Clone, Serialize, PartialEq)] pub struct SubgraphPublishResponse { - pub schema_hash: Option, + pub api_schema_hash: Option, // we skip serializing this field as it is merged with "success" // at the top level diff --git a/src/command/output.rs b/src/command/output.rs index 05cc7198bf..ee274b7e32 100644 --- a/src/command/output.rs +++ b/src/command/output.rs @@ -85,10 +85,10 @@ impl RoverOutput { } => { eprintln!( "{}#{} Published successfully {}", - graph_ref, publish_response.schema_hash, publish_response.change_summary + graph_ref, publish_response.api_schema_hash, publish_response.change_summary ); print_one_line_descriptor("Schema Hash"); - print_content(&publish_response.schema_hash); + print_content(&publish_response.api_schema_hash); } RoverOutput::SubgraphPublishResponse { graph_ref, @@ -119,9 +119,7 @@ impl RoverOutput { if !publish_response.composition_errors.is_empty() { let warn_prefix = Red.normal().paint("WARN:"); eprintln!("{} The following composition errors occurred:", warn_prefix,); - for error in publish_response.composition_errors.clone() { - eprintln!("{}", &error); - } + eprintln!("{}", &publish_response.composition_errors); } } RoverOutput::SubgraphDeleteResponse { @@ -139,9 +137,8 @@ impl RoverOutput { Cyan.normal().paint(subgraph), Cyan.normal().paint(graph_ref.to_string()), ); - for error in delete_response.composition_errors.clone() { - eprintln!("{}", &error); - } + + eprintln!("{}", &delete_response.composition_errors); eprintln!("{} This is only a prediction. If the graph changes before confirming, these errors could change.", warn_prefix); } else { eprintln!("{} At the time of checking, there would be no composition errors resulting from the deletion of this subgraph.", warn_prefix); @@ -168,9 +165,7 @@ impl RoverOutput { warn_prefix, ); - for error in delete_response.composition_errors.clone() { - eprintln!("{}", &error); - } + eprintln!("{}", &delete_response.composition_errors); } } } @@ -675,7 +670,7 @@ mod tests { #[test] fn graph_publish_response_json() { let mock_publish_response = GraphPublishResponse { - schema_hash: "123456".to_string(), + api_schema_hash: "123456".to_string(), change_summary: ChangeSummary { field_changes: FieldChanges { additions: 2, @@ -700,7 +695,7 @@ mod tests { let expected_json = json!( { "data": { - "schema_hash": "123456", + "api_schema_hash": "123456", "field_changes": { "additions": 2, "removals": 1, @@ -721,7 +716,7 @@ mod tests { #[test] fn subgraph_publish_success_response_json() { let mock_publish_response = SubgraphPublishResponse { - schema_hash: Some("123456".to_string()), + api_schema_hash: Some("123456".to_string()), composition_errors: CompositionErrors::new(), supergraph_was_updated: true, @@ -739,7 +734,7 @@ mod tests { let expected_json = json!( { "data": { - "schema_hash": "123456", + "api_schema_hash": "123456", "subgraph_was_created": true, "composition_errors": [], "success": true @@ -752,7 +747,7 @@ mod tests { #[test] fn subgraph_publish_failure_response_json() { let mock_publish_response = SubgraphPublishResponse { - schema_hash: None, + api_schema_hash: None, composition_errors: vec![ CompositionError { @@ -779,7 +774,7 @@ mod tests { .into(); let expected_json = json!({ "data": { - "schema_hash": null, + "api_schema_hash": null, "subgraph_was_created": false, "composition_errors": [ {