Skip to content

Commit

Permalink
Merge branch 'composition-integration' into loshz/supergraph-watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
loshz committed Sep 17, 2024
2 parents 948d1d3 + 0316b8e commit 9bccc19
Show file tree
Hide file tree
Showing 10 changed files with 345 additions and 14 deletions.
9 changes: 9 additions & 0 deletions crates/rover-client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,15 @@ fn check_workflow_error_msg(check_response: &CheckWorkflowResponse) -> String {
} else {
None
},
if let Some(custom_response) = &check_response.maybe_custom_response {
if custom_response.task_status == CheckTaskStatus::FAILED {
Some("custom")
} else {
None
}
} else {
None
},
]
.iter()
.filter_map(|&x| x)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,29 @@ query GraphCheckWorkflowQuery($graph_id: ID!, $workflow_id: ID!) {
}
}
}
... on CustomCheckTask {
result {
violations {
coordinate
level
message
rule
sourceLocations {
start {
byteOffset
column
line
}
end {
byteOffset
column
line
}
subgraphName
}
}
}
}
}
}
}
Expand Down
64 changes: 61 additions & 3 deletions crates/rover-client/src/operations/graph/check_workflow/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ use graphql_client::*;
use crate::blocking::StudioClient;
use crate::operations::graph::check_workflow::types::{CheckWorkflowInput, QueryResponseData};
use crate::shared::{
CheckWorkflowResponse, Diagnostic, GraphRef, LintCheckResponse, OperationCheckResponse,
SchemaChange,
CheckWorkflowResponse, CustomCheckResponse, Diagnostic, GraphRef, LintCheckResponse,
OperationCheckResponse, SchemaChange, Violation,
};
use crate::RoverClientError;

use self::graph_check_workflow_query::GraphCheckWorkflowQueryGraphCheckWorkflowTasksOn::{
LintCheckTask, OperationsCheckTask,
CustomCheckTask, LintCheckTask, OperationsCheckTask,
};
use self::graph_check_workflow_query::{
CheckWorkflowStatus, CheckWorkflowTaskStatus,
GraphCheckWorkflowQueryGraphCheckWorkflowTasksOnCustomCheckTaskResult,
GraphCheckWorkflowQueryGraphCheckWorkflowTasksOnLintCheckTaskResult,
GraphCheckWorkflowQueryGraphCheckWorkflowTasksOnOperationsCheckTaskResult,
};
Expand Down Expand Up @@ -96,6 +97,12 @@ fn get_check_response_from_data(
GraphCheckWorkflowQueryGraphCheckWorkflowTasksOnLintCheckTaskResult,
> = None;

let mut custom_status = None;
let mut custom_target_url = None;
let mut custom_result: Option<
GraphCheckWorkflowQueryGraphCheckWorkflowTasksOnCustomCheckTaskResult,
> = None;

for task in check_workflow.tasks {
match task.on {
OperationsCheckTask(typed_task) => {
Expand All @@ -114,6 +121,13 @@ fn get_check_response_from_data(
lint_result = Some(result)
}
}
CustomCheckTask(typed_task) => {
custom_status = Some(task.status);
custom_target_url = task.target_url;
if let Some(result) = typed_task.result {
custom_result = Some(result)
}
}
_ => (),
}
}
Expand All @@ -138,6 +152,11 @@ fn get_check_response_from_data(
lint_target_url,
lint_result,
),
maybe_custom_response: get_custom_response_from_result(
custom_status,
custom_target_url,
custom_result,
),
maybe_proposals_response: None,
maybe_downstream_response: None,
};
Expand All @@ -160,6 +179,7 @@ fn get_target_url_from_data(data: QueryResponseData) -> Option<String> {
match task.on {
OperationsCheckTask(_) => target_url = task.target_url,
LintCheckTask(_) => target_url = task.target_url,
CustomCheckTask(_) => target_url = task.target_url,
_ => (),
}
}
Expand Down Expand Up @@ -236,3 +256,41 @@ fn get_lint_response_from_result(
None => None,
}
}

fn get_custom_response_from_result(
task_status: Option<CheckWorkflowTaskStatus>,
target_url: Option<String>,
results: Option<GraphCheckWorkflowQueryGraphCheckWorkflowTasksOnCustomCheckTaskResult>,
) -> Option<CustomCheckResponse> {
match results {
Some(result) => {
let violations: Vec<Violation> = result
.violations
.iter()
.map(|violation| {
let start_line = if let Some(source_locations) = &violation.source_locations {
if !source_locations.is_empty() {
Some(source_locations[0].start.line)
} else {
None
}
} else {
None
};
Violation {
level: violation.level.to_string(),
message: violation.message.clone(),
start_line,
rule: violation.rule.clone(),
}
})
.collect();
Some(CustomCheckResponse {
task_status: task_status.into(),
target_url,
violations,
})
}
None => None,
}
}
12 changes: 12 additions & 0 deletions crates/rover-client/src/operations/graph/check_workflow/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,15 @@ impl Display for graph_check_workflow_query::LintRule {
Debug::fmt(self, f)
}
}

impl fmt::Display for graph_check_workflow_query::ViolationLevel {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let printable = match &self {
graph_check_workflow_query::ViolationLevel::WARNING => "WARNING",
graph_check_workflow_query::ViolationLevel::ERROR => "ERROR",
graph_check_workflow_query::ViolationLevel::INFO => "INFO",
graph_check_workflow_query::ViolationLevel::Other(_) => "UNKNOWN",
};
write!(f, "{}", printable)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,29 @@ query SubgraphCheckWorkflowQuery($workflowId: ID!, $graphId: ID!) {
}
}
}
... on CustomCheckTask {
result {
violations {
coordinate
level
message
rule
sourceLocations {
start {
byteOffset
column
line
}
end {
byteOffset
column
line
}
subgraphName
}
}
}
}
... on ProposalsCheckTask {
didOverrideProposalsCheckTask
proposalCoverage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ use graphql_client::*;
use crate::blocking::StudioClient;
use crate::operations::subgraph::check_workflow::types::QueryResponseData;
use crate::shared::{
CheckWorkflowResponse, Diagnostic, DownstreamCheckResponse, GraphRef, LintCheckResponse,
OperationCheckResponse, ProposalsCheckResponse, ProposalsCheckSeverityLevel, ProposalsCoverage,
RelatedProposal, SchemaChange,
CheckWorkflowResponse, CustomCheckResponse, Diagnostic, DownstreamCheckResponse, GraphRef,
LintCheckResponse, OperationCheckResponse, ProposalsCheckResponse, ProposalsCheckSeverityLevel,
ProposalsCoverage, RelatedProposal, SchemaChange, Violation,
};
use crate::RoverClientError;

use super::types::*;

use self::subgraph_check_workflow_query::SubgraphCheckWorkflowQueryGraphCheckWorkflowTasksOn::{
CompositionCheckTask, DownstreamCheckTask, LintCheckTask, OperationsCheckTask,
CompositionCheckTask, CustomCheckTask, DownstreamCheckTask, LintCheckTask, OperationsCheckTask,
ProposalsCheckTask,
};
use self::subgraph_check_workflow_query::{
CheckWorkflowStatus, CheckWorkflowTaskStatus, ProposalStatus,
SubgraphCheckWorkflowQueryGraphCheckWorkflowTasksOnCustomCheckTaskResult,
SubgraphCheckWorkflowQueryGraphCheckWorkflowTasksOnDownstreamCheckTaskResults,
SubgraphCheckWorkflowQueryGraphCheckWorkflowTasksOnLintCheckTaskResult,
SubgraphCheckWorkflowQueryGraphCheckWorkflowTasksOnOperationsCheckTaskResult,
Expand Down Expand Up @@ -111,6 +112,12 @@ fn get_check_response_from_data(
let mut proposals_result: Option<ProposalsCheckTaskUnion> = None;
let mut proposals_target_url = None;

let mut custom_status = None;
let mut custom_result: Option<
SubgraphCheckWorkflowQueryGraphCheckWorkflowTasksOnCustomCheckTaskResult,
> = None;
let mut custom_target_url = None;

let mut downstream_status = None;
let mut downstream_target_url = None;
let mut downstream_result: Option<
Expand Down Expand Up @@ -158,6 +165,11 @@ fn get_check_response_from_data(
proposals_target_url = task.target_url;
proposals_result = Some(typed_task);
}
CustomCheckTask(typed_task) => {
custom_status = Some(task.status);
custom_target_url = task.target_url;
custom_result = typed_task.result;
}
DownstreamCheckTask(typed_task) => {
downstream_status = Some(task.status);
downstream_target_url = task.target_url;
Expand Down Expand Up @@ -213,6 +225,11 @@ fn get_check_response_from_data(
proposals_status,
proposals_result,
),
maybe_custom_response: get_custom_response_from_result(
custom_status,
custom_target_url,
custom_result,
),
maybe_downstream_response: get_downstream_response_from_result(
downstream_status,
downstream_target_url,
Expand Down Expand Up @@ -387,6 +404,44 @@ fn get_proposals_response_from_result(
}
}

fn get_custom_response_from_result(
task_status: Option<CheckWorkflowTaskStatus>,
target_url: Option<String>,
results: Option<SubgraphCheckWorkflowQueryGraphCheckWorkflowTasksOnCustomCheckTaskResult>,
) -> Option<CustomCheckResponse> {
match results {
Some(result) => {
let violations: Vec<Violation> = result
.violations
.iter()
.map(|violation| {
let start_line = if let Some(source_locations) = &violation.source_locations {
if !source_locations.is_empty() {
Some(source_locations[0].start.line)
} else {
None
}
} else {
None
};
Violation {
level: violation.level.to_string(),
message: violation.message.clone(),
start_line,
rule: violation.rule.clone(),
}
})
.collect();
Some(CustomCheckResponse {
task_status: task_status.into(),
target_url,
violations,
})
}
None => None,
}
}

fn get_downstream_response_from_result(
task_status: Option<CheckWorkflowTaskStatus>,
target_url: Option<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,15 @@ impl Display for subgraph_check_workflow_query::LintRule {
Debug::fmt(self, f)
}
}

impl fmt::Display for subgraph_check_workflow_query::ViolationLevel {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let printable = match &self {
subgraph_check_workflow_query::ViolationLevel::WARNING => "WARNING",
subgraph_check_workflow_query::ViolationLevel::ERROR => "ERROR",
subgraph_check_workflow_query::ViolationLevel::INFO => "INFO",
subgraph_check_workflow_query::ViolationLevel::Other(_) => "UNKNOWN",
};
write!(f, "{}", printable)
}
}
Loading

0 comments on commit 9bccc19

Please sign in to comment.