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 options.federation {
|
||||||
if self.enable_apollo_link {
|
if !self.suppress_apollo_link {
|
||||||
writeln!(sdl, "extend schema @link(").ok();
|
writeln!(sdl, "extend schema @link(").ok();
|
||||||
writeln!(sdl, "\turl: \"https://specs.apollo.dev/federation/v2.0\",").ok();
|
writeln!(sdl, "\turl: \"https://specs.apollo.dev/federation/v2.0\",").ok();
|
||||||
writeln!(sdl, "\timport: [\"@key\", \"@tag\", \"@shareable\", \"@inaccessible\", \"@override\", \"@external\", \"@provides\", \"@requires\"]").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 subscription_type: Option<String>,
|
||||||
pub introspection_mode: IntrospectionMode,
|
pub introspection_mode: IntrospectionMode,
|
||||||
pub enable_federation: bool,
|
pub enable_federation: bool,
|
||||||
pub enable_apollo_link: bool,
|
pub suppress_apollo_link: bool,
|
||||||
pub federation_subscription: bool,
|
pub federation_subscription: bool,
|
||||||
pub ignore_name_conflicts: HashSet<String>,
|
pub ignore_name_conflicts: HashSet<String>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,13 +173,13 @@ impl<Query, Mutation, Subscription> SchemaBuilder<Query, Mutation, Subscription>
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enables printing the apollo federation 2 `@link` directive during
|
/// By default, schema export in the federation mode will now automatically
|
||||||
/// federation schema export; the directive is attached to an "extend
|
/// print out a `@link` directive attached to an `extend schema`
|
||||||
/// schema" element, and will have values set to ensure that
|
/// element. If you need to prevent this printing for any reason, you
|
||||||
/// the federation schema directives and types are named properly.
|
/// can use this method to prevent that printing.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn enable_apollo_fed2_link(mut self) -> Self {
|
pub fn suppress_apollo_link(mut self) -> Self {
|
||||||
self.registry.enable_apollo_link = true;
|
self.registry.suppress_apollo_link = true;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,7 +389,7 @@ where
|
||||||
},
|
},
|
||||||
introspection_mode: IntrospectionMode::Enabled,
|
introspection_mode: IntrospectionMode::Enabled,
|
||||||
enable_federation: false,
|
enable_federation: false,
|
||||||
enable_apollo_link: false,
|
suppress_apollo_link: false,
|
||||||
federation_subscription: false,
|
federation_subscription: false,
|
||||||
ignore_name_conflicts,
|
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]
|
#[tokio::test]
|
||||||
pub async fn test_link_directive() {
|
pub async fn test_suppress_link_directive() {
|
||||||
struct User {
|
struct User {
|
||||||
id: ID,
|
id: ID,
|
||||||
}
|
}
|
||||||
|
@ -614,12 +616,12 @@ pub async fn test_link_directive() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let schema_sdl = Schema::build(Query, EmptyMutation, EmptySubscription)
|
let schema_sdl = Schema::build(Query, EmptyMutation, EmptySubscription)
|
||||||
.enable_apollo_fed2_link()
|
.suppress_apollo_link()
|
||||||
.finish()
|
.finish()
|
||||||
.sdl_with_options(SDLExportOptions::new().federation());
|
.sdl_with_options(SDLExportOptions::new().federation());
|
||||||
|
|
||||||
let path = std::path::Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap())
|
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();
|
let expected_schema = std::fs::read_to_string(&path).unwrap();
|
||||||
if schema_sdl != expected_schema {
|
if schema_sdl != expected_schema {
|
||||||
std::fs::write(path, schema_sdl).unwrap();
|
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!]!
|
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
Block a user