Skip to content

Commit

Permalink
tailcallhq#2904-cleanUp: apollo_federation
Browse files Browse the repository at this point in the history
  • Loading branch information
ayusham001 committed Sep 25, 2024
1 parent 551b50e commit 6080a0f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
16 changes: 16 additions & 0 deletions src/core/blueprint/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,24 @@ pub fn compile_entity_resolver(inputs: CompileEntityResolver<'_>) -> Valid<IR, S
}

pub fn compile_service(config: &ConfigModule) -> Valid<IR, String> {
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 {
Expand Down
4 changes: 2 additions & 2 deletions src/core/blueprint/operators/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod apollo_federation;
mod federation;
mod call;
mod enum_alias;
mod expr;
Expand All @@ -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::*;
Expand Down

0 comments on commit 6080a0f

Please sign in to comment.