Skip to content

Commit

Permalink
Clarify composition rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Meschreiber committed Aug 21, 2023
1 parent 249c158 commit 85f7694
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions docs/source/schema/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,16 @@ If you want to define a custom schema directive to _transform_ your executable s

### In subgraphs

> ⚠️ **Important considerations**
>
> Before you use directives in a federated graph, make sure to consider the following:
>
> - Custom directives are _not_ included in your graph's composed supergraph schema. The composition process strips all subgraph directives. Only a given subgraph is aware of its own directives.
> - If multiple subgraphs can resolve a particular field, each subgraph should almost always apply the exact same set of custom directives (with the exact same definition) to that field. Otherwise, the behavior of that field might vary depending on _which_ subgraph resolves it.
> - Because directives are specific to individual subgraphs, it's technically valid for different subgraphs to define the _same_ directive with _different_ logic. As stated in the previous point, if a custom directive is used in multiple subgraphs to resolve a particular field, you should almost always use define the same directive with the same logic across subgraphs. Composition does not detect or warn about such inconsistencies.
Before you use custom directives in a federated graph, make sure to consider the following:
- If multiple subgraphs can resolve a particular field, each subgraph should almost always apply the exact same set of custom directives (with the exact same definition) to that field. Otherwise, the behavior of that field might vary depending on _which_ subgraph resolves it.
- Because directives are specific to individual subgraphs, it's technically valid for different subgraphs to define the _same_ directive with _different_ logic. As stated in the previous point, if a custom directive is used in multiple subgraphs to resolve a particular field, you should define the same directive with the same logic across subgraphs. _Composition does not detect or warn about such inconsistencies._
- The composition process treats [executable (client-side)](/federation/federated-types/composition/#executable-directives) and [type system (server-side) directives](/federation/federated-types/composition/#type-system-directives) differently:
- An executable directive is composed into the supergraph schema if:
- All subgraphs define the directive identically
- The directive is not included in any [`@composeDirective`](/federation/federated-types/federated-directives/#composedirective) directives
- Type system directives are not composed into the supergraph schema, but they can provide information to the router via the [`@composeDirective`](/federation/federated-types/federated-directives/#composedirective) directive.

#### Transformer functions

[As our example shows](https://github.com/apollographql/docs-examples/blob/main/apollo-server/v4/custom-directives/upper-case-directive/src/index.ts), in Apollo Server 3 and 4 you can define a **transformer function** for each of your subgraph schema's custom directives.

Expand Down

0 comments on commit 85f7694

Please sign in to comment.