Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

push -> publish #347

Merged
merged 4 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ rover graph fetch test@cats
rover graph check --schema=./path-to-valid-sdl test@cats
```

1. Push your local graph to Apollo Studio.
1. Publish your local graph to Apollo Studio.

```bash
rover graph push --schema ./path-to-valid-schema test@cats
rover graph publish --schema ./path-to-valid-schema test@cats
```


Expand All @@ -58,7 +58,7 @@ The most common commands from there are:
- rover graph fetch: Fetch a graph schema from the Apollo graph registry
- rover graph check: Check for breaking changes in a local graph schema against a graph schema in the Apollo graph
registry
- rover graph push: Push an updated graph schema to the Apollo graph registry
- rover graph publish: Publish an updated graph schema to the Apollo graph registry

You can open the full documentation for Rover by running:

Expand Down
2 changes: 1 addition & 1 deletion crates/rover-client/src/query/graph/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Timestamp = String;
pub struct CheckSchemaQuery;

/// The main function to be used from this module.
/// This function takes a proposed schema and validates it against a pushed
/// This function takes a proposed schema and validates it against a published
/// schema.
pub fn run(
variables: check_schema_query::Variables,
Expand Down
4 changes: 2 additions & 2 deletions crates/rover-client/src/query/graph/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// "graph fetch" command execution
pub mod fetch;

/// "graph push" command execution
pub mod push;
/// "graph publish" command execution
pub mod publish;

/// "graph check" command exeuction
pub mod check;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mutation PushSchemaMutation(
mutation PublishSchemaMutation(
$variant: String!
$graphId: ID!
$schemaDocument: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,38 @@ use graphql_client::*;
// The paths are relative to the directory where your `Cargo.toml` is located.
// Both json and the GraphQL schema language are supported as sources for the schema
#[graphql(
query_path = "src/query/graph/push.graphql",
query_path = "src/query/graph/publish.graphql",
schema_path = ".schema/schema.graphql",
response_derives = "PartialEq, Debug, Serialize, Deserialize",
deprecated = "warn"
)]
/// This struct is used to generate the module containing `Variables` and
/// `ResponseData` structs.
/// Snake case of this name is the mod name. i.e. stash_schema_query
pub struct PushSchemaMutation;
pub struct PublishSchemaMutation;

#[derive(Debug, PartialEq)]
pub struct PushResponse {
pub struct PublishResponse {
pub schema_hash: String,
pub change_summary: String,
}

/// Returns a message from apollo studio about the status of the update, and
/// a sha256 hash of the schema to be used with `schema publish`
pub fn run(
variables: push_schema_mutation::Variables,
variables: publish_schema_mutation::Variables,
client: &StudioClient,
) -> Result<PushResponse, RoverClientError> {
) -> Result<PublishResponse, RoverClientError> {
let graph = variables.graph_id.clone();
let data = client.post::<PushSchemaMutation>(variables)?;
let push_response = get_push_response_from_data(data, graph)?;
build_response(push_response)
let data = client.post::<PublishSchemaMutation>(variables)?;
let publish_response = get_publish_response_from_data(data, graph)?;
build_response(publish_response)
}

fn get_push_response_from_data(
data: push_schema_mutation::ResponseData,
fn get_publish_response_from_data(
data: publish_schema_mutation::ResponseData,
graph: String,
) -> Result<push_schema_mutation::PushSchemaMutationServiceUploadSchema, RoverClientError> {
) -> Result<publish_schema_mutation::PublishSchemaMutationServiceUploadSchema, RoverClientError> {
// then, from the response data, get .service?.upload_schema?
let service_data = match data.service {
Some(data) => data,
Expand All @@ -54,43 +54,47 @@ fn get_push_response_from_data(
}

fn build_response(
push_response: push_schema_mutation::PushSchemaMutationServiceUploadSchema,
) -> Result<PushResponse, RoverClientError> {
if !push_response.success {
let msg = format!("Schema upload failed with error: {}", push_response.message);
publish_response: publish_schema_mutation::PublishSchemaMutationServiceUploadSchema,
) -> Result<PublishResponse, RoverClientError> {
if !publish_response.success {
let msg = format!(
"Schema upload failed with error: {}",
publish_response.message
);
return Err(RoverClientError::AdhocError { msg });
}

let hash = match &push_response.tag {
let hash = match &publish_response.tag {
// we only want to print the first 6 chars of a hash
Some(tag_data) => tag_data.schema.hash.clone()[..6].to_string(),
None => {
let msg = format!(
"No data in response from schema push. Failed with message: {}",
push_response.message
"No data in response from schema publish. Failed with message: {}",
publish_response.message
);
return Err(RoverClientError::AdhocError { msg });
}
};

// If you push the exact same schema as is currently published,
// If you publish the exact same schema as is currently published,
// the response CODE is NO_CHANGES but under the result diff,
// it gives you the diff for that hash (i.e., the first time it was pushed)
// it gives you the diff for that hash (i.e., the first time it was published)
// which very well may have changes. For this, we'll just look at the code
// first and handle the response as if there was `None` for the diff
let change_summary = if push_response.code == "NO_CHANGES" {
let change_summary = if publish_response.code == "NO_CHANGES" {
build_change_summary(None)
} else {
build_change_summary(push_response.tag.unwrap().diff_to_previous)
build_change_summary(publish_response.tag.unwrap().diff_to_previous)
};

Ok(PushResponse {
Ok(PublishResponse {
schema_hash: hash,
change_summary,
})
}

type ChangeDiff = push_schema_mutation::PushSchemaMutationServiceUploadSchemaTagDiffToPrevious;
type ChangeDiff =
publish_schema_mutation::PublishSchemaMutationServiceUploadSchemaTagDiffToPrevious;

/// builds a string-representation of the diff between two schemas
/// e.g. ` [Fields: +2 -1 △0, Types: +4 -0 △7]` or `[No Changes]`
Expand Down Expand Up @@ -118,12 +122,12 @@ mod tests {
use serde_json::json;

#[test]
fn get_push_response_from_data_gets_data() {
fn get_publish_response_from_data_gets_data() {
let json_response = json!({
"service": {
"uploadSchema": {
"code": "IT_WERK",
"message": "it really do be pushed",
"message": "it really do be published",
"success": true,
"tag": {
"variant": { "name": "current" },
Expand All @@ -132,25 +136,25 @@ mod tests {
}
}
});
let data: push_schema_mutation::ResponseData =
let data: publish_schema_mutation::ResponseData =
serde_json::from_value(json_response).unwrap();
let output = get_push_response_from_data(data, "mygraph".to_string());
let output = get_publish_response_from_data(data, "mygraph".to_string());

assert!(output.is_ok());
assert_eq!(
output.unwrap(),
push_schema_mutation::PushSchemaMutationServiceUploadSchema {
publish_schema_mutation::PublishSchemaMutationServiceUploadSchema {
code: "IT_WERK".to_string(),
message: "it really do be pushed".to_string(),
message: "it really do be published".to_string(),
success: true,
tag: Some(
push_schema_mutation::PushSchemaMutationServiceUploadSchemaTag {
publish_schema_mutation::PublishSchemaMutationServiceUploadSchemaTag {
variant:
push_schema_mutation::PushSchemaMutationServiceUploadSchemaTagVariant {
publish_schema_mutation::PublishSchemaMutationServiceUploadSchemaTagVariant {
name: "current".to_string()
},
schema:
push_schema_mutation::PushSchemaMutationServiceUploadSchemaTagSchema {
publish_schema_mutation::PublishSchemaMutationServiceUploadSchemaTagSchema {
hash: "123456".to_string()
},
diff_to_previous: None,
Expand All @@ -161,25 +165,25 @@ mod tests {
}

#[test]
fn get_push_response_from_data_errs_with_no_service() {
fn get_publish_response_from_data_errs_with_no_service() {
let json_response = json!({ "service": null });
let data: push_schema_mutation::ResponseData =
let data: publish_schema_mutation::ResponseData =
serde_json::from_value(json_response).unwrap();
let output = get_push_response_from_data(data, "mygraph".to_string());
let output = get_publish_response_from_data(data, "mygraph".to_string());

assert!(output.is_err());
}

#[test]
fn get_push_response_from_data_errs_with_no_upload_response() {
fn get_publish_response_from_data_errs_with_no_upload_response() {
let json_response = json!({
"service": {
"uploadSchema": null
}
});
let data: push_schema_mutation::ResponseData =
let data: publish_schema_mutation::ResponseData =
serde_json::from_value(json_response).unwrap();
let output = get_push_response_from_data(data, "mygraph".to_string());
let output = get_publish_response_from_data(data, "mygraph".to_string());

assert!(output.is_err());
}
Expand All @@ -188,21 +192,21 @@ mod tests {
fn build_response_struct_from_success() {
let json_response = json!({
"code": "IT_WERK",
"message": "it really do be pushed",
"message": "it really do be published",
"success": true,
"tag": {
"variant": { "name": "current" },
"schema": { "hash": "123456" }
}
});
let update_response: push_schema_mutation::PushSchemaMutationServiceUploadSchema =
let update_response: publish_schema_mutation::PublishSchemaMutationServiceUploadSchema =
serde_json::from_value(json_response).unwrap();
let output = build_response(update_response);

assert!(output.is_ok());
assert_eq!(
output.unwrap(),
PushResponse {
PublishResponse {
schema_hash: "123456".to_string(),
change_summary: "[No Changes]".to_string(),
}
Expand All @@ -217,7 +221,7 @@ mod tests {
"success": false,
"tag": null
});
let update_response: push_schema_mutation::PushSchemaMutationServiceUploadSchema =
let update_response: publish_schema_mutation::PublishSchemaMutationServiceUploadSchema =
serde_json::from_value(json_response).unwrap();
let output = build_response(update_response);

Expand All @@ -232,7 +236,7 @@ mod tests {
"success": true,
"tag": null
});
let update_response: push_schema_mutation::PushSchemaMutationServiceUploadSchema =
let update_response: publish_schema_mutation::PublishSchemaMutationServiceUploadSchema =
serde_json::from_value(json_response).unwrap();
let output = build_response(update_response);

Expand Down
2 changes: 1 addition & 1 deletion crates/rover-client/src/query/subgraph/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Timestamp = String;
pub struct CheckPartialSchemaQuery;

/// The main function to be used from this module.
/// This function takes a proposed schema and validates it against a pushed
/// This function takes a proposed schema and validates it against a published
/// schema.
pub fn run(
variables: check_partial_schema_query::Variables,
Expand Down
4 changes: 2 additions & 2 deletions crates/rover-client/src/query/subgraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ pub mod check;
/// "subgraph fetch" command execution
pub mod fetch;

/// "subgraph push" command execution
pub mod push;
/// "subgraph publish" command execution
pub mod publish;

/// "subgraph list"
pub mod list;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mutation PushPartialSchemaMutation(
mutation PublishPartialSchemaMutation(
$graphId: ID!
$graphVariant: String!
$name: String!
Expand Down
Loading