Skip to content

Commit

Permalink
chore: finish wiring OperationCheck error
Browse files Browse the repository at this point in the history
  • Loading branch information
EverlastingBugstopper committed Jul 15, 2021
1 parent 20fd54f commit a16f4f7
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
5 changes: 4 additions & 1 deletion crates/rover-client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ pub enum RoverClientError {
// we nest the CheckResponse here because we want to print the entire response even
// if there were failures
#[error("{}", check_response_error_msg(.check_response))]
OperationCheckFailure { check_response: CheckResponse },
OperationCheckFailure {
graph_ref: GraphRef,
check_response: CheckResponse,
},

/// This error occurs when a user has a malformed Graph Ref
#[error("Graph IDs must be in the format <NAME> or <NAME>@<VARIANT>, where <NAME> can only contain letters, numbers, or the characters `-` or `_`, and must be 64 characters or less. <VARIANT> must be 64 characters or less.")]
Expand Down
8 changes: 4 additions & 4 deletions crates/rover-client/src/operations/graph/check/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ fn get_check_response_from_data(
data: MutationResponseData,
graph_ref: GraphRef,
) -> Result<CheckResponse, RoverClientError> {
let service = data
.service
.ok_or(RoverClientError::GraphNotFound { graph_ref })?;
let service = data.service.ok_or(RoverClientError::GraphNotFound {
graph_ref: graph_ref.clone(),
})?;
let target_url = service.check_schema.target_url;

let diff_to_previous = service.check_schema.diff_to_previous;
Expand All @@ -65,5 +65,5 @@ fn get_check_response_from_data(
num_failures,
};

check_response.check_for_failures()
check_response.check_for_failures(graph_ref)
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn get_check_response_from_data(
changes,
change_severity,
};
check_response.check_for_failures()
check_response.check_for_failures(graph_ref)
} else {
let num_failures = query_composition_errors.len();

Expand Down
7 changes: 6 additions & 1 deletion crates/rover-client/src/shared/check_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::cmp::Ordering;
use std::fmt;
use std::str::FromStr;

use crate::shared::GraphRef;
use crate::RoverClientError;

use serde::Serialize;
Expand Down Expand Up @@ -40,10 +41,14 @@ impl CheckResponse {
}
}

pub fn check_for_failures(&self) -> Result<CheckResponse, RoverClientError> {
pub fn check_for_failures(
&self,
graph_ref: GraphRef,
) -> Result<CheckResponse, RoverClientError> {
match &self.num_failures.cmp(&0) {
Ordering::Equal => Ok(self.clone()),
Ordering::Greater => Err(RoverClientError::OperationCheckFailure {
graph_ref,
check_response: self.clone(),
}),
Ordering::Less => unreachable!("Somehow encountered a negative number of failures."),
Expand Down
4 changes: 4 additions & 0 deletions docs/source/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,7 @@ There are many reasons why you may run into composition errors. This error shoul
Some composition errors are part of normal workflows. For instance, you may need to publish a subgraph that does not compose if you are trying to [migrate an entity or field](https://www.apollographql.com/docs/federation/entities/#migrating-entities-and-fields-advanced).


### E030

This error occurs when an operation check fails. This means that you proposed a schema that would break operations in use by existing clients. You can configure this behavior in the Checks -> Configuration view in [Apollo Studio](https://studio.apollographql.com/), and you can read more about client checks [here](https://www.apollographql.com/docs/studio/schema-checks/).

13 changes: 8 additions & 5 deletions src/error/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,16 @@ impl From<&mut anyhow::Error> for Metadata {
Some(Code::E029),
)
}
RoverClientError::OperationCheckFailure { check_response } => {
RoverClientError::OperationCheckFailure {
graph_ref,
check_response,
} => {
print_check_response(check_response);
(
Some(Suggestion::Adhoc(
"TODO: make a new error code and markdown file linking to client checks".to_string(),
)),
None,
Some(Suggestion::FixOperationsInSchema {
graph_ref: graph_ref.clone(),
}),
Some(Code::E030),
)
}
RoverClientError::SubgraphIntrospectionNotAvailable => {
Expand Down

0 comments on commit a16f4f7

Please sign in to comment.