Skip to main content
IMPORTANT: Please note that since this command runs locally, the subgraphs may or may not exist on the control plane. It is recommended to not use this for production, if you plan to use the Cosmo platform as schema registry or analytics platform. For production, you can fetch the latest router execution config for your federated graph using the fetch command instead.

Usage

Description

The npx wgc router compose command allows you to compose subgraphs and build a router execution config locally without a connection to the control plane.

Options

  • -i, --input: The path to the input config file that contains information about your subgraphs.
  • -o, --out : Destination file for the router config. Prints to standard output if not provided.
  • --suppress-warnings: This flag suppresses any warnings produced by composition.
  • --split-configs-enabled: This flag enables splitting the router config into multiple files.
  • --exclude [tags...]: Schema elements with these tags will be excluded from the composed schema. Providing exclude and/or include tags produces a contract of the supergraph rather than the full supergraph.
  • --include [tags...]: Schema elements with these tags will be included in the composed schema. Providing exclude and/or include tags produces a contract of the supergraph rather than the full supergraph.
  • --disable-base-contract: Specifies whether a contract for the base federated graph should be created. Yields an error if supplied without any included or excluded tags.
  • --contract-feature-flag-names [feature-flag-names...]: Specifies that a contract for one or more specific feature flags should be created. Yields an error if supplied without any included or excluded tags.
Note: The --split-configs-enabled flag requires Router version 0.315.0 or higher.

Input file structure

Feature flags (optional)

You can define feature flags in the input file so the composed router config includes alternate subgraphs when a flag is active. Each flag lists one or more feature_graphs that describe the replacement subgraph to serve when the flag is enabled (e.g. via the X-Feature-Flag header). For an overview of how the router uses feature flags, see Feature Flags.

Contracts (optional)

By default, compose produces the full supergraph. Passing --exclude and/or --include produces a Schema Contract of that supergraph instead. The filtering is driven by the @tag directives applied to your subgraph schemas.
  • --exclude removes every schema element tagged with any of the given tags.
  • --include keeps only the schema elements tagged with any of the given tags, plus the elements required to resolve them.
Both options accept multiple tags and can be combined. By default, only a contract of the base federated graph will be generated, which can be be disabled by --disable-base-contract. In addition (or alternatively), contract can be generated for specific feature flag names if passed to --contract-feature-flag-names. Only feature flags passed as an argument to this option will generate contracts. Defining tags but disabling the base contract and not providing any feature flag names will produce an error. This is the local equivalent of a contract graph created with wgc contract create. Use it to test a contract with your router without a control plane connection.
Compose a contract that excludes all schema elements tagged internal or experimental.
Compose a contract that includes only the schema elements tagged public.
Compose a contract for feature flags “ff1” and “ff2” (but not the base federated graph) that includes only the schema elements tagged public but excludes any nested schema elements tagged ‘internal.
Note: Contract filtering relies on the @tag directive. Make sure @tag is imported in each subgraph schema that uses it.

Examples

Compose subgraphs mentioned in the input file graph.yaml
Compose subgraphs mentioned in graph.yaml and write it to router.json

Notes

  • The npx wgc router compose command does not interact with the control plane and completely runs locally.
  • When using the --split-configs-enabled option, the --out is always treated as a directory.