From efb05693c10d8d3734baddb7ba6dee46f284d553 Mon Sep 17 00:00:00 2001 From: Sunli Date: Thu, 22 Sep 2022 23:34:49 +0800 Subject: [PATCH] Federation v1 is no longer supported --- README.md | 4 ++-- docs/en/src/apollo_federation.md | 22 +--------------------- src/lib.rs | 2 +- src/registry/export_sdl.rs | 10 ++++------ src/registry/mod.rs | 1 - src/schema.rs | 11 ----------- tests/federation.rs | 1 - 7 files changed, 8 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 62eee670..dfd955a4 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ async fn main() { - Batch queries - Apollo Persisted Queries - Apollo Tracing extension -- Apollo Federation +- Apollo Federation(v2) > **Note**: Minimum supported Rust version: 1.59.0 or later @@ -95,7 +95,7 @@ Integrations are what glue `async-graphql` with your web server, here are provid This crate offers the following features, all of which are not activated by default: | feature | enables | -| :----------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +|:-------------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | **`apollo_tracing`** | Enable the [Apollo tracing extension](extensions/struct.ApolloTracing.html). | | **`apollo_persisted_queries`** | Enable the [Apollo persisted queries extension](extensions/apollo_persisted_queries/struct.ApolloPersistedQueries.html). | | **`log`** | Enable the [logger extension](extensions/struct.Logger.html). | diff --git a/docs/en/src/apollo_federation.md b/docs/en/src/apollo_federation.md index 6f8b7f7d..2997a5aa 100644 --- a/docs/en/src/apollo_federation.md +++ b/docs/en/src/apollo_federation.md @@ -2,7 +2,7 @@ `Apollo Federation` is a `GraphQL` API gateway which can combine multiple GraphQL services, allowing each service to implement the subset of the API it is responsible for. You can read more in the [official documentation](https://www.apollographql.com/docs/apollo-server/federation/introduction). -`Async-graphql` supports all the functionality of `Apollo Federation`, but some modifications to your `Schema` are required. +`Async-graphql` supports all the functionality of `Apollo Federation v2`, but some modifications to your `Schema` are required. - You can use the `extends` property declaration on `async_graphql::Object` and `async_graphql::Interface` to extend a type offered by another implementing service. @@ -20,26 +20,6 @@ - The `override` directive is used to indicate that a field is now to be resolved by the current subgraph instead of the named subgraph. -- The `link` directive is needed in order to indicate that the subgraph is Federation v2 compatible, enabling the `shareable`, `inaccessable`, and `override` directives. - -## Enabling Federation v2 using the link directive - -async-graphql provides a configuration function `enable_apollo_fed2_link` on the schema builder to have it print out an `extend schema` element with an appropriately configured `link` directive whenever the federation schema is requested. - -```rust -Schema::build(Query, EmptyMutation, EmptySubscription) - .enable_apollo_fed2_link() - .finish() -``` - -and the following (or similar) will be attached to the schema: -``` -extend schema @link( - url: "https://specs.apollo.dev/federation/v2.0", - import: ["@key", "@tag", "@shareable", "@inaccessible", "@override", "@external", "@provides", "@requires"] -) -``` - ## Entity lookup function ```rust diff --git a/src/lib.rs b/src/lib.rs index 41ff53d7..31ed83fc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -51,7 +51,7 @@ //! * Apollo Tracing extension //! * Limit query complexity/depth //! * Error Extensions -//! * Apollo Federation +//! * Apollo Federation(v2) //! * Batch Queries //! * Apollo Persisted Queries //! diff --git a/src/registry/export_sdl.rs b/src/registry/export_sdl.rs index be38f43b..b613f4ab 100644 --- a/src/registry/export_sdl.rs +++ b/src/registry/export_sdl.rs @@ -112,12 +112,10 @@ impl Registry { } if options.federation { - 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(); - writeln!(sdl, ")").ok(); - } + 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(); + writeln!(sdl, ")").ok(); } else { writeln!(sdl, "schema {{").ok(); writeln!(sdl, "\tquery: {}", self.query_type).ok(); diff --git a/src/registry/mod.rs b/src/registry/mod.rs index 5a6e6f34..cf67b893 100644 --- a/src/registry/mod.rs +++ b/src/registry/mod.rs @@ -423,7 +423,6 @@ pub struct Registry { pub subscription_type: Option, pub introspection_mode: IntrospectionMode, pub enable_federation: 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 adcac107..39769ae3 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -173,16 +173,6 @@ 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. - #[must_use] - pub fn enable_apollo_fed2_link(mut self) -> Self { - self.registry.enable_apollo_link = true; - self - } - /// Make the Federation SDL include subscriptions. /// /// Note: Not included by default, in order to be compatible with Apollo @@ -389,7 +379,6 @@ where }, introspection_mode: IntrospectionMode::Enabled, enable_federation: false, - enable_apollo_link: false, federation_subscription: false, ignore_name_conflicts, }; diff --git a/tests/federation.rs b/tests/federation.rs index 26775617..ff1d7c3c 100644 --- a/tests/federation.rs +++ b/tests/federation.rs @@ -605,7 +605,6 @@ pub async fn test_link_directive() { } let schema_sdl = Schema::build(Query, EmptyMutation, EmptySubscription) - .enable_apollo_fed2_link() .finish() .sdl_with_options(SDLExportOptions::new().federation());