diff --git a/src/core/blueprint/index.rs b/src/core/blueprint/index.rs index 3631b932ad..f14da66f9d 100644 --- a/src/core/blueprint/index.rs +++ b/src/core/blueprint/index.rs @@ -187,6 +187,8 @@ mod test { use crate::core::blueprint::Blueprint; use crate::core::config::ConfigModule; use crate::include_config; + use insta::assert_snapshot; + use crate::federation::compile_service; fn setup() -> Index { let config = include_config!("./fixture/all-constructs.graphql").unwrap(); @@ -261,4 +263,18 @@ mod test { assert!(index.is_type_implements("Post", "Post")); assert!(!index.is_type_implements("Node", "User")); } + + #[test] + fn test_compile_service_snapshot() { + let config = include_config!("./fixture/all-constructs.graphql").unwrap(); + let cfg_module = ConfigModule::from(config); + + let result = compile_service(&cfg_module); + + if let Valid::Success(IR::Service(output)) = result { + assert_snapshot!(output); + } else { + panic!("Expected Valid::Success"); + } + } } diff --git a/src/core/blueprint/operators/apollo_federation.rs b/src/core/blueprint/operators/federation.rs similarity index 85% rename from src/core/blueprint/operators/apollo_federation.rs rename to src/core/blueprint/operators/federation.rs index a078e6fe8c..70cc2f4845 100644 --- a/src/core/blueprint/operators/apollo_federation.rs +++ b/src/core/blueprint/operators/federation.rs @@ -80,26 +80,24 @@ pub fn compile_entity_resolver(inputs: CompileEntityResolver<'_>) -> Valid Valid { - let mut sdl = - crate::core::document::print(filter_conflicting_directives(config.config().into())); - - writeln!(sdl).ok(); - // Add tailcall specific definitions to the sdl output - writeln!( - sdl, - "{}", - crate::core::document::print(filter_conflicting_directives(Config::graphql_schema())) - ) - .ok(); - writeln!(sdl).ok(); - // Mark subgraph as Apollo federation v2 compatible according to [docs](https://www.apollographql.com/docs/apollo-server/using-federation/apollo-subgraph-setup/#2-opt-in-to-federation-2) - // (borrowed from async_graphql) - writeln!(sdl, "extend schema @link(").ok(); - writeln!(sdl, "\turl: \"https://specs.apollo.dev/federation/v2.3\",").ok(); - writeln!(sdl, "\timport: [\"@key\", \"@tag\", \"@shareable\", \"@inaccessible\", \"@override\", \"@external\", \"@provides\", \"@requires\", \"@composeDirective\", \"@interfaceObject\"]").ok(); - writeln!(sdl, ")").ok(); - - Valid::succeed(IR::Service(sdl)) + let mut service_doc = crate::core::document::print(filter_conflicting_directives( + config.config().into(), + )); + + let additional_schema = crate::core::document::print(filter_conflicting_directives( + Config::graphql_schema(), + )); + + let federation_v2_extension = r#" + extend schema @link( + url: "https://specs.apollo.dev/federation/v2.3", + import: ["@key", "@tag", "@shareable", "@inaccessible", "@override", "@external", "@provides", "@requires", "@composeDirective", "@interfaceObject"] + ) + "#; + + writeln!(service_doc, "{}\n{}", additional_schema, federation_v2_extension).ok(); + + Valid::succeed(IR::Service(service_doc)) } fn filter_conflicting_directives(sd: ServiceDocument) -> ServiceDocument { diff --git a/src/core/blueprint/operators/mod.rs b/src/core/blueprint/operators/mod.rs index 2b4842899e..343eff8150 100644 --- a/src/core/blueprint/operators/mod.rs +++ b/src/core/blueprint/operators/mod.rs @@ -1,4 +1,4 @@ -mod apollo_federation; +mod federation; mod call; mod enum_alias; mod expr; @@ -9,7 +9,7 @@ mod js; mod modify; mod protected; -pub use apollo_federation::*; +pub use federation::*; pub use call::*; pub use enum_alias::*; pub use expr::*;