Overview
Router-level feature flags let you swap a subgraph at request time without a redeploy. Each flag defines a replacement subgraph. When a request includes the matching header or cookie, the router resolves the target subgraph to the flagged replacement.For a primer on Cosmo feature flags and rollout strategies, see the concepts guide.
Manage feature flags with Cosmo (recommended)
The recommended way to manage and deploy feature flags is with the wgc CLI and Cosmo Cloud (or self-hosted Control Plane). You create feature subgraphs, compose them into a feature flag viawgc feature-flag create, and Cosmo produces the feature-flag configuration as part of the router config. The router then receives this configuration when it fetches its config from the Control Plane—no local YAML needed.
To get started:
- Create a feature subgraph with
wgc feature-subgraph create. - Create and enable a feature flag with
wgc feature-flag create, attaching the feature subgraph(s) and labels for your federated graph(s).
Alternative: Local composition
If you run the router using a local config file (e.g.router-compose.yaml)
instead of fetching config from Cosmo, you can still use feature flags. Define feature_flags and feature_graphs
in the same input file you pass to wgc router compose. The compose command will include the flag configuration in the generated router config. For the input file structure and a full example, see Compose — Feature flags (optional).
Key points:
feature_flags[*].nameis the value you will send from the client (case sensitive).feature_graphs[*].subgraph_namemust match the corresponding entry undersubgraphs(checkoutin the example).- The router swaps the referenced
subgraph_namewith the replacement defined infeature_graphswhen the flag is active.
Name feature flag schemas using the
feature-flag_*.graphql convention and check in an empty placeholder subgraph file to keep composition predictable.Trigger the Flag
Activate a flag by sending the header (or matching cookie) with the desired flag name. All requests that include the header are routed through the replacement subgraph.X-Feature-Flag: test_checkout, it composes the operation against the replacement schema and forwards traffic to the routing URLs declared in the flag configuration.