From 515d03da31f095f2674b5c9e4265beee541e0b49 Mon Sep 17 00:00:00 2001 From: Dylan Anthony Date: Fri, 2 May 2025 11:28:38 -0600 Subject: [PATCH 1/2] Support transformed subgraphs for connectors auto-upgrade --- Cargo.lock | 17 ++++---- Cargo.toml | 2 +- apollo-composition/Cargo.toml | 2 +- apollo-composition/src/lib.rs | 81 +++++++++++++++++++---------------- 4 files changed, 55 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ee3472cb..9953da16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,9 +38,9 @@ checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" [[package]] name = "apollo-compiler" -version = "1.27.0" +version = "1.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bb8a0d8a54b31d8a9efcc25d4be3d949d823e8105a710861d6d4a4ef811b5f2" +checksum = "b3eb9f97e5cc573361cdeb65204fbb7c459c9a9d5a6bec48ee37355c642a06ad" dependencies = [ "ahash", "apollo-parser", @@ -49,7 +49,7 @@ dependencies = [ "rowan", "serde", "serde_json_bytes", - "thiserror 1.0.69", + "thiserror 2.0.8", "triomphe", "typed-arena", ] @@ -66,9 +66,8 @@ dependencies = [ [[package]] name = "apollo-federation" -version = "2.2.0-rc.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "155f96556b840c9c0b3f722e61f7eb04e3c348c486605a14b8709cb39b02efec" +version = "2.2.0" +source = "git+https://github.com/apollographql/router?branch=dylan%2Fauto-upgrade-connect-0.1#d57ab45d6139b027b2634e22413f84af540da1c4" dependencies = [ "apollo-compiler", "derive_more", @@ -91,7 +90,7 @@ dependencies = [ "shape", "strum", "strum_macros", - "thiserror 1.0.69", + "thiserror 2.0.8", "time", "tracing", "url", @@ -128,9 +127,9 @@ dependencies = [ [[package]] name = "ariadne" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31beedec3ce83ae6da3a79592b3d8d7afd146a5b15bb9bb940279aced60faa89" +checksum = "36f5e3dca4e09a6f340a61a0e9c7b61e030c69fc27bf29d73218f7e5e3b7638f" dependencies = [ "concolor", "unicode-width", diff --git a/Cargo.toml b/Cargo.toml index dbee90a6..0fb76176 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,4 +3,4 @@ members = ["apollo-federation-types", "apollo-composition"] resolver = "2" [workspace.dependencies] -apollo-compiler = "1.0.0-beta.24" \ No newline at end of file +apollo-compiler = "1.28.0" \ No newline at end of file diff --git a/apollo-composition/Cargo.toml b/apollo-composition/Cargo.toml index 0e789ced..82935db7 100644 --- a/apollo-composition/Cargo.toml +++ b/apollo-composition/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/apollographql/federation-rs/" [dependencies] apollo-compiler = { workspace = true } -apollo-federation = { version = "=2.2.0-rc.0", features = ["connect_v0.2"] } +apollo-federation = { version = "=2.2.0", git = "https://github.com/apollographql/router", branch = "dylan/auto-upgrade-connect-0.1" } apollo-federation-types = { version = "0.15.3", path = "../apollo-federation-types", features = [ "composition", ] } diff --git a/apollo-composition/src/lib.rs b/apollo-composition/src/lib.rs index 735cc7cc..3633e1ed 100644 --- a/apollo-composition/src/lib.rs +++ b/apollo-composition/src/lib.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use std::iter::once; -use apollo_compiler::schema::ExtendedType; +use apollo_compiler::{schema::ExtendedType, Schema}; use apollo_federation::sources::connect::{ expand::{expand_connectors, Connectors, ExpansionResult}, validation::{validate, Severity as ValidationSeverity, ValidationResult}, @@ -66,37 +66,43 @@ pub trait HybridComposition { /// 3. Run Rust-based validation on the supergraph /// 4. Call [`validate_satisfiability`] to run JavaScript-based validation on the supergraph async fn compose(&mut self, subgraph_definitions: Vec) { - let validation_results = subgraph_definitions - .iter() - .map(|subgraph| { - ( - subgraph.name.clone(), - validate(&subgraph.sdl, &subgraph.name), - ) - }) - .collect::>(); - let subgraph_validation_errors = validation_results - .iter() - .flat_map(|(name, validation_result)| { - validation_result - .errors - .iter() - .cloned() - .map(|validation_error| Issue { - code: validation_error.code.to_string(), - message: validation_error.message, - locations: validation_error + let mut subgraph_validation_errors = Vec::new(); + let mut parsed_schemas = HashMap::new(); + let subgraph_definitions = subgraph_definitions + .into_iter() + .map(|mut subgraph| { + let ValidationResult { + errors, + has_connectors, + schema, + transformed, + } = validate(subgraph.sdl, &subgraph.name); + subgraph.sdl = transformed; + for error in errors { + subgraph_validation_errors.push(Issue { + code: error.code.to_string(), + message: error.message, + locations: error .locations .into_iter() .map(|range| SubgraphLocation { - subgraph: Some(name.clone()), + subgraph: Some(subgraph.name.clone()), range: Some(range), }) .collect(), - severity: convert_severity(validation_error.code.severity()), + severity: convert_severity(error.code.severity()), }) + } + parsed_schemas.insert( + subgraph.name.clone(), + SubgraphSchema { + schema, + has_connectors, + }, + ); + subgraph }) - .collect::>(); + .collect(); let run_composition = subgraph_validation_errors .iter() @@ -115,7 +121,7 @@ pub trait HybridComposition { // Any issues with overrides are fatal since they'll cause errors in expansion, // so we return early if we see any. - let override_errors = validate_overrides(validation_results); + let override_errors = validate_overrides(parsed_schemas); if !override_errors.is_empty() { self.add_issues(override_errors.into_iter()); return; @@ -168,16 +174,20 @@ pub trait HybridComposition { } } +struct SubgraphSchema { + schema: Schema, + has_connectors: bool, +} + /// Validate overrides for connector-related subgraphs /// /// Overrides mess with the supergraph in ways that can be difficult to detect when /// expanding connectors; the supergraph may omit overridden fields and other shenanigans. /// To allow for a better developer experience, we check here if any connector-enabled subgraphs /// have fields overridden. -fn validate_overrides(schemas: impl IntoIterator) -> Vec { - let validations_by_subgraph_name = HashMap::<_, _>::from_iter(schemas); +fn validate_overrides(schemas: HashMap) -> Vec { let mut override_errors = Vec::new(); - for (subgraph_name, ValidationResult { schema, .. }) in validations_by_subgraph_name.iter() { + for (subgraph_name, SubgraphSchema { schema, .. }) in &schemas { // We need to grab all fields in the schema since only fields can have the @override // directive attached macro_rules! extract_directives { @@ -218,32 +228,31 @@ fn validate_overrides(schemas: impl IntoIterator Date: Fri, 2 May 2025 16:00:55 -0600 Subject: [PATCH 2/2] Update apollo-federation to dev branch --- Cargo.lock | 2 +- apollo-composition/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9953da16..b28d3f13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,7 +67,7 @@ dependencies = [ [[package]] name = "apollo-federation" version = "2.2.0" -source = "git+https://github.com/apollographql/router?branch=dylan%2Fauto-upgrade-connect-0.1#d57ab45d6139b027b2634e22413f84af540da1c4" +source = "git+https://github.com/apollographql/router?branch=dev#014a1750e4514db7269791e684ab25e911c44af3" dependencies = [ "apollo-compiler", "derive_more", diff --git a/apollo-composition/Cargo.toml b/apollo-composition/Cargo.toml index 82935db7..ac838b48 100644 --- a/apollo-composition/Cargo.toml +++ b/apollo-composition/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/apollographql/federation-rs/" [dependencies] apollo-compiler = { workspace = true } -apollo-federation = { version = "=2.2.0", git = "https://github.com/apollographql/router", branch = "dylan/auto-upgrade-connect-0.1" } +apollo-federation = { version = "=2.2.0", git = "https://github.com/apollographql/router", branch = "dev" } apollo-federation-types = { version = "0.15.3", path = "../apollo-federation-types", features = [ "composition", ] }