Skip to main content

Enum is used as both an input and output but is inconsistently defined across inclusive subgraphs

When you receive an error like Enum X is used as both an input and output but is inconsistently defined across inclusive subgraphs it means you are publishing a change to an enum that is used as both an input and an output. The error lists:
  • each subgraph that defines the enum but does not define every enum value, with the missing values
  • each subgraph that uses the enum as an input, with the coordinates of the arguments, input fields, and directive arguments
  • each subgraph that uses the enum as an output, with the coordinates of the fields
For example:
Enum values declared with @inaccessible in any subgraph are not listed as missing. When publishing a new enum value to a subgraph, depending on whether that enum is used as an input, output, or both, incompatibilities and run-time issues could arise. For example, imagine Subgraph A defines an enum with value A, and it is used as an input. However, Subgraph B defines the same enum with values A and B, and it is used as an output. Composition cannot add value B to the federated graph because Subgraph A is unaware of value B and cannot accept it as a valid input. Similarly, composition also cannot remove value B from the federated graph because then returning B from Subgraph B would be invalid. In such an instance, the only way to prevent errors is to define the enum consistently across all subgraphs in which the enum appears. To solve this issue you should proceed as follows:
  • in the origin subgraph, add @inaccessible to Enum.NewValue
  • in each other subgraph that defines the enum, define Enum.NewValue (no directive)
  • after you have published the change to all subgraphs that define that enum, remove @inaccessible from the origin subgraph and publish the change
This migration approach, while cumbersome, ensures that the federated contract is respected at all times, keeping your router safe from any run-time errors.