Skip to content

Commit

Permalink
tailcallhq#2904-cleanUp: apollo_federation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ayusham001 committed Sep 25, 2024
1 parent 7a7be31 commit 0d49be3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/core/blueprint/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ mod test {

let result = compile_service(&cfg_module);

if let Valid::Success(IR::Service(output)) = result {
if let Ok(IR::Service(output)) = result {
assert_snapshot!(output);
} else {
panic!("Expected Valid::Success");
Expand Down
53 changes: 34 additions & 19 deletions src/core/blueprint/operators/federation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,40 @@ pub fn compile_entity_resolver(inputs: CompileEntityResolver<'_>) -> Valid<IR, S
.map_to(IR::Entity(resolver_by_type))
}

pub fn compile_service(config: &ConfigModule) -> Valid<IR, String> {
let mut sdl = crate::core::document::print(filter_conflicting_directives(config.config().into()));

let additional_defs = crate::core::document::print(filter_conflicting_directives(Config::graphql_schema()));

let federation_v2_directives = r#"
extend schema @link(
url: "https://specs.apollo.dev/federation/v2.3",
import: [
"@key", "@tag", "@shareable", "@inaccessible",
"@override", "@external", "@provides", "@requires",
"@composeDirective", "@interfaceObject"
]
)
"#;

writeln!(sdl, "{}{}", additional_defs, federation_v2_directives).ok();

Valid::succeed(IR::Service(sdl))
pub fn compile_service(config: &ConfigModule) -> Result<Valid<IR>, String> {
let mut service_doc = ServiceDocument::from(config.config().into());

let federation_directive = DirectiveDefinition {
name: "link".to_string(),
arguments: vec![
Argument {
name: "url".to_string(),
value: Value::String("https://specs.apollo.dev/federation/v2.3".to_string()),
},
Argument {
name: "import".to_string(),
value: Value::List(vec![
Value::String("@key".to_string()),
Value::String("@tag".to_string()),
Value::String("@shareable".to_string()),
Value::String("@inaccessible".to_string()),
Value::String("@override".to_string()),
Value::String("@external".to_string()),
Value::String("@provides".to_string()),
Value::String("@requires".to_string()),
Value::String("@composeDirective".to_string()),
Value::String("@interfaceObject".to_string()),
]),
},
],
};

service_doc.add_directive(federation_directive);

let mut complete_sdl = String::new();
writeln!(complete_sdl, "{}", crate::core::document::print(service_doc))?;

Ok(Valid::succeed(IR::Service(complete_sdl)))
}

fn filter_conflicting_directives(sd: ServiceDocument) -> ServiceDocument {
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/operators/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod federation;
pub mod federation;
mod call;
mod enum_alias;
mod expr;
Expand Down

0 comments on commit 0d49be3

Please sign in to comment.