Skip to content

Commit

Permalink
chore: rename schema_hash to api_schema_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
EverlastingBugstopper committed Jul 22, 2021
1 parent 38d3a9d commit 1797045
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 32 deletions.
4 changes: 2 additions & 2 deletions crates/rover-client/src/operations/graph/publish/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn build_response(
};

Ok(GraphPublishResponse {
schema_hash: hash,
api_schema_hash: hash,
change_summary,
})
}
Expand Down Expand Up @@ -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(),
}
);
Expand Down
22 changes: 14 additions & 8 deletions crates/rover-client/src/operations/graph/publish/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl From<GitContext> 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,
}
Expand All @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions crates/rover-client/src/operations/subgraph/publish/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct SubgraphPublishInput {

#[derive(Debug, Clone, Serialize, PartialEq)]
pub struct SubgraphPublishResponse {
pub schema_hash: Option<String>,
pub api_schema_hash: Option<String>,

// we skip serializing this field as it is merged with "success"
// at the top level
Expand Down
29 changes: 12 additions & 17 deletions src/command/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand All @@ -168,9 +165,7 @@ impl RoverOutput {
warn_prefix,
);

for error in delete_response.composition_errors.clone() {
eprintln!("{}", &error);
}
eprintln!("{}", &delete_response.composition_errors);
}
}
}
Expand Down Expand Up @@ -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,
Expand All @@ -700,7 +695,7 @@ mod tests {
let expected_json = json!(
{
"data": {
"schema_hash": "123456",
"api_schema_hash": "123456",
"field_changes": {
"additions": 2,
"removals": 1,
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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": [
{
Expand Down

0 comments on commit 1797045

Please sign in to comment.