What is a feature flag?

In WunderGraph Cosmo , feature flags work by creating toggle-able collections of “subgraph replacements”, known as feature subgraphs, for one or more supergraphs.

The three pieces

In summary, a feature flag is built from three things:

A normal subgraph that already composes your supergraph.

How they fit together

A feature subgraph does nothing on its own. It only takes effect once it is part of a feature flag and that flag is enabled. Toggling a feature flag is what swaps the feature subgraphs in for their base subgraphs.

When you enable a flag, Cosmo runs a fresh composition that includes the feature subgraphs, and embeds that result as a feature-flag configuration inside the router's execution config.

Core terminology

This course uses a few core GraphQL Federation terms. As a quick primer, here are the terms we will use in this course:

The overall approach: a way to combine many independently built GraphQL APIs into one unified API, allowing consumers to call a single endpoint instead of each service separately.

Our exercise (using WunderGraph Cosmo)

You'll also come across some vendor-specific terms, such as:

We'll self-host the router locally for this exercise, as described in the next lesson.

Why use feature flags?

Migrating functionality
  • How: Pull a capability out of a monolith into a new subgraph and evaluate the results. Once the outputs match and performance looks good, you promote the flag from shadow to a real rollout.
  • Why: De-risks migration efforts.
Incremental rollout
  • How: Ship a schema change to 1% of clients, watch your metrics, and ramp up only when it looks healthy.
  • Why: If something is wrong, you disable the flag instead of rolling back an entire deploy.
Schema evolution
  • How: Run more than one version of a subgraph's schema at the same time.
  • Why: Clients that opt into the flag see the new fields; everyone else keeps the stable schema until they are ready.
Dynamic configuration
  • How: Because the flag is chosen per request (via a header or cookie), you can drive it from a JWT claim, a cookie, or a gateway rule.
  • Why: Effectively a per-user or per-cohort toggle.
Staging environments
  • How: Instead of standing up a full parallel stack per developer, a single shared environment plus a feature flag can give each developer or team an isolated view of their in-progress schema.
  • Why: Reduces infrastructure overhead and lets developers collaborate or test safely in isolation.

What the router does not handle

An important boundary: the Cosmo Router is not responsible for deciding which percentage of traffic gets the flag.

The router simply reads a header or cookie on each request and serves the matching schema. Deciding which requests carry that header—1%, then 10%, then 100%—is the job of your load balancer, proxy, or gateway. We come back to this in the gradual-rollout lesson.


Task

Knowledge check

What is a feature subgraph?

A feature subgraph on its own, not part of any flag, will…

Who decides what percentage of traffic receives a feature flag?