Skip to content

Commit

Permalink
err: introspection on non-fed graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeDawkins committed Apr 20, 2021
1 parent 42a3809 commit 2ca3b27
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions crates/rover-client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,7 @@ pub enum RoverClientError {
/// could not parse the latest version
#[error("Could not get the latest release version")]
UnparseableReleaseVersion,

#[error("This endpoint doesn't support subgraph introspection via the Query._service field")]
SubgraphIntrospectionNotAvailable,
}
1 change: 0 additions & 1 deletion crates/rover-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub mod introspection;
pub use error::RoverClientError;

/// Module for actually querying studio
#[allow(clippy::upper_case_acronyms)]
pub mod query;

/// Module for getting release info
Expand Down
16 changes: 14 additions & 2 deletions crates/rover-client/src/query/subgraph/introspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,20 @@ pub fn run(
) -> Result<IntrospectionResponse, RoverClientError> {
// let graph = variables.graph_id.clone();
let variables = introspection_query::Variables {};
let response_data = client.post::<IntrospectionQuery>(variables, headers)?;
build_response(response_data)
let response_data = client.post::<IntrospectionQuery>(variables, headers);
match response_data {
Ok(data) => build_response(data),
Err(e) => {
// this is almost definitely a result of a graph not
// being federated, or not matching the federation spec
if e.to_string().contains("Cannot query field") {
Err(RoverClientError::SubgraphIntrospectionNotAvailable)
} else {
Err(e)
}
}
}
// build_response(response_data)
}

fn build_response(
Expand Down
3 changes: 2 additions & 1 deletion src/error/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ impl From<&mut anyhow::Error> for Metadata {
| RoverClientError::SendRequest(_)
| RoverClientError::MalformedResponse { null_field: _ }
| RoverClientError::InvalidSeverity => (Some(Suggestion::SubmitIssue), None),
RoverClientError::ExpectedFederatedGraph { graph: _ } => {
RoverClientError::SubgraphIntrospectionNotAvailable
| RoverClientError::ExpectedFederatedGraph { graph: _ } => {
(Some(Suggestion::UseFederatedGraph), None)
}
RoverClientError::NoSchemaForVariant {
Expand Down
2 changes: 1 addition & 1 deletion src/error/metadata/suggestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Display for Suggestion {
)
}
Suggestion::UseFederatedGraph => {
"Try running the command on a valid federated graph.".to_string()
"Try running the command on a valid federated graph or use the appropriate `rover graph` command instead of `rover subgraph`.".to_string()
}
Suggestion::CheckGraphNameAndAuth => {
"Make sure your graph name is typed correctly, and that your API key is valid. (Are you using the right profile?)".to_string()
Expand Down

0 comments on commit 2ca3b27

Please sign in to comment.