diff --git a/src/registry/export_sdl.rs b/src/registry/export_sdl.rs index be38f43b..92561e10 100644 --- a/src/registry/export_sdl.rs +++ b/src/registry/export_sdl.rs @@ -112,7 +112,7 @@ impl Registry { } if options.federation { - if self.enable_apollo_link { + if !self.suppress_apollo_link { writeln!(sdl, "extend schema @link(").ok(); writeln!(sdl, "\turl: \"https://specs.apollo.dev/federation/v2.0\",").ok(); writeln!(sdl, "\timport: [\"@key\", \"@tag\", \"@shareable\", \"@inaccessible\", \"@override\", \"@external\", \"@provides\", \"@requires\"]").ok(); diff --git a/src/registry/mod.rs b/src/registry/mod.rs index 5a6e6f34..3d493b6a 100644 --- a/src/registry/mod.rs +++ b/src/registry/mod.rs @@ -423,7 +423,7 @@ pub struct Registry { pub subscription_type: Option, pub introspection_mode: IntrospectionMode, pub enable_federation: bool, - pub enable_apollo_link: bool, + pub suppress_apollo_link: bool, pub federation_subscription: bool, pub ignore_name_conflicts: HashSet, } diff --git a/src/schema.rs b/src/schema.rs index adcac107..6c6c9875 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -173,13 +173,13 @@ impl SchemaBuilder self } - /// Enables printing the apollo federation 2 `@link` directive during - /// federation schema export; the directive is attached to an "extend - /// schema" element, and will have values set to ensure that - /// the federation schema directives and types are named properly. + /// By default, schema export in the federation mode will now automatically + /// print out a `@link` directive attached to an `extend schema` + /// element. If you need to prevent this printing for any reason, you + /// can use this method to prevent that printing. #[must_use] - pub fn enable_apollo_fed2_link(mut self) -> Self { - self.registry.enable_apollo_link = true; + pub fn suppress_apollo_link(mut self) -> Self { + self.registry.suppress_apollo_link = true; self } @@ -389,7 +389,7 @@ where }, introspection_mode: IntrospectionMode::Enabled, enable_federation: false, - enable_apollo_link: false, + suppress_apollo_link: false, federation_subscription: false, ignore_name_conflicts, }; diff --git a/tests/federation.rs b/tests/federation.rs index 0acfa38d..624a98f6 100644 --- a/tests/federation.rs +++ b/tests/federation.rs @@ -547,8 +547,10 @@ pub async fn test_entity_inaccessible() { } } +// tests suppressing the link directive. note that test_entity_inaccessible and +// test_entity_tag now verify the default printing of the link directive. #[tokio::test] -pub async fn test_link_directive() { +pub async fn test_suppress_link_directive() { struct User { id: ID, } @@ -614,12 +616,12 @@ pub async fn test_link_directive() { } let schema_sdl = Schema::build(Query, EmptyMutation, EmptySubscription) - .enable_apollo_fed2_link() + .suppress_apollo_link() .finish() .sdl_with_options(SDLExportOptions::new().federation()); let path = std::path::Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()) - .join("tests/schemas/test_fed2_link.schema.graphqls"); + .join("tests/schemas/test_suppress_link.graphqls"); let expected_schema = std::fs::read_to_string(&path).unwrap(); if schema_sdl != expected_schema { std::fs::write(path, schema_sdl).unwrap(); diff --git a/tests/schemas/test_entity_inaccessible.schema.graphql b/tests/schemas/test_entity_inaccessible.schema.graphql index 7da5863f..93f8f71a 100644 --- a/tests/schemas/test_entity_inaccessible.schema.graphql +++ b/tests/schemas/test_entity_inaccessible.schema.graphql @@ -65,3 +65,7 @@ extend type Query { } +extend schema @link( + url: "https://specs.apollo.dev/federation/v2.0", + import: ["@key", "@tag", "@shareable", "@inaccessible", "@override", "@external", "@provides", "@requires"] +) diff --git a/tests/schemas/test_entity_tag.schema.graphql b/tests/schemas/test_entity_tag.schema.graphql index d7bdf7aa..1106ac6b 100644 --- a/tests/schemas/test_entity_tag.schema.graphql +++ b/tests/schemas/test_entity_tag.schema.graphql @@ -65,3 +65,7 @@ extend type Query { } +extend schema @link( + url: "https://specs.apollo.dev/federation/v2.0", + import: ["@key", "@tag", "@shareable", "@inaccessible", "@override", "@external", "@provides", "@requires"] +) diff --git a/tests/schemas/test_fed2_link.schema.graphqls b/tests/schemas/test_suppress_link.graphqls similarity index 57% rename from tests/schemas/test_fed2_link.schema.graphqls rename to tests/schemas/test_suppress_link.graphqls index dfb4a959..eb878e1b 100644 --- a/tests/schemas/test_fed2_link.schema.graphqls +++ b/tests/schemas/test_suppress_link.graphqls @@ -20,7 +20,3 @@ extend type User @key(fields: "id") { reviews: [Review!]! } -extend schema @link( - url: "https://specs.apollo.dev/federation/v2.0", - import: ["@key", "@tag", "@shareable", "@inaccessible", "@override", "@external", "@provides", "@requires"] -)