default to printing the applicaiton of the link directive
change to providing a method to opt-out of printing it.
This commit is contained in:
parent
406c6906b7
commit
393184a23c
|
@ -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();
|
||||
|
|
|
@ -423,7 +423,7 @@ pub struct Registry {
|
|||
pub subscription_type: Option<String>,
|
||||
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<String>,
|
||||
}
|
||||
|
|
|
@ -173,13 +173,13 @@ impl<Query, Mutation, Subscription> SchemaBuilder<Query, Mutation, Subscription>
|
|||
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,
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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"]
|
||||
)
|
||||
|
|
|
@ -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"]
|
||||
)
|
||||
|
|
|
@ -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"]
|
||||
)
|
Loading…
Reference in New Issue