Skip to content

Commit c1d80dd

Browse files
JakeDawkinslrlna
authored andcommitted
err: introspection on non-fed graphs
1 parent ec56764 commit c1d80dd

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

crates/rover-client/src/error.rs

+3
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,7 @@ pub enum RoverClientError {
129129
/// could not parse the latest version
130130
#[error("Could not get the latest release version")]
131131
UnparseableReleaseVersion,
132+
133+
#[error("This endpoint doesn't support subgraph introspection via the Query._service field")]
134+
SubgraphIntrospectionNotAvailable,
132135
}

crates/rover-client/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub mod introspection;
1616
pub use error::RoverClientError;
1717

1818
/// Module for actually querying studio
19-
#[allow(clippy::upper_case_acronyms)]
2019
pub mod query;
2120

2221
/// Module for getting release info

crates/rover-client/src/query/subgraph/introspect.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,20 @@ pub fn run(
2424
) -> Result<IntrospectionResponse, RoverClientError> {
2525
// let graph = variables.graph_id.clone();
2626
let variables = introspection_query::Variables {};
27-
let response_data = client.post::<IntrospectionQuery>(variables, headers)?;
28-
build_response(response_data)
27+
let response_data = client.post::<IntrospectionQuery>(variables, headers);
28+
match response_data {
29+
Ok(data) => build_response(data),
30+
Err(e) => {
31+
// this is almost definitely a result of a graph not
32+
// being federated, or not matching the federation spec
33+
if e.to_string().contains("Cannot query field") {
34+
Err(RoverClientError::SubgraphIntrospectionNotAvailable)
35+
} else {
36+
Err(e)
37+
}
38+
}
39+
}
40+
// build_response(response_data)
2941
}
3042

3143
fn build_response(

src/error/metadata/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ impl From<&mut anyhow::Error> for Metadata {
5858
RoverClientError::InvalidSeverity => {
5959
(Some(Suggestion::SubmitIssue), Some(Code::E006))
6060
}
61-
RoverClientError::ExpectedFederatedGraph { graph: _ } => {
61+
RoverClientError::SubgraphIntrospectionNotAvailable
62+
| RoverClientError::ExpectedFederatedGraph { graph: _ } => {
6263
(Some(Suggestion::UseFederatedGraph), Some(Code::E007))
6364
}
6465
RoverClientError::NoSchemaForVariant {

src/error/metadata/suggestion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl Display for Suggestion {
6464
format!("Try resolving the composition errors in your subgraph(s), and publish them with the {} command.", Yellow.normal().paint("`rover subgraph publish`"))
6565
}
6666
Suggestion::UseFederatedGraph => {
67-
"Try running the command on a valid federated graph.".to_string()
67+
"Try running the command on a valid federated graph or use the appropriate `rover graph` command instead of `rover subgraph`.".to_string()
6868
}
6969
Suggestion::CheckGraphNameAndAuth => {
7070
"Make sure your graph name is typed correctly, and that your API key is valid. (Are you using the right profile?)".to_string()

0 commit comments

Comments
 (0)