From 2803cf312886209f5c15949a31c837cb3aadc646 Mon Sep 17 00:00:00 2001 From: aidan coyne Date: Thu, 22 Sep 2022 09:48:10 -0500 Subject: [PATCH] Revert "default to printing the applicaiton of the link directive" This reverts commit 393184a23c5c8af19efc66a55c96dfda18560c8e. --- src/registry/export_sdl.rs | 2 +- src/registry/mod.rs | 2 +- src/schema.rs | 14 +++++++------- tests/federation.rs | 8 +++----- .../test_entity_inaccessible.schema.graphql | 4 ---- tests/schemas/test_entity_tag.schema.graphql | 4 ---- ...ink.graphqls => test_fed2_link.schema.graphqls} | 4 ++++ 7 files changed, 16 insertions(+), 22 deletions(-) rename tests/schemas/{test_suppress_link.graphqls => test_fed2_link.schema.graphqls} (57%) diff --git a/src/registry/export_sdl.rs b/src/registry/export_sdl.rs index 92561e10..be38f43b 100644 --- a/src/registry/export_sdl.rs +++ b/src/registry/export_sdl.rs @@ -112,7 +112,7 @@ impl Registry { } if options.federation { - if !self.suppress_apollo_link { + if self.enable_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 3d493b6a..5a6e6f34 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 suppress_apollo_link: bool, + pub enable_apollo_link: bool, pub federation_subscription: bool, pub ignore_name_conflicts: HashSet, } diff --git a/src/schema.rs b/src/schema.rs index 6c6c9875..adcac107 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -173,13 +173,13 @@ impl SchemaBuilder self } - /// 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. + /// 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. #[must_use] - pub fn suppress_apollo_link(mut self) -> Self { - self.registry.suppress_apollo_link = true; + pub fn enable_apollo_fed2_link(mut self) -> Self { + self.registry.enable_apollo_link = true; self } @@ -389,7 +389,7 @@ where }, introspection_mode: IntrospectionMode::Enabled, enable_federation: false, - suppress_apollo_link: false, + enable_apollo_link: false, federation_subscription: false, ignore_name_conflicts, }; diff --git a/tests/federation.rs b/tests/federation.rs index 624a98f6..0acfa38d 100644 --- a/tests/federation.rs +++ b/tests/federation.rs @@ -547,10 +547,8 @@ 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_suppress_link_directive() { +pub async fn test_link_directive() { struct User { id: ID, } @@ -616,12 +614,12 @@ pub async fn test_suppress_link_directive() { } let schema_sdl = Schema::build(Query, EmptyMutation, EmptySubscription) - .suppress_apollo_link() + .enable_apollo_fed2_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_suppress_link.graphqls"); + .join("tests/schemas/test_fed2_link.schema.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 93f8f71a..7da5863f 100644 --- a/tests/schemas/test_entity_inaccessible.schema.graphql +++ b/tests/schemas/test_entity_inaccessible.schema.graphql @@ -65,7 +65,3 @@ 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 1106ac6b..d7bdf7aa 100644 --- a/tests/schemas/test_entity_tag.schema.graphql +++ b/tests/schemas/test_entity_tag.schema.graphql @@ -65,7 +65,3 @@ 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_suppress_link.graphqls b/tests/schemas/test_fed2_link.schema.graphqls similarity index 57% rename from tests/schemas/test_suppress_link.graphqls rename to tests/schemas/test_fed2_link.schema.graphqls index eb878e1b..dfb4a959 100644 --- a/tests/schemas/test_suppress_link.graphqls +++ b/tests/schemas/test_fed2_link.schema.graphqls @@ -20,3 +20,7 @@ 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"] +)