Skip to content

Commit 8a46547

Browse files
chore: begin adding shared types
I got a little carried away with this commit, but it's a good thing I promise. We've got lots of shared types now, I've got plans for a bunch more, and things are looking cleaner than ever. graph::check and subgraph::check were the primary drivers here, but some other stuff was touched along the way.
1 parent 7555b91 commit 8a46547

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+349
-239
lines changed

ARCHITECTURE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ Then, we'll create a new struct that will have auto-generated types for the `hel
320320
// The paths are relative to the directory where your `Cargo.toml` is located.
321321
// Both json and the GraphQL schema language are supported as sources for the schema
322322
#[graphql(
323-
query_path = "src/query/graph/hello.graphql",
323+
query_path = "src/operations/graph/hello.graphql",
324324
schema_path = ".schema/schema.graphql",
325325
response_derives = "PartialEq, Debug, Serialize, Deserialize",
326326
deprecated = "warn"

crates/rover-client/src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use reqwest::Url;
22
use thiserror::Error;
33

4-
use crate::query::subgraph::check::types::CompositionError;
4+
use crate::operations::subgraph::check::types::CompositionError;
55

66
/// RoverClientError represents all possible failures that can occur during a client request.
77
#[derive(Error, Debug)]

crates/rover-client/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ pub use error::RoverClientError;
1212

1313
#[allow(clippy::upper_case_acronyms)]
1414
/// Module for actually querying studio
15-
pub mod query;
15+
pub mod operations;
1616

1717
/// Module for getting release info
1818
pub mod releases;
1919

2020
/// Module for shared functionality
21-
pub mod utils;
21+
pub mod shared;

crates/rover-client/src/query/config/is_federated.rs crates/rover-client/src/operations/config/is_federated.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use graphql_client::*;
77
// The paths are relative to the directory where your `Cargo.toml` is located.
88
// Both json and the GraphQL schema language are supported as sources for the schema
99
#[graphql(
10-
query_path = "src/query/config/is_federated.graphql",
10+
query_path = "src/operations/config/is_federated.graphql",
1111
schema_path = ".schema/schema.graphql",
1212
response_derives = "PartialEq, Debug, Serialize, Deserialize",
1313
deprecated = "warn"

crates/rover-client/src/query/config/who_am_i/query_runner.rs crates/rover-client/src/operations/config/who_am_i/query_runner.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::blocking::StudioClient;
2-
use crate::query::config::who_am_i::{
2+
use crate::operations::config::who_am_i::{
33
types::{QueryActorType, QueryResponseData, RegistryIdentity},
44
Actor, ConfigWhoAmIInput,
55
};
@@ -13,7 +13,7 @@ use graphql_client::*;
1313
// The paths are relative to the directory where your `Cargo.toml` is located.
1414
// Both json and the GraphQL schema language are supported as sources for the schema
1515
#[graphql(
16-
query_path = "src/query/config/who_am_i/who_am_i_query.graphql",
16+
query_path = "src/operations/config/who_am_i/who_am_i_query.graphql",
1717
schema_path = ".schema/schema.graphql",
1818
response_derives = "PartialEq, Debug, Serialize, Deserialize",
1919
deprecated = "warn"

crates/rover-client/src/query/graph/check.graphql crates/rover-client/src/operations/graph/check/check_mutation.graphql

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
mutation CheckSchemaQuery(
2-
$graphId: ID!
1+
mutation GraphCheckMutation(
2+
$graph_id: ID!
33
$variant: String
4-
$schema: String
5-
$gitContext: GitContextInput!
4+
$proposed_schema: String
5+
$git_context: GitContextInput!
66
$config: HistoricQueryParameters!
77
) {
88
service(id: $graphId) {
@@ -24,4 +24,4 @@ mutation CheckSchemaQuery(
2424
}
2525
}
2626
}
27-
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mod mutation_runner;
2+
mod types;
3+
4+
pub use mutation_runner::run;
5+
pub use types::GraphCheckInput;
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,53 @@
11
use crate::blocking::StudioClient;
2+
use crate::operations::graph::check::types::{GraphCheckInput, MutationResponseData};
3+
use crate::shared::CheckResponse;
24
use crate::RoverClientError;
3-
use graphql_client::*;
45

5-
use reqwest::Url;
6+
use graphql_client::*;
67

78
type Timestamp = String;
89
#[derive(GraphQLQuery)]
910
// The paths are relative to the directory where your `Cargo.toml` is located.
1011
// Both json and the GraphQL schema language are supported as sources for the schema
1112
#[graphql(
12-
query_path = "src/query/graph/check.graphql",
13+
query_path = "src/operations/graph/check/check_mutation.graphql",
1314
schema_path = ".schema/schema.graphql",
1415
response_derives = "PartialEq, Debug, Serialize, Deserialize",
1516
deprecated = "warn"
1617
)]
1718
/// This struct is used to generate the module containing `Variables` and
1819
/// `ResponseData` structs.
19-
/// Snake case of this name is the mod name. i.e. check_schema_query
20-
pub struct CheckSchemaQuery;
20+
/// Snake case of this name is the mod name. i.e. graph_check_mutation
21+
pub(crate) struct GraphCheckMutation;
2122

2223
/// The main function to be used from this module.
2324
/// This function takes a proposed schema and validates it against a published
2425
/// schema.
2526
pub fn run(
26-
variables: check_schema_query::Variables,
27+
input: GraphCheckInput,
2728
client: &StudioClient,
2829
) -> Result<CheckResponse, RoverClientError> {
29-
let graph = variables.graph_id.clone();
30-
let data = client.post::<CheckSchemaQuery>(variables)?;
30+
let graph = input.graph_id.clone();
31+
let data = client.post::<GraphCheckMutation>(input.into())?;
3132
get_check_response_from_data(data, graph)
3233
}
3334

34-
#[derive(Debug)]
35-
pub struct CheckResponse {
36-
pub target_url: Option<Url>,
37-
pub number_of_checked_operations: i64,
38-
pub change_severity: check_schema_query::ChangeSeverity,
39-
pub changes: Vec<check_schema_query::CheckSchemaQueryServiceCheckSchemaDiffToPreviousChanges>,
40-
}
41-
4235
fn get_check_response_from_data(
43-
data: check_schema_query::ResponseData,
36+
data: MutationResponseData,
4437
graph: String,
4538
) -> Result<CheckResponse, RoverClientError> {
4639
let service = data.service.ok_or(RoverClientError::NoService { graph })?;
47-
let target_url = get_url(service.check_schema.target_url);
40+
let target_url = service.check_schema.target_url;
4841

4942
let diff_to_previous = service.check_schema.diff_to_previous;
5043

5144
let number_of_checked_operations = diff_to_previous.number_of_checked_operations.unwrap_or(0);
5245

53-
let change_severity = diff_to_previous.severity;
54-
let changes = diff_to_previous.changes;
46+
let change_severity = diff_to_previous.severity.into();
47+
let mut changes = Vec::with_capacity(diff_to_previous.changes.len());
48+
for change in diff_to_previous.changes {
49+
changes.push(change.into());
50+
}
5551

5652
Ok(CheckResponse {
5753
target_url,
@@ -60,17 +56,3 @@ fn get_check_response_from_data(
6056
changes,
6157
})
6258
}
63-
64-
fn get_url(url: Option<String>) -> Option<Url> {
65-
match url {
66-
Some(url) => {
67-
let url = Url::parse(&url);
68-
match url {
69-
Ok(url) => Some(url),
70-
// if the API returns an invalid URL, don't put it in the response
71-
Err(_) => None,
72-
}
73-
}
74-
None => None,
75-
}
76-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
use crate::operations::graph::check::mutation_runner::graph_check_mutation;
2+
use crate::shared::{ChangeSeverity, CheckConfig, GitContext, SchemaChange};
3+
4+
#[derive(Debug, Clone, PartialEq)]
5+
pub struct GraphCheckInput {
6+
pub graph_id: String,
7+
pub variant: String,
8+
pub proposed_schema: String,
9+
pub git_context: GitContext,
10+
pub config: CheckConfig,
11+
}
12+
13+
impl From<GraphCheckInput> for MutationVariables {
14+
fn from(input: GraphCheckInput) -> Self {
15+
Self {
16+
graph_id: input.graph_id,
17+
variant: Some(input.variant),
18+
proposed_schema: Some(input.proposed_schema),
19+
config: input.config.into(),
20+
git_context: input.git_context.into(),
21+
}
22+
}
23+
}
24+
25+
type MutationConfig = graph_check_mutation::HistoricQueryParameters;
26+
impl From<CheckConfig> for MutationConfig {
27+
fn from(input: CheckConfig) -> Self {
28+
Self {
29+
query_count_threshold: input.query_count_threshold,
30+
query_count_threshold_percentage: input.query_count_threshold_percentage,
31+
from: input.validation_period_from,
32+
to: input.validation_period_to,
33+
// we don't support configuring these, but we can't leave them out
34+
excluded_clients: None,
35+
ignored_operations: None,
36+
included_variants: None,
37+
}
38+
}
39+
}
40+
41+
type MutationVariables = graph_check_mutation::Variables;
42+
pub(crate) type MutationResponseData = graph_check_mutation::ResponseData;
43+
44+
type MutationChangeSeverity = graph_check_mutation::ChangeSeverity;
45+
impl From<MutationChangeSeverity> for ChangeSeverity {
46+
fn from(severity: MutationChangeSeverity) -> Self {
47+
match severity {
48+
MutationChangeSeverity::NOTICE => ChangeSeverity::PASS,
49+
MutationChangeSeverity::FAILURE => ChangeSeverity::FAIL,
50+
_ => ChangeSeverity::unreachable(),
51+
}
52+
}
53+
}
54+
55+
impl From<ChangeSeverity> for MutationChangeSeverity {
56+
fn from(severity: ChangeSeverity) -> Self {
57+
match severity {
58+
ChangeSeverity::PASS => MutationChangeSeverity::NOTICE,
59+
ChangeSeverity::FAIL => MutationChangeSeverity::FAILURE,
60+
}
61+
}
62+
}
63+
64+
type MutationSchemaChange =
65+
graph_check_mutation::GraphCheckMutationServiceCheckSchemaDiffToPreviousChanges;
66+
impl From<SchemaChange> for MutationSchemaChange {
67+
fn from(schema_change: SchemaChange) -> MutationSchemaChange {
68+
MutationSchemaChange {
69+
severity: schema_change.severity.into(),
70+
code: schema_change.code,
71+
description: schema_change.description,
72+
}
73+
}
74+
}
75+
76+
impl From<MutationSchemaChange> for SchemaChange {
77+
fn from(schema_change: MutationSchemaChange) -> SchemaChange {
78+
SchemaChange {
79+
severity: schema_change.severity.into(),
80+
code: schema_change.code,
81+
description: schema_change.description,
82+
}
83+
}
84+
}
85+
86+
type MutationGitContextInput = graph_check_mutation::GitContextInput;
87+
impl From<GitContext> for MutationGitContextInput {
88+
fn from(git_context: GitContext) -> MutationGitContextInput {
89+
MutationGitContextInput {
90+
branch: git_context.branch,
91+
commit: git_context.commit,
92+
committer: git_context.author,
93+
remote_url: git_context.remote_url,
94+
message: None,
95+
}
96+
}
97+
}

crates/rover-client/src/query/graph/fetch.rs crates/rover-client/src/operations/graph/fetch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type GraphQLDocument = String;
1010
// The paths are relative to the directory where your `Cargo.toml` is located.
1111
// Both json and the GraphQL schema language are supported as sources for the schema
1212
#[graphql(
13-
query_path = "src/query/graph/fetch.graphql",
13+
query_path = "src/operations/graph/fetch.graphql",
1414
schema_path = ".schema/schema.graphql",
1515
response_derives = "PartialEq, Debug, Serialize, Deserialize",
1616
deprecated = "warn"

crates/rover-client/src/query/graph/introspect/query_runner.rs crates/rover-client/src/operations/graph/introspect/query_runner.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use crate::blocking::GraphQLClient;
2-
use crate::query::graph::introspect::{types::*, Schema};
2+
use crate::operations::graph::introspect::{types::*, Schema};
33
use crate::RoverClientError;
44
use graphql_client::*;
55

66
use std::convert::TryFrom;
77

88
#[derive(GraphQLQuery)]
99
#[graphql(
10-
query_path = "src/query/graph/introspect/introspect_query.graphql",
11-
schema_path = "src/query/graph/introspect/introspect_schema.graphql",
10+
query_path = "src/operations/graph/introspect/introspect_query.graphql",
11+
schema_path = "src/operations//graph/introspect/introspect_schema.graphql",
1212
response_derives = "PartialEq, Debug, Serialize, Deserialize",
1313
deprecated = "warn"
1414
)]

crates/rover-client/src/query/graph/introspect/schema.rs crates/rover-client/src/operations/graph/introspect/schema.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use sdl_encoder::{
1010
use serde::Deserialize;
1111
use std::convert::TryFrom;
1212

13-
use crate::query::graph::introspect::query_runner::graph_introspect_query;
13+
use crate::operations::graph::introspect::query_runner::graph_introspect_query;
1414

1515
type FullTypeField = graph_introspect_query::FullTypeFields;
1616
type FullTypeInputField = graph_introspect_query::FullTypeInputFields;
@@ -363,7 +363,7 @@ mod tests {
363363
use std::convert::TryFrom;
364364
use std::fs::File;
365365

366-
use crate::query::graph::introspect::types::QueryResponseData;
366+
use crate::operations::graph::introspect::types::QueryResponseData;
367367

368368
#[test]
369369
fn it_builds_simple_schema() {

crates/rover-client/src/query/graph/introspect/types.rs crates/rover-client/src/operations/graph/introspect/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::HashMap;
22

3-
use crate::query::graph::introspect::query_runner::graph_introspect_query;
3+
use crate::operations::graph::introspect::query_runner::graph_introspect_query;
44

55
pub(crate) type QueryResponseData = graph_introspect_query::ResponseData;
66
pub(crate) type QueryVariables = graph_introspect_query::Variables;

crates/rover-client/src/query/graph/publish.rs crates/rover-client/src/operations/graph/publish.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use graphql_client::*;
66
// The paths are relative to the directory where your `Cargo.toml` is located.
77
// Both json and the GraphQL schema language are supported as sources for the schema
88
#[graphql(
9-
query_path = "src/query/graph/publish.graphql",
9+
query_path = "src/operations/graph/publish.graphql",
1010
schema_path = ".schema/schema.graphql",
1111
response_derives = "PartialEq, Debug, Serialize, Deserialize",
1212
deprecated = "warn"
File renamed without changes.

crates/rover-client/src/query/subgraph/check/check_query.graphql crates/rover-client/src/operations/subgraph/check/check_mutation.graphql

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
mutation SubgraphCheckQuery(
1+
mutation SubgraphCheckMutation(
22
$graph_id: ID!
33
$variant: String!
44
$subgraph: String!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod mutation_runner;
2+
pub(crate) mod types;
3+
pub use types::SubgraphCheckInput;

0 commit comments

Comments
 (0)