## Usage

```
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.

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.

## Input file structure

```
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](https://cosmo-docs.wundergraph.com/router/feature-flags).

```
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
```

## Examples

```
npx wgc router compose -i graph.yaml
```
Compose subgraphs mentioned in the input file graph.yaml

```
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.
