Definition
Arguments
Overview
The@composeDirective directive declares that another (custom) directive should be propagated into the router schema
(supergraph schema).
By default, only specific machinery directives are persisted in the federated graph; custom directives are not.
Usage
Behavior attempts to mirror that of Apollo.
Warnings are added in certain cases to provide extra context and ensure the desired effect is reached.
@link directive, the custom directive definition must also be added
to the subgraph schema importing that directive.
Please note that composition cannot cross-reference or verify the definitions declared in the feature URL and the
schema in any way.
Lastly, the name of the imported and defined directive (with leading @) must be provided as a value to the name
argument of a @composeDirective directive:
For brevity, “composing a directive” will henceforth serve as a substitute for “providing the name of an imported and
defined directive to the
name argument of a @composeDirective directive”.Edge cases
Multiple versions
For each subgraph that composes a directive in that subgraph, only the definition with the highest version will be propagated into the router schema. For example:Non-propagation
If a directive is not referenced in at least one subgraph that also composes that directive, declarations of that directive will not be propagated into the router schema even if the directive is used in other subgraphs. The directive definition, however, will still be propagated:Propagation from subgraphs that include but do not compose the directive
If at least one subgraph both composes and references a composed directive within that same subgraph, all declarations of that directive will (attempted to) be propagated to the router schema. This includes all declarations of the directive within subgraphs that do not explicitly compose it. For example:Directive de-duplication
If a composed directive is declared on the same coordinates across subgraphs, only unique declarations will be propagated. This behaviour is regardless of whether the directive definition is repeatable:Multiple unique directive declarations with a non-repeatable definition
If the highest version of the directive is not defined as repeatable, but the directive is declared on a node in multiple subgraphs with disparate arguments (where applicable), only the first encountered instance of the directive will be propagated into the router schema for that node. This behaviour will also produce a warning. For example:Incompatible inter-subgraph definitions
Upon federation, all declarations of a composed directive will be validated against the definition of the composed directive with the highest version. This means a directive that is valid in subgraph may no longer be valid in the router schema. Such cases produce a composition error:Errors
@composeDirective will produce composition errors if:
- The directive name supplied to the
nameargument is not imported through a@linkdirective. - The string supplied to the
nameargument does not start with@. - The user attempts to provide a federation directive (e.g.,
@key) as an argument. - Directive declarations are incompatible across subgraphs.