Skip to content

Commit ea26d4d

Browse files
chore: refactor subgraph introspect
1 parent 02a8e14 commit ea26d4d

File tree

7 files changed

+51
-21
lines changed

7 files changed

+51
-21
lines changed

crates/rover-client/src/query/subgraph/introspect_query.graphql crates/rover-client/src/query/subgraph/introspect/introspect_query.graphql

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
query IntrospectionQuery{
1+
query SubgraphIntrospectQuery{
22
_service {
33
sdl
44
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub(crate) mod query_runner;
2+
pub(crate) mod types;
3+
4+
pub use query_runner::run;
5+
pub use types::{SubgraphIntrospectInput, SubgraphIntrospectResponse};
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
11
use crate::blocking::GraphQLClient;
2+
use crate::query::subgraph::introspect::types::*;
23
use crate::RoverClientError;
4+
35
use graphql_client::*;
4-
use std::collections::HashMap;
56

67
#[derive(GraphQLQuery)]
78
#[graphql(
8-
query_path = "src/query/subgraph/introspect_query.graphql",
9-
schema_path = "src/query/subgraph/introspect_schema.graphql",
9+
query_path = "src/query/subgraph/introspect/introspect_query.graphql",
10+
schema_path = "src/query/subgraph/introspect/introspect_schema.graphql",
1011
response_derives = "PartialEq, Debug, Serialize, Deserialize",
1112
deprecated = "warn"
1213
)]
1314

14-
pub struct IntrospectionQuery;
15-
16-
#[derive(Debug, PartialEq)]
17-
pub struct IntrospectionResponse {
18-
pub result: String,
19-
}
15+
pub(crate) struct SubgraphIntrospectQuery;
2016

2117
pub fn run(
18+
input: SubgraphIntrospectInput,
2219
client: &GraphQLClient,
23-
headers: &HashMap<String, String>,
24-
) -> Result<IntrospectionResponse, RoverClientError> {
25-
let variables = introspection_query::Variables {};
26-
let response_data = client.post::<IntrospectionQuery>(variables, headers);
20+
) -> Result<SubgraphIntrospectResponse, RoverClientError> {
21+
let response_data =
22+
client.post::<SubgraphIntrospectQuery>(input.clone().into(), &input.headers);
2723

2824
match response_data {
2925
Ok(data) => build_response(data),
@@ -39,14 +35,12 @@ pub fn run(
3935
}
4036
}
4137

42-
fn build_response(
43-
data: introspection_query::ResponseData,
44-
) -> Result<IntrospectionResponse, RoverClientError> {
38+
fn build_response(data: QueryResponseData) -> Result<SubgraphIntrospectResponse, RoverClientError> {
4539
let service_data = data.service.ok_or(RoverClientError::IntrospectionError {
4640
msg: "No introspection response available.".to_string(),
4741
})?;
4842

49-
Ok(IntrospectionResponse {
43+
Ok(SubgraphIntrospectResponse {
5044
result: service_data.sdl,
5145
})
5246
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use crate::query::subgraph::introspect::query_runner::subgraph_introspect_query;
2+
3+
pub(crate) type QueryVariables = subgraph_introspect_query::Variables;
4+
pub(crate) type QueryResponseData = subgraph_introspect_query::ResponseData;
5+
6+
use std::collections::HashMap;
7+
8+
#[derive(Debug, Clone, PartialEq)]
9+
pub struct SubgraphIntrospectInput {
10+
pub headers: HashMap<String, String>,
11+
}
12+
13+
impl From<SubgraphIntrospectInput> for QueryVariables {
14+
fn from(_input: SubgraphIntrospectInput) -> Self {
15+
Self {}
16+
}
17+
}
18+
19+
#[derive(Debug, Clone, PartialEq)]
20+
pub struct SubgraphIntrospectResponse {
21+
pub result: String,
22+
}

src/command/subgraph/introspect.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ use std::collections::HashMap;
33
use structopt::StructOpt;
44
use url::Url;
55

6-
use rover_client::{blocking::GraphQLClient, query::subgraph::introspect};
6+
use rover_client::{
7+
blocking::GraphQLClient,
8+
query::subgraph::introspect::{self, SubgraphIntrospectInput},
9+
};
710

811
use crate::command::RoverStdout;
912
use crate::utils::parsers::parse_header;
@@ -43,7 +46,7 @@ impl Introspect {
4346
}
4447
}
4548

46-
let introspection_response = introspect::run(&client, &headers)?;
49+
let introspection_response = introspect::run(SubgraphIntrospectInput { headers }, &client)?;
4750

4851
Ok(RoverStdout::Introspection(introspection_response.result))
4952
}

src/command/supergraph/compose/do_compose.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use ansi_term::Colour::Red;
66
use camino::Utf8PathBuf;
77

88
use rover_client::query::subgraph::fetch::SubgraphFetchInput;
9+
use rover_client::query::subgraph::introspect::SubgraphIntrospectInput;
910
use rover_client::{
1011
blocking::GraphQLClient,
1112
query::subgraph::{fetch, introspect},
@@ -105,7 +106,12 @@ pub(crate) fn get_subgraph_definitions(
105106
// obtain SDL and add it to subgraph_definition.
106107
let client = GraphQLClient::new(&subgraph_url.to_string())?;
107108

108-
let introspection_response = introspect::run(&client, &HashMap::new())?;
109+
let introspection_response = introspect::run(
110+
SubgraphIntrospectInput {
111+
headers: HashMap::new(),
112+
},
113+
&client,
114+
)?;
109115
let schema = introspection_response.result;
110116

111117
// We don't require a routing_url for this variant of a schema,

0 commit comments

Comments
 (0)