# Deploy your own Subgraph

Source: https://docs.graphops.xyz/subgraphs/guides/deploy-with-graph-cli

Build your Subgraph with the standard Graph CLI, deploy it to get a Deployment CID, and publish it
on The Graph Network if you want a Graph Network Subgraph ID. Either identifier is what you give
GraphOps when you choose **Set up a Subgraph** and **My own Subgraph**.

*You build and publish with Graph CLI. The Deployment CID it prints is what you query, give to a Managed Subgraph, or set as an Endpoint Alias target.*

- Your project: `graph codegen · graph build`.
- Publish: `graph deploy` prints the Deployment CID.
- Query endpoint: /v1/deploymentCID/<DEPLOYMENT_CID>.
- Managed Subgraph: GraphOps keeps it indexed.
- Endpoint Alias: A stable URL that targets it.

## Prerequisites

* A Subgraph project with `subgraph.yaml`, for example one created with `graph init`.
* The standard Graph CLI installed for your project.
* A Subgraph in Subgraph Studio, and its deploy key, to deploy to.
* A GraphOps organization with Subgraphs access and an API key that includes Subgraphs.

## Deploy

### Generate types \[#generate-types]

```sh
graph codegen

```

### Build the Subgraph \[#build-the-subgraph]

```sh
graph build

```

### Deploy a version \[#deploy-a-version]

Authenticate once with `graph auth` and your deploy key, then deploy with the Subgraph's slug.
To deploy to another Graph Node instead, add its `--node` and `--ipfs` URLs.

Prerequisites

1. Replace `<SUBGRAPH_SLUG>` with your Subgraph's name.

```sh
graph deploy <SUBGRAPH_SLUG> --version-label v1.0.0

```

Copy the Deployment CID from the command output and record it with the
release. A Deployment CID identifies this exact version. It is all a Managed Subgraph needs:
GraphOps can index it whether or not you publish it.

### Publish on The Graph Network (optional) \[#publish-on-the-graph-network-optional]

Publish when you want indexers on The Graph Network to serve your Subgraph, or want each version
you publish to reach your application automatically:

```sh
graph publish

```

Publishing gives the Subgraph a Graph Network Subgraph ID. Every later version you publish
belongs to the same ID, so an ID follows your releases while a Deployment CID stays on one
version.

### Use the identifier in GraphOps \[#use-the-identifier-in-graphops]

Start **Set up a Subgraph** and answer **My own Subgraph**. Paste the identifier
that matches how you release:

[Set up a Subgraph](https://platform.graphops.xyz/organizations/current/services/subgraphs/setup)

| You paste                 | You release new versions                                     | See                                                              |
| ------------------------- | ------------------------------------------------------------ | ---------------------------------------------------------------- |
| Deployment CID            | From GraphOps Platform: stage, test and promote each version | [Develop and release a Subgraph](./develop-and-release)          |
| Graph Network Subgraph ID | By publishing on The Graph Network                           | [Release by publishing](../choose-a-setup#release-by-publishing) |

The setup then asks whether GraphOps should keep it indexed and creates the Managed Subgraph and
Endpoint Alias your answers need. Managed Subgraphs need a monthly plan for your organization.

### Check the deployment \[#check-the-deployment]

Prerequisites

1. Set GRAPHOPS\_API\_KEY to your GraphOps API key.

2. Replace `<DEPLOYMENT_CID>` with the Deployment CID to query.

[Example project](/examples/subgraphs.guides.deploy-with-graph-cli.sh-5.tar.gz)

```sh
curl --fail-with-body --silent --show-error "https://subgraphs.graphops.xyz/v1/deploymentCID/<DEPLOYMENT_CID>" \
  -H "Authorization: Bearer ${GRAPHOPS_API_KEY}" \
  -H "Content-Type: application/json" \
  --data '{
    "query": "query DeploymentStatus { _meta { deployment block { number hash } hasIndexingErrors } }"
  }'

```

Output

```json
{
  "data": {
    "_meta": {
      "deployment": "QmTZ8ejXJxRo7vDBS4uwqBeGoxLSWbhaA7oXa1RvxunLy7",
      "block": {
        "number": 26285621,
        "hash": "0x40c3154aaa484a99057c58a6c72c27171ed861d260179db387850027655d0881"
      },
      "hasIndexingErrors": false
    }
  }
}
```

Should match the CID from graph deploy

Rises as the new deployment indexes

Must stay false before you release

`_meta.block.number` rises while the new deployment indexes. Query your application's fields only
after it reaches the blocks your application needs.

## Release the new version

Test the new deployment through its Deployment CID endpoint before production
clients use it. Then release it as the Next version of a Managed Subgraph, so your production
Endpoint Alias moves only once it is indexed;
[Develop and release a Subgraph](./develop-and-release) walks through that workflow.

* Keep the previous Deployment CID as a rollback target.
* Check `_meta.hasIndexingErrors` after deploying and after each release.

## Next steps

* [Choose your Subgraph setup](../choose-a-setup): Decide how GraphOps keeps your Subgraph indexed and how new versions reach your application.
* [Develop and release a Subgraph](./develop-and-release): Test each version, then release it behind a stable URL.
* [Monitor sync health](./monitor-sync-health): Track indexing progress and errors from your application.