> ## Documentation Index
> Fetch the complete documentation index at: https://wundergraphinc-brendan-add-sof-link.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Publish

> Publishes a subgraph on the control plane. Optionally, you can publish and create a subgraph in one step.

## **Usage**

```bash theme={null}
npx wgc subgraph publish [subgraphName] --schema [schemaFilePath]
```

<Note>
  **Publish** is an irreversible action. However, the change will only be visible to the routers once the composition has been successful. Until then, the routers will operate with the most recent valid composition. Please use [subgraph check](/cli/subgraph/check) to understand the impact of your change.
</Note>

## **Description**

The `npx wgc subgraph publish` command enables you to publish a specific subgraph to the Cosmo platform. Publishing a subgraph makes it available for consumption by other services or applications, allowing them to send GraphQL queries and retrieve data from your subgraph. The `[subgraphName]` argument specifies the name of the subgraph you want to publish, while the `--schema` option defines the path to the GraphQL schema file that contains your subgraph's schema definition.

<Warning>
  A previously created [Event-Driven Graph (EDG)](/federation/event-driven-federated-subscriptions)cannot be changed into a regular subgraph. Similarly, a regular subgraph cannot be changed into an EDG. Attempting to do either of these actions will result in an error.
</Warning>

<Warning>
  If you want to publish a plugin subgraph, you must use the [router plugin publish](/cli/router/plugin/publish) command instead.
</Warning>

## **Parameters**

* `[subgraphName]`: The name of the subgraph you want to publish. Make sure to use the correct name of the subgraph you previously created.

## **Options**

<Note>
  If the subgraph has already been created previously, the `routing-url`, `label`, `subscription-url`,`subscription-protocol`, and `websocket-subprotocol parameters`will be ignored. Use [subgraph update](/cli/subgraph/update) to update these values.

  If creating an [Event-Driven Graph](/federation/event-driven-federated-subscriptions) with `subgraph publish`, providing *any* of `routing-url`, `subscription-url`,`subscription-protocol`, or `websocket-subprotocol` will produce an error.
</Note>

* `--routing-url`: Set the URL for the subgraph's data source. This URL defines the endpoint from where the subgraph will fetch data.

  * Example: `--routing-url http://localhost:4001/graphql`

<Note>
  If you are *creating* a subgraph for the first time with `subgraph publish`, the `routing-url` parameter is **required for non-Event-Driven Graphs**.

  If you are *not* creating a subgraph for the first time, the `routing-url` parameter will be ignored. To update the routing URL of an existing subgraph, use [subgraph update](/cli/subgraph/update).
</Note>

* `--label`: Assign multiple labels to the new subgraph. Labels are used to categorize and organize subgraphs based on specific criteria (e.g., team, department, project).

  * Example: `--label team=A`

<Note>
  If you are *creating* a subgraph for the first time with `subgraph publish`, the `label` parameter can be used to set labels. Note that a subgraph will only be considered for a federated graph composition if the subgraph's labels match the labels matcher of that federated graph.

  If you are *not* creating a subgraph for the first time, the `label` parameter will be ignored. To update the labels of an existing subgraph, use [subgraph update](/cli/subgraph/update).
</Note>

* `-n, --namespace` : The namespace of the subgraph (Default: "default").

* `--schema`: The file path to the GraphQL schema definition for the subgraph you want to publish. This file should contain the complete schema definition in the GraphQL Schema Definition Language (SDL) format.

  * Example: `--schema ../demo/subgraphs/products/products.graphql`

* `--fail-on-admission-webhook-error `: If set, the command will fail if the admission webhook fails

* `--fail-on-composition-error `: If set, the command will fail if the composition of the monograph fails.

* `--subscription-url:` Optionally, use a different URL for subscription requests. If no subscription URL is provided, the router URL is used for subscriptions.

<Note>
  If you are *creating* a subgraph for the first time with `subgraph publish`, the `subscription-url` parameter can be used to set the subscription URL.

  If you are *not* creating a subgraph for the first time, the `subscription-url` parameter will be ignored. To update the subscription URL of an existing subgraph, use [subgraph update](/cli/subgraph/update).
</Note>

* `--subscription-protocol:` Optionally, set a protocol to use for subscriptions. The available options are:

  * `ws` (default): Negotiate an appropriate protocol over websockets. Both `graphql-ws` and `subscription-transport-ws` are supported.

  * `sse`: Use Server-Sent Events with a GET request.

  * `sse_post`: Use Server-Sent events with a POST request.

<Note>
  If you are *creating* a subgraph for the first time with `subgraph publish`, the `subscription-protocol` parameter can be used to set the subscription protocol.

  If you are *not* creating a subgraph for the first time, the `subscription-protocol` parameter will be ignored. To update the subscription protocol of an existing subgraph, use [subgraph update](/cli/subgraph/update).
</Note>

* `--websocket-subprotocol:` The subprotocol to use when subscribing to the subgraph. The supported protocols are auto(default), graphql-ws, and graphql-transport-ws. It should be used only if the subscription protocol is ws.

<Note>
  If you are *creating* a subgraph for the first time with `subgraph publish`, the `websocket-subprotocol` parameter can be used to set the websocket subprotocol.

  If you are *not* creating a subgraph for the first time, the `websocket-subprotocol` parameter will be ignored. To update the websocket subprotocol of an existing subgraph, use [subgraph update](/cli/subgraph/update).
</Note>

* `--suppress-warnings`: This flag suppresses any warnings produced by composition.

## **Example**

### Publish a schema to an existing subgraph.

```bash theme={null}
npx wgc subgraph publish products --schema ../demo/subgraphs/products/products.graphql
```

### **Create a subgraph and publish a schema in one command**

```bash theme={null}
npx wgc subgraph publish products --schema ../demo/subgraphs/products/products.graphql --routing-url http://localhost:4001/graphql --label=team=A
```

## **Notes**

* The `npx wgc subgraph publish` command interacts with the Cosmo platform's control plane to publish the specified subgraph.

* Double-check that the path provided for the `--schema` option points to the correct location of the GraphQL schema file you intend to publish.
