Skip to content

Commit

Permalink
chore: move GraphRef to rover-client (#664)
Browse files Browse the repository at this point in the history
  • Loading branch information
EverlastingBugstopper authored Jul 7, 2021
1 parent e29b87b commit 6ac35e1
Show file tree
Hide file tree
Showing 41 changed files with 358 additions and 274 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ humantime = "2.1.0"
opener = "0.5.0"
os_info = "3.0"
prettytable-rs = "0.8.0"
regex = "1"
serde = "1.0"
serde_json = "1.0"
serde_yaml = "0.8"
Expand Down
1 change: 1 addition & 0 deletions crates/rover-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ git2 = { version = "0.13.20", default-features = false, features = ["vendored-op
graphql_client = "0.9"
http = "0.2"
reqwest = {version = "0.11", default-features = false, features = ["json", "blocking", "rustls-tls", "gzip"]}
regex = "1"
sdl-encoder = {path = "../sdl-encoder"}
semver = "1"
serde = "1"
Expand Down
6 changes: 5 additions & 1 deletion crates/rover-client/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use reqwest::Url;
use thiserror::Error;

use crate::{operations::subgraph::check::types::CompositionError, shared::CheckResponse};
use crate::shared::{CheckResponse, CompositionError};

/// RoverClientError represents all possible failures that can occur during a client request.
#[derive(Error, Debug)]
Expand Down Expand Up @@ -138,6 +138,10 @@ pub enum RoverClientError {
#[error("{}", check_response_error_msg(.check_response))]
OperationCheckFailure { check_response: CheckResponse },

/// This error occurs when a user has a malformed Graph Ref
#[error("Graph IDs must be in the format <NAME> or <NAME>@<VARIANT>, where <NAME> can only contain letters, numbers, or the characters `-` or `_`, and must be 64 characters or less. <VARIANT> must be 64 characters or less.")]
InvalidGraphRef,

/// This error occurs when a user has a malformed API key
#[error(
"The API key you provided is malformed. An API key must have three parts separated by a colon."
Expand Down
3 changes: 2 additions & 1 deletion crates/rover-client/src/operations/config/who_am_i/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod runner;
mod types;

pub mod runner;
pub use runner::run;
pub use types::{Actor, ConfigWhoAmIInput, RegistryIdentity};
2 changes: 1 addition & 1 deletion crates/rover-client/src/operations/graph/check/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn run(
input: GraphCheckInput,
client: &StudioClient,
) -> Result<CheckResponse, RoverClientError> {
let graph = input.graph_id.clone();
let graph = input.graph_ref.name.clone();
let data = client.post::<GraphCheckMutation>(input.into())?;
get_check_response_from_data(data, graph)
}
Expand Down
9 changes: 4 additions & 5 deletions crates/rover-client/src/operations/graph/check/types.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::operations::graph::check::runner::graph_check_mutation;
use crate::shared::{ChangeSeverity, CheckConfig, GitContext, SchemaChange};
use crate::shared::{ChangeSeverity, CheckConfig, GitContext, GraphRef, SchemaChange};

#[derive(Debug, Clone, PartialEq)]
pub struct GraphCheckInput {
pub graph_id: String,
pub variant: String,
pub graph_ref: GraphRef,
pub proposed_schema: String,
pub git_context: GitContext,
pub config: CheckConfig,
Expand All @@ -13,8 +12,8 @@ pub struct GraphCheckInput {
impl From<GraphCheckInput> for MutationVariables {
fn from(input: GraphCheckInput) -> Self {
Self {
graph_id: input.graph_id,
variant: Some(input.variant),
graph_id: input.graph_ref.name,
variant: Some(input.graph_ref.variant),
proposed_schema: Some(input.proposed_schema),
config: input.config.into(),
git_context: input.git_context.into(),
Expand Down
6 changes: 4 additions & 2 deletions crates/rover-client/src/operations/subgraph/check/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod runner;
pub(crate) mod types;
mod runner;
mod types;

pub use runner::run;
pub use types::SubgraphCheckInput;
8 changes: 4 additions & 4 deletions crates/rover-client/src/operations/subgraph/check/runner.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::types::*;
use crate::blocking::StudioClient;
use crate::operations::{config::is_federated, subgraph::check::types::MutationResponseData};
use crate::shared::{CheckResponse, SchemaChange};
use crate::shared::{CheckResponse, CompositionError, SchemaChange};
use crate::RoverClientError;

use graphql_client::*;
Expand All @@ -28,12 +28,12 @@ pub fn run(
input: SubgraphCheckInput,
client: &StudioClient,
) -> Result<CheckResponse, RoverClientError> {
let graph = input.graph_id.clone();
let graph = input.graph_ref.name.clone();
// This response is used to check whether or not the current graph is federated.
let is_federated = is_federated::run(
is_federated::is_federated_graph::Variables {
graph_id: input.graph_id.clone(),
graph_variant: input.variant.clone(),
graph_id: input.graph_ref.name.clone(),
graph_variant: input.graph_ref.variant.clone(),
},
&client,
)?;
Expand Down
15 changes: 4 additions & 11 deletions crates/rover-client/src/operations/subgraph/check/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::operations::subgraph::check::runner::subgraph_check_mutation;
use crate::shared::{ChangeSeverity, CheckConfig, GitContext};
use crate::shared::{ChangeSeverity, CheckConfig, GitContext, GraphRef};

type MutationVariables = subgraph_check_mutation::Variables;

Expand Down Expand Up @@ -36,8 +36,7 @@ impl From<GitContext> for MutationGitContextInput {

#[derive(Debug, Clone, PartialEq)]
pub struct SubgraphCheckInput {
pub graph_id: String,
pub variant: String,
pub graph_ref: GraphRef,
pub subgraph: String,
pub proposed_schema: String,
pub git_context: GitContext,
Expand All @@ -47,8 +46,8 @@ pub struct SubgraphCheckInput {
impl From<SubgraphCheckInput> for MutationVariables {
fn from(input: SubgraphCheckInput) -> Self {
Self {
graph_id: input.graph_id,
variant: input.variant,
graph_id: input.graph_ref.name,
variant: input.graph_ref.variant,
subgraph: input.subgraph,
proposed_schema: MutationSchema {
sdl: Some(input.proposed_schema),
Expand All @@ -68,9 +67,3 @@ impl From<SubgraphCheckInput> for MutationVariables {
}
}
}

#[derive(Debug, Clone, PartialEq)]
pub struct CompositionError {
pub message: String,
pub code: Option<String>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mutation SubgraphDeleteMutation(
) {
errors {
message
code
}
updatedGateway
}
Expand Down
3 changes: 1 addition & 2 deletions crates/rover-client/src/operations/subgraph/delete/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
mod runner;

pub(crate) mod types;
mod types;

pub use runner::run;
pub use types::{SubgraphDeleteInput, SubgraphDeleteResponse};
37 changes: 31 additions & 6 deletions crates/rover-client/src/operations/subgraph/delete/runner.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::blocking::StudioClient;
use crate::operations::subgraph::delete::types::*;
use crate::shared::CompositionError;
use crate::RoverClientError;

use graphql_client::*;
Expand All @@ -24,7 +25,7 @@ pub fn run(
input: SubgraphDeleteInput,
client: &StudioClient,
) -> Result<SubgraphDeleteResponse, RoverClientError> {
let graph = input.graph_id.clone();
let graph = input.graph_ref.name.clone();
let response_data = client.post::<SubgraphDeleteMutation>(input.into())?;
let data = get_delete_data_from_response(response_data, graph)?;
Ok(build_response(data))
Expand All @@ -42,10 +43,15 @@ fn get_delete_data_from_response(
}

fn build_response(response: MutationComposition) -> SubgraphDeleteResponse {
let composition_errors: Vec<String> = response
let composition_errors: Vec<CompositionError> = response
.errors
.iter()
.filter_map(|error| error.as_ref().map(|e| e.message.clone()))
.filter_map(|error| {
error.as_ref().map(|e| CompositionError {
message: e.message.clone(),
code: e.code.clone(),
})
})
.collect();

// if there are no errors, just return None
Expand All @@ -72,9 +78,15 @@ mod tests {
"service": {
"removeImplementingServiceAndTriggerComposition": {
"errors": [
{ "message": "wow" },
{
"message": "wow",
"code": null
},
null,
{ "message": "boo" }
{
"message": "boo",
"code": "BOO"
}
],
"updatedGateway": false,
}
Expand All @@ -90,10 +102,12 @@ mod tests {
errors: vec![
Some(MutationCompositionErrors {
message: "wow".to_string(),
code: None,
}),
None,
Some(MutationCompositionErrors {
message: "boo".to_string(),
code: Some("BOO".to_string()),
}),
],
updated_gateway: false,
Expand All @@ -107,10 +121,12 @@ mod tests {
errors: vec![
Some(MutationCompositionErrors {
message: "wow".to_string(),
code: None,
}),
None,
Some(MutationCompositionErrors {
message: "boo".to_string(),
code: Some("BOO".to_string()),
}),
],
updated_gateway: false,
Expand All @@ -120,7 +136,16 @@ mod tests {
assert_eq!(
parsed,
SubgraphDeleteResponse {
composition_errors: Some(vec!["wow".to_string(), "boo".to_string()]),
composition_errors: Some(vec![
CompositionError {
message: "wow".to_string(),
code: None
},
CompositionError {
message: "boo".to_string(),
code: Some("BOO".to_string())
}
]),
updated_gateway: false,
}
);
Expand Down
14 changes: 8 additions & 6 deletions crates/rover-client/src/operations/subgraph/delete/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::operations::subgraph::delete::runner::subgraph_delete_mutation;
use crate::{
operations::subgraph::delete::runner::subgraph_delete_mutation,
shared::{CompositionError, GraphRef},
};

pub(crate) type MutationComposition = subgraph_delete_mutation::SubgraphDeleteMutationServiceRemoveImplementingServiceAndTriggerComposition;
pub(crate) type MutationVariables = subgraph_delete_mutation::Variables;
Expand All @@ -8,8 +11,7 @@ pub(crate) type MutationCompositionErrors = subgraph_delete_mutation::SubgraphDe

#[derive(Debug, Clone, PartialEq)]
pub struct SubgraphDeleteInput {
pub graph_id: String,
pub variant: String,
pub graph_ref: GraphRef,
pub subgraph: String,
pub dry_run: bool,
}
Expand All @@ -21,14 +23,14 @@ pub struct SubgraphDeleteInput {
#[derive(Debug, PartialEq)]
pub struct SubgraphDeleteResponse {
pub updated_gateway: bool,
pub composition_errors: Option<Vec<String>>,
pub composition_errors: Option<Vec<CompositionError>>,
}

impl From<SubgraphDeleteInput> for MutationVariables {
fn from(input: SubgraphDeleteInput) -> Self {
Self {
graph_id: input.graph_id,
variant: input.variant,
graph_id: input.graph_ref.name,
variant: input.graph_ref.variant,
subgraph: input.subgraph,
dry_run: input.dry_run,
}
Expand Down
6 changes: 4 additions & 2 deletions crates/rover-client/src/operations/subgraph/fetch/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod runner;
pub(crate) mod types;
mod runner;
mod types;

pub use runner::run;
pub use types::{SubgraphFetchInput, SubgraphFetchResponse};
8 changes: 4 additions & 4 deletions crates/rover-client/src/operations/subgraph/fetch/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ pub fn run(
input: SubgraphFetchInput,
client: &StudioClient,
) -> Result<SubgraphFetchResponse, RoverClientError> {
let variables: SubgraphFetchVariables = input.clone().into();
let response_data = client.post::<SubgraphFetchQuery>(variables.into())?;
get_sdl_from_response_data(input, response_data)
let input_clone = input.clone();
let response_data = client.post::<SubgraphFetchQuery>(input.into())?;
get_sdl_from_response_data(input_clone, response_data)
}

fn get_sdl_from_response_data(
input: SubgraphFetchInput,
response_data: SubgraphFetchResponseData,
) -> Result<SubgraphFetchResponse, RoverClientError> {
let service_list = get_services_from_response_data(&input.graph_id, response_data)?;
let service_list = get_services_from_response_data(&input.graph_ref.name, response_data)?;
let sdl = get_sdl_for_service(&input.subgraph, service_list)?;
Ok(SubgraphFetchResponse { sdl })
}
Expand Down
26 changes: 6 additions & 20 deletions crates/rover-client/src/operations/subgraph/fetch/types.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::shared::GraphRef;

use super::runner::subgraph_fetch_query;

pub(crate) type ServiceList = Vec<subgraph_fetch_query::SubgraphFetchQueryServiceImplementingServicesOnFederatedImplementingServicesServices>;
Expand All @@ -7,31 +9,15 @@ pub(crate) type QueryVariables = subgraph_fetch_query::Variables;

#[derive(Debug, Clone, PartialEq)]
pub struct SubgraphFetchInput {
pub graph_id: String,
pub variant: String,
pub graph_ref: GraphRef,
pub subgraph: String,
}

#[derive(Debug, Clone, PartialEq)]
pub(crate) struct SubgraphFetchVariables {
graph_id: String,
variant: String,
}

impl From<SubgraphFetchInput> for SubgraphFetchVariables {
impl From<SubgraphFetchInput> for QueryVariables {
fn from(input: SubgraphFetchInput) -> Self {
Self {
graph_id: input.graph_id,
variant: input.variant,
}
}
}

impl From<SubgraphFetchVariables> for QueryVariables {
fn from(fetch_variables: SubgraphFetchVariables) -> Self {
Self {
graph_id: fetch_variables.graph_id,
variant: fetch_variables.variant,
graph_id: input.graph_ref.name,
variant: input.graph_ref.variant,
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/rover-client/src/operations/subgraph/list/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
mod runner;

pub(crate) mod types;
mod types;

pub use runner::run;
pub use types::{SubgraphListInput, SubgraphListResponse};
2 changes: 1 addition & 1 deletion crates/rover-client/src/operations/subgraph/list/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn run(
input: SubgraphListInput,
client: &StudioClient,
) -> Result<SubgraphListResponse, RoverClientError> {
let graph = input.graph_id.clone();
let graph = input.graph_ref.name.clone();
let response_data = client.post::<SubgraphListQuery>(input.into())?;
let root_url = response_data.frontend_url_root.clone();
let subgraphs = get_subgraphs_from_response_data(response_data, graph.clone())?;
Expand Down
Loading

0 comments on commit 6ac35e1

Please sign in to comment.