Skip to content

Commit

Permalink
Show a better message when a subgraph is published with no changes (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bonnici authored Oct 5, 2023
1 parent 981e9b8 commit 69e5e59
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/rover-client/.schema/hash.id

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/rover-client/.schema/last_run.uuid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions crates/rover-client/.schema/schema.graphql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mutation SubgraphPublishMutation(
}
didUpdateGateway: updatedGateway
serviceWasCreated: wasCreated
serviceWasUpdated: wasUpdated
launchCliCopy
launchUrl
}
Expand Down
41 changes: 38 additions & 3 deletions crates/rover-client/src/operations/subgraph/publish/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ fn build_response(publish_response: UpdateResponse) -> SubgraphPublishResponse {
},
supergraph_was_updated: publish_response.did_update_gateway,
subgraph_was_created: publish_response.service_was_created,
subgraph_was_updated: publish_response.service_was_updated,
build_errors,
launch_cli_copy: publish_response.launch_cli_copy,
launch_url: publish_response.launch_url,
Expand All @@ -134,7 +135,8 @@ mod tests {
}
],
"didUpdateGateway": false,
"serviceWasCreated": true
"serviceWasCreated": true,
"serviceWasUpdated": true
});
let update_response: UpdateResponse = serde_json::from_value(json_response).unwrap();
let output = build_response(update_response);
Expand All @@ -158,6 +160,7 @@ mod tests {
.into(),
supergraph_was_updated: false,
subgraph_was_created: true,
subgraph_was_updated: true,
launch_url: None,
launch_cli_copy: None,
}
Expand All @@ -170,7 +173,8 @@ mod tests {
"compositionConfig": { "schemaHash": "5gf564" },
"errors": [],
"didUpdateGateway": true,
"serviceWasCreated": true
"serviceWasCreated": true,
"serviceWasUpdated": true
});
let update_response: UpdateResponse = serde_json::from_value(json_response).unwrap();
let output = build_response(update_response);
Expand All @@ -182,6 +186,7 @@ mod tests {
build_errors: BuildErrors::new(),
supergraph_was_updated: true,
subgraph_was_created: true,
subgraph_was_updated: true,
launch_url: None,
launch_cli_copy: None,
}
Expand All @@ -199,7 +204,8 @@ mod tests {
"code": null
}],
"didUpdateGateway": false,
"serviceWasCreated": false
"serviceWasCreated": false,
"serviceWasUpdated": true
});
let update_response: UpdateResponse = serde_json::from_value(json_response).unwrap();
let output = build_response(update_response);
Expand All @@ -216,6 +222,7 @@ mod tests {
.into(),
supergraph_was_updated: false,
subgraph_was_created: false,
subgraph_was_updated: true,
launch_url: None,
launch_cli_copy: None,
}
Expand All @@ -229,6 +236,7 @@ mod tests {
"errors": [],
"didUpdateGateway": true,
"serviceWasCreated": true,
"serviceWasUpdated": true,
"launchUrl": "test.com/launchurl",
"launchCliCopy": "You can monitor this launch in Apollo Studio: test.com/launchurl",
});
Expand All @@ -242,11 +250,38 @@ mod tests {
build_errors: BuildErrors::new(),
supergraph_was_updated: true,
subgraph_was_created: true,
subgraph_was_updated: true,
launch_url: Some("test.com/launchurl".to_string()),
launch_cli_copy: Some(
"You can monitor this launch in Apollo Studio: test.com/launchurl".to_string()
),
}
);
}

#[test]
fn build_response_works_with_unmodified_subgraph() {
let json_response = json!({
"compositionConfig": { "schemaHash": "5gf564" },
"errors": [],
"didUpdateGateway": false,
"serviceWasCreated": false,
"serviceWasUpdated": false
});
let update_response: UpdateResponse = serde_json::from_value(json_response).unwrap();
let output = build_response(update_response);

assert_eq!(
output,
SubgraphPublishResponse {
api_schema_hash: Some("5gf564".to_string()),
build_errors: BuildErrors::new(),
supergraph_was_updated: false,
subgraph_was_created: false,
subgraph_was_updated: false,
launch_url: None,
launch_cli_copy: None,
}
);
}
}
2 changes: 2 additions & 0 deletions crates/rover-client/src/operations/subgraph/publish/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub struct SubgraphPublishResponse {

pub subgraph_was_created: bool,

pub subgraph_was_updated: bool,

#[serde(skip_serializing)]
pub build_errors: BuildErrors,

Expand Down
2 changes: 2 additions & 0 deletions docs/source/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ Here's an example success output for `rover subgraph publish`:
"api_schema_hash": "a1bc0d",
"supergraph_was_updated": true,
"subgraph_was_created": true,
"subgraph_was_updated": true,
"success": true
},
"error": null
Expand All @@ -211,6 +212,7 @@ And here's an example error output:
"data": {
"api_schema_hash": null,
"subgraph_was_created": false,
"subgraph_was_updated": true,
"supergraph_was_updated": false,
"success": true
},
Expand Down
48 changes: 47 additions & 1 deletion src/command/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,13 @@ impl RoverOutput {
subgraph,
graph_ref
)?;
} else {
} else if publish_response.subgraph_was_updated {
stderrln!("The '{}' subgraph in '{}' was updated", subgraph, graph_ref)?;
} else {
stderrln!(
"The '{}' subgraph was NOT updated because no changes were detected",
subgraph
)?;
}

if publish_response.supergraph_was_updated {
Expand Down Expand Up @@ -1183,6 +1188,7 @@ mod tests {
build_errors: BuildErrors::new(),
supergraph_was_updated: true,
subgraph_was_created: true,
subgraph_was_updated: true,
launch_url: Some("test.com/launchurl".to_string()),
launch_cli_copy: Some(
"You can monitor this launch in Apollo Studio: test.com/launchurl".to_string(),
Expand All @@ -1204,6 +1210,7 @@ mod tests {
"api_schema_hash": "123456",
"supergraph_was_updated": true,
"subgraph_was_created": true,
"subgraph_was_updated": true,
"success": true,
"launch_url": "test.com/launchurl",
"launch_cli_copy": "You can monitor this launch in Apollo Studio: test.com/launchurl",
Expand Down Expand Up @@ -1233,6 +1240,7 @@ mod tests {
.into(),
supergraph_was_updated: false,
subgraph_was_created: false,
subgraph_was_updated: true,
launch_url: None,
launch_cli_copy: None,
};
Expand All @@ -1251,6 +1259,7 @@ mod tests {
"data": {
"api_schema_hash": null,
"subgraph_was_created": false,
"subgraph_was_updated": true,
"supergraph_was_updated": false,
"success": true,
"launch_url": null,
Expand Down Expand Up @@ -1280,6 +1289,43 @@ mod tests {
assert_json_eq!(expected_json, actual_json);
}

#[test]
fn subgraph_publish_unchanged_response_json() {
let mock_publish_response = SubgraphPublishResponse {
api_schema_hash: Some("123456".to_string()),
build_errors: BuildErrors::new(),
supergraph_was_updated: false,
subgraph_was_created: false,
subgraph_was_updated: false,
launch_url: None,
launch_cli_copy: None,
};
let actual_json: JsonOutput = RoverOutput::SubgraphPublishResponse {
graph_ref: GraphRef {
name: "graph".to_string(),
variant: "variant".to_string(),
},
subgraph: "subgraph".to_string(),
publish_response: mock_publish_response,
}
.into();
let expected_json = json!(
{
"json_version": "1",
"data": {
"api_schema_hash": "123456",
"supergraph_was_updated": false,
"subgraph_was_created": false,
"subgraph_was_updated": false,
"success": true,
"launch_url": null,
"launch_cli_copy": null,
},
"error": null
});
assert_json_eq!(expected_json, actual_json);
}

#[test]
fn profiles_json() {
let mock_profiles = vec!["default".to_string(), "staging".to_string()];
Expand Down

0 comments on commit 69e5e59

Please sign in to comment.