From 458421ad5c41dac417bbfd119782a3c050d57897 Mon Sep 17 00:00:00 2001 From: Avery Harnish Date: Mon, 16 Aug 2021 16:51:55 -0500 Subject: [PATCH] fix(rover-client): properly send validation period config fixes a regression in v0.2.0-beta.0-1 that doesn't ever send `null` when a configuration period isn't set via argument --- .../src/operations/graph/check/types.rs | 18 +++---- .../src/operations/subgraph/check/types.rs | 48 +++++++++---------- .../rover-client/src/shared/check_response.rs | 35 +++++++++----- subgraphs/reviews.graphql | 0 4 files changed, 54 insertions(+), 47 deletions(-) delete mode 100644 subgraphs/reviews.graphql diff --git a/crates/rover-client/src/operations/graph/check/types.rs b/crates/rover-client/src/operations/graph/check/types.rs index ae3de170f..8e154c680 100644 --- a/crates/rover-client/src/operations/graph/check/types.rs +++ b/crates/rover-client/src/operations/graph/check/types.rs @@ -24,18 +24,18 @@ impl From for MutationVariables { type MutationConfig = graph_check_mutation::HistoricQueryParameters; impl From for MutationConfig { fn from(input: CheckConfig) -> Self { + let (from, to) = match input.validation_period { + Some(validation_period) => ( + Some(validation_period.from.to_string()), + Some(validation_period.to.to_string()), + ), + None => (None, None), + }; Self { queryCountThreshold: input.query_count_threshold, queryCountThresholdPercentage: input.query_count_threshold_percentage, - from: Some( - input - .validation_period - .clone() - .unwrap_or_default() - .from - .to_string(), - ), - to: Some(input.validation_period.unwrap_or_default().to.to_string()), + from, + to, // we don't support configuring these, but we can't leave them out excludedClients: None, ignoredOperations: None, diff --git a/crates/rover-client/src/operations/subgraph/check/types.rs b/crates/rover-client/src/operations/subgraph/check/types.rs index 0dd62083b..18e0e8fad 100644 --- a/crates/rover-client/src/operations/subgraph/check/types.rs +++ b/crates/rover-client/src/operations/subgraph/check/types.rs @@ -53,32 +53,30 @@ impl From for MutationVariables { sdl: Some(input.proposed_schema), hash: None, }, - config: MutationConfig { - queryCountThreshold: input.config.query_count_threshold, - queryCountThresholdPercentage: input.config.query_count_threshold_percentage, - from: Some( - input - .config - .validation_period - .clone() - .unwrap_or_default() - .from - .to_string(), - ), - to: Some( - input - .config - .validation_period - .unwrap_or_default() - .to - .to_string(), - ), - // we don't support configuring these, but we can't leave them out - excludedClients: None, - ignoredOperations: None, - includedVariants: None, - }, + config: input.config.into(), git_context: input.git_context.into(), } } } + +impl From for MutationConfig { + fn from(input: CheckConfig) -> Self { + let (from, to) = match input.validation_period { + Some(validation_period) => ( + Some(validation_period.from.to_string()), + Some(validation_period.to.to_string()), + ), + None => (None, None), + }; + Self { + queryCountThreshold: input.query_count_threshold, + queryCountThresholdPercentage: input.query_count_threshold_percentage, + from, + to, + // we don't support configuring these, but we can't leave them out + excludedClients: None, + ignoredOperations: None, + includedVariants: None, + } + } +} diff --git a/crates/rover-client/src/shared/check_response.rs b/crates/rover-client/src/shared/check_response.rs index 2831ab25a..a5826e0ee 100644 --- a/crates/rover-client/src/shared/check_response.rs +++ b/crates/rover-client/src/shared/check_response.rs @@ -1,5 +1,5 @@ use std::cmp::Ordering; -use std::fmt::{self}; +use std::fmt::{self, Display}; use std::str::FromStr; use crate::shared::GraphRef; @@ -153,10 +153,10 @@ pub struct CheckConfig { pub validation_period: Option, } -#[derive(Debug, PartialEq, Eq, Serialize, Default, Clone)] +#[derive(Debug, PartialEq, Eq, Serialize, Clone)] pub struct ValidationPeriod { - pub from: i64, - pub to: i64, + pub from: Period, + pub to: Period, } // Validation period is parsed as human readable time. @@ -171,16 +171,25 @@ impl FromStr for ValidationPeriod { }; let duration = humantime::parse_duration(period)?; - let from = duration.as_secs() as i64; - let from = -from; - - let to = 0; - Ok(ValidationPeriod { - // search "from" a negative time window - from: -from, - // search "to" now (-0) seconds - to: -to, + from: Period::Past(duration.as_secs() as i64), + to: Period::Now, }) } } + +#[derive(Debug, Clone, PartialEq, Eq, Serialize)] +pub enum Period { + Now, + Past(i64), +} + +impl Display for Period { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let period = match &self { + Period::Now => "-0".to_string(), + Period::Past(seconds) => (-seconds).to_string(), + }; + write!(f, "{}", period) + } +} diff --git a/subgraphs/reviews.graphql b/subgraphs/reviews.graphql deleted file mode 100644 index e69de29bb..000000000