|
| 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 | +} |
0 commit comments