> ## Documentation Index
> Fetch the complete documentation index at: https://wundergraphinc-alberto-router-651-remove-netpoll.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Compose

> Compose generates the router execution config locally from your subgraphs. The config can be used to start your router with a pre-built router config.

<Info>
  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](/cli/router/fetch) command instead.
</Info>

## Usage

```bash theme={"system"}
npx wgc router compose -i <path-to-input-file>
```

## 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>
  Note: The `--split-configs-enabled` flag requires Router version [0.315.0](https://github.com/wundergraph/cosmo/releases/tag/router%400.315.0) or higher.
</Note>

## Input file structure

```bash theme={"system"}
version: 1
subgraphs:
  # You can either provide schema file or introspection. File takes precedence
  - name: employees
    routing_url: http://localhost:4001/graphql
    schema:
      file: ./employees.graphql
    subscription:
      url: http://localhost:4001/sse #Optional, defaults to routing_url
      protocol: sse # Optional, defaults to ws (websockets)
      websocket_subprotocol: graphql-ws # Optional, defaults to auto.
      # Available options are auto, graphql-ws, graphql-transport-ws
  - name: family
    routing_url: http://localhost:4002/graphql
    introspection:
      url: http://localhost:4002/graphql
      headers:
        Authorization: 'Bearer YOUR_TOKEN_HERE'
```

## 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](/router/feature-flags).

```yaml theme={"system"}
feature_flags:
  - name: test_checkout
    feature_graphs:
      - name: checkout_canary
        subgraph_name: checkout
        routing_url: https://api.example.com/checkout-canary/graphql
        schema:
          file: feature-flag_checkout.graphql
subgraphs:
  - name: checkout
    routing_url: https://api.example.com/checkout/graphql
    schema:
      file: checkout.graphql
```

## Contracts (optional)

By default, `compose` produces the full supergraph.
Passing `--exclude` and/or `--include` produces a [Schema Contract](/concepts/schema-contracts) 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`](/cli/schema-contracts/create).
Use it to test a contract with your router without a control plane connection.

```bash theme={"system"}
npx wgc router compose -i graph.yaml --exclude internal experimental -o router.json
```

Compose a contract that excludes all schema elements tagged `internal` or `experimental`.

```bash theme={"system"}
npx wgc router compose -i graph.yaml --include public -o router.json
```

Compose a contract that includes only the schema elements tagged `public`.

```bash theme={"system"}
npx wgc router compose -i graph.yaml --include public --exclude internal --disable-base-contract --contract-feature-flag-names ff1 ff2 -o router.json
```

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>
  Note: Contract filtering relies on the `@tag` directive. Make sure `@tag` is imported in each subgraph schema that uses it.
</Note>

## Examples

```bash theme={"system"}
npx wgc router compose -i graph.yaml
```

Compose subgraphs mentioned in the input file graph.yaml

```bash theme={"system"}
npx wgc router compose -i graph.yaml -o router.json
```

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.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.