diff --git a/crates/rover-client/src/query/subgraph/introspect_query.graphql b/crates/rover-client/src/query/subgraph/introspect/introspect_query.graphql similarity index 52% rename from crates/rover-client/src/query/subgraph/introspect_query.graphql rename to crates/rover-client/src/query/subgraph/introspect/introspect_query.graphql index b29c43696..4d6269dfe 100644 --- a/crates/rover-client/src/query/subgraph/introspect_query.graphql +++ b/crates/rover-client/src/query/subgraph/introspect/introspect_query.graphql @@ -1,4 +1,4 @@ -query IntrospectionQuery{ +query SubgraphIntrospectQuery{ _service { sdl } diff --git a/crates/rover-client/src/query/subgraph/introspect_schema.graphql b/crates/rover-client/src/query/subgraph/introspect/introspect_schema.graphql similarity index 100% rename from crates/rover-client/src/query/subgraph/introspect_schema.graphql rename to crates/rover-client/src/query/subgraph/introspect/introspect_schema.graphql diff --git a/crates/rover-client/src/query/subgraph/introspect/mod.rs b/crates/rover-client/src/query/subgraph/introspect/mod.rs new file mode 100644 index 000000000..e16e29777 --- /dev/null +++ b/crates/rover-client/src/query/subgraph/introspect/mod.rs @@ -0,0 +1,5 @@ +pub(crate) mod query_runner; +pub(crate) mod types; + +pub use query_runner::run; +pub use types::{SubgraphIntrospectInput, SubgraphIntrospectResponse}; diff --git a/crates/rover-client/src/query/subgraph/introspect.rs b/crates/rover-client/src/query/subgraph/introspect/query_runner.rs similarity index 57% rename from crates/rover-client/src/query/subgraph/introspect.rs rename to crates/rover-client/src/query/subgraph/introspect/query_runner.rs index 8a2a0b206..a46ce5084 100644 --- a/crates/rover-client/src/query/subgraph/introspect.rs +++ b/crates/rover-client/src/query/subgraph/introspect/query_runner.rs @@ -1,29 +1,25 @@ use crate::blocking::GraphQLClient; +use crate::query::subgraph::introspect::types::*; use crate::RoverClientError; + use graphql_client::*; -use std::collections::HashMap; #[derive(GraphQLQuery)] #[graphql( - query_path = "src/query/subgraph/introspect_query.graphql", - schema_path = "src/query/subgraph/introspect_schema.graphql", + query_path = "src/query/subgraph/introspect/introspect_query.graphql", + schema_path = "src/query/subgraph/introspect/introspect_schema.graphql", response_derives = "PartialEq, Debug, Serialize, Deserialize", deprecated = "warn" )] -pub struct IntrospectionQuery; - -#[derive(Debug, PartialEq)] -pub struct IntrospectionResponse { - pub result: String, -} +pub(crate) struct SubgraphIntrospectQuery; pub fn run( + input: SubgraphIntrospectInput, client: &GraphQLClient, - headers: &HashMap, -) -> Result { - let variables = introspection_query::Variables {}; - let response_data = client.post::(variables, headers); +) -> Result { + let response_data = + client.post::(input.clone().into(), &input.headers); match response_data { Ok(data) => build_response(data), @@ -39,14 +35,12 @@ pub fn run( } } -fn build_response( - data: introspection_query::ResponseData, -) -> Result { +fn build_response(data: QueryResponseData) -> Result { let service_data = data.service.ok_or(RoverClientError::IntrospectionError { msg: "No introspection response available.".to_string(), })?; - Ok(IntrospectionResponse { + Ok(SubgraphIntrospectResponse { result: service_data.sdl, }) } diff --git a/crates/rover-client/src/query/subgraph/introspect/types.rs b/crates/rover-client/src/query/subgraph/introspect/types.rs new file mode 100644 index 000000000..6f3301964 --- /dev/null +++ b/crates/rover-client/src/query/subgraph/introspect/types.rs @@ -0,0 +1,22 @@ +use crate::query::subgraph::introspect::query_runner::subgraph_introspect_query; + +pub(crate) type QueryVariables = subgraph_introspect_query::Variables; +pub(crate) type QueryResponseData = subgraph_introspect_query::ResponseData; + +use std::collections::HashMap; + +#[derive(Debug, Clone, PartialEq)] +pub struct SubgraphIntrospectInput { + pub headers: HashMap, +} + +impl From for QueryVariables { + fn from(_input: SubgraphIntrospectInput) -> Self { + Self {} + } +} + +#[derive(Debug, Clone, PartialEq)] +pub struct SubgraphIntrospectResponse { + pub result: String, +} diff --git a/src/command/subgraph/introspect.rs b/src/command/subgraph/introspect.rs index 4b69876f0..884cfe5c8 100644 --- a/src/command/subgraph/introspect.rs +++ b/src/command/subgraph/introspect.rs @@ -3,7 +3,10 @@ use std::collections::HashMap; use structopt::StructOpt; use url::Url; -use rover_client::{blocking::GraphQLClient, query::subgraph::introspect}; +use rover_client::{ + blocking::GraphQLClient, + query::subgraph::introspect::{self, SubgraphIntrospectInput}, +}; use crate::command::RoverStdout; use crate::utils::parsers::parse_header; @@ -43,7 +46,7 @@ impl Introspect { } } - let introspection_response = introspect::run(&client, &headers)?; + let introspection_response = introspect::run(SubgraphIntrospectInput { headers }, &client)?; Ok(RoverStdout::Introspection(introspection_response.result)) } diff --git a/src/command/supergraph/compose/do_compose.rs b/src/command/supergraph/compose/do_compose.rs index b816c3e7a..d775e627b 100644 --- a/src/command/supergraph/compose/do_compose.rs +++ b/src/command/supergraph/compose/do_compose.rs @@ -6,6 +6,7 @@ use ansi_term::Colour::Red; use camino::Utf8PathBuf; use rover_client::query::subgraph::fetch::SubgraphFetchInput; +use rover_client::query::subgraph::introspect::SubgraphIntrospectInput; use rover_client::{ blocking::GraphQLClient, query::subgraph::{fetch, introspect}, @@ -105,7 +106,12 @@ pub(crate) fn get_subgraph_definitions( // obtain SDL and add it to subgraph_definition. let client = GraphQLClient::new(&subgraph_url.to_string())?; - let introspection_response = introspect::run(&client, &HashMap::new())?; + let introspection_response = introspect::run( + SubgraphIntrospectInput { + headers: HashMap::new(), + }, + &client, + )?; let schema = introspection_response.result; // We don't require a routing_url for this variant of a schema,