Federation v1 is no longer supported

This commit is contained in:
Sunli 2022-09-22 23:34:49 +08:00
parent d75d79769a
commit efb05693c1
7 changed files with 8 additions and 43 deletions

View File

@ -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). |

View File

@ -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

View File

@ -51,7 +51,7 @@
//! * Apollo Tracing extension
//! * Limit query complexity/depth
//! * Error Extensions
//! * Apollo Federation
//! * Apollo Federation(v2)
//! * Batch Queries
//! * Apollo Persisted Queries
//!

View File

@ -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();

View File

@ -423,7 +423,6 @@ pub struct Registry {
pub subscription_type: Option<String>,
pub introspection_mode: IntrospectionMode,
pub enable_federation: bool,
pub enable_apollo_link: bool,
pub federation_subscription: bool,
pub ignore_name_conflicts: HashSet<String>,
}

View File

@ -173,16 +173,6 @@ 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.
#[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,
};

View File

@ -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());