Skip to content

Commit 29bcb09

Browse files
authored
docs: link directive (#3202)
Clarify required `@link` directive for Fed 2
1 parent a6eb01b commit 29bcb09

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

docs/shared/link-directive.mdx

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Subgraph schemas opt in to Federation v2 features by applying the `@link` directive to the `schema` type. You can optionally add an `import` list to this definition to include each federation-specific directive that the subgraph schema uses. In the example below, the schema uses the `@key` and `@shareable` directives:
2+
3+
```graphql
4+
extend schema
5+
@link(url: "https://specs.apollo.dev/federation/v2.0",
6+
import: ["@key", "@shareable"])
7+
```
8+
9+
<Tip>
10+
11+
You can use `@link` to distinguish between Federation v1 (no `@link`) and Federation v2 (required `@link`) schemas.
12+
13+
</Tip>

docs/source/reference/federation/directives.mdx

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ description: Reference for GraphQL federation directives including @key, @extend
66

77
import ProgressiveOverrideEnterprise from '../../../shared/progressive-override-enterprise.mdx';
88
import EnterpriseDirective from '../../../shared/enterprise-directive.mdx';
9+
import LinkDirective from '../../../shared/link-directive.mdx';
910

1011
Apollo Federation defines a collection of directives that you use in your subgraph schemas to enable certain features.
1112

@@ -73,6 +74,8 @@ type Book @fed__shareable {
7374

7475
As shown, custom namespace prefixes also end in two underscores.
7576

77+
## Managing schemas
78+
7679
<MinVersion version="2.0">
7780

7881
### The `@link` directive
@@ -90,6 +93,8 @@ directive @link(
9093

9194
This directive links definitions from an external specification to this schema. Every Federation 2 subgraph uses the `@link` directive to import the other federation-specific directives described in this article (see the syntax in [Importing directives](#importing-directives)).
9295

96+
<LinkDirective />
97+
9398
For more information on `@link`, see the [official spec](https://specs.apollo.dev/link/v1.0/).
9499

95100
## Managing types

docs/source/reference/federation/subgraph-spec.mdx

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ subtitle: Subgraph specification reference for server library developers
44
description: Learn about Apollo Federation 2 subgraph specifications, enhanced introspection, and entity field resolution for GraphQL server libraries.
55
---
66

7+
import LinkDirective from '../../../shared/link-directive.mdx';
8+
79
This content is provided for developers adding federated subgraph support to a GraphQL server library, and for anyone curious about the inner workings of federation. You do not need to read this if you're building a supergraph with existing [subgraph-compatible libraries](/graphos/reference/federation/compatible-subgraphs), such as Apollo Server.
810

911
Servers that are partially or fully compatible with this specification are tracked in Apollo's [subgraph compatibility repository](https://github.com/apollographql/apollo-federation-subgraph-compatibility).
@@ -13,6 +15,7 @@ For a GraphQL service to operate as an Apollo Federation 2 subgraph, it must do
1315
- Automatically extend its schema with all definitions listed in [Subgraph schema additions](#subgraph-schema-additions)
1416
- Correctly resolve the `Query._service` [enhanced introspection field](#fetch-service-capabilities)
1517
- Provide a mechanism for subgraph developers to resolve entity fields via the [`Query._entities` field](#resolving-entity-fields-with-query_entities)
18+
- Apply the [`@link` directive to the `schema` type](#apply-link-directive)
1619

1720
Each of these requirements is described in the sections below.
1821

@@ -408,6 +411,10 @@ For this reference resolver, the developer calls a `fetchProductByUPC` function,
408411

409412
Your subgraph library does not need to use this reference resolver pattern. It just needs to provide and document some pattern for defining entity-fetching logic.
410413

414+
## Apply @link directive
415+
416+
<LinkDirective />
417+
411418
## Glossary of schema additions
412419

413420
This section describes type and field definitions that a valid subgraph service must automatically add to its schema. These definitions are all listed above in [Subgraph schema additions](#subgraph-schema-additions).

0 commit comments

Comments
 (0)