An example of how feature flags could be used to release an experimental feature to a subset of a federated graph’s consumers.
Package | Minimum version |
---|---|
wgc | 0.58.0 |
router | 0.95.0 |
MyGraph
, with the label matchers team=A
. MyGraph
has been successfully composed with two published subgraphs, users
and products
, which both define the labels team=A
. Here are the schemas:
Users service SDL
products
service. We want to extend the current functionality thus:
User
entity.
basket
field.
Product
type.
wgc feature-subgraph create
. Every feature subgraph is linked to the “base” or “original” subgraph that it intends to replace. In this case, the feature we wish to gradually introduce to our customers is within the products
service, so we pass products
(the name of the service) to the --subgraphs
parameter.
products-feature
can be published using wgc subgraph publish
:
wgc feature-flag create
. A feature flag must be created with the provision of at least one space-delimited feature subgraph name to the --feature-subgraphs
parameter. Defining labels with the --label
parameter dictates to which federated graphs the feature flag applies. Lastly, feature flags are disabled upon creation by default, unless the --enabled
flag is passed. Note that in the example command below, the labels match the label matchers of the federated graph MyGraph
.
my-flag
was created with the --enabled
flag, it will be enabled (activated) immediately upon creation. Consequently, two new compositions should have been triggered: a recomposition of the base federated graph and a composition that includes the enabled feature flag.
A successful feature flag composition will produce an embedded feature flag configuration within the base router execution configuration.
Header | Value |
---|---|
X-Feature-Flag | Name of the feature flag |
X-Feature-Flag
header. If the name of the feature flag is invalid, the default federated graph will be served. An example is shown below:
Header | Value |
---|---|
Cookie | feature_flag={name of the feature flag} |
Cookie
header in the format feature_flag={name of the feature flag}
. If the name of the feature flag is invalid, the default federated graph will be served. An example is shown below:
Product.name
field or mutate a User
with addProductToUserBasket
. When the header or cookie is not included, the base (non-feature flag) federated graph will be served.