# Deploy with Graph Artifacts

GraphOS supports two approaches for deploying with graph artifacts. Choose the one that fits your infrastructure:

* **CI/CD pipeline**: Your pipeline fetches the artifact URI from the GraphOS Platform API and writes it to the router's configuration at deploy time. This approach works with any infrastructure.
* **Apollo GraphOS Operator for Kubernetes**: If you run on Kubernetes, you can declare the desired artifact reference in a `Supergraph` custom resource and let the Operator manage the router deployment. This replaces manual environment variable management in your pipeline scripts.

## Deploy with your CI/CD pipeline

To integrate graph artifacts into your CI/CD workflow, in your pipeline, programmatically fetch the latest graph artifact's reference URI using the [GraphOS Platform API](https://www.apollographql.com/docs/graphos/platform/platform-api), then save it to your router's configuration as part of deployment.

1. Fetch the graph artifact history of a variant using the [GraphOS Platform API](https://www.apollographql.com/docs/graphos/platform/platform-api).

   ```graphql title=GetGraphArtifactHistory
   # Fetch the latest Graph Artifact URIs for a specific graph variant
   query GetGraphArtifactHistory($graphId: ID!, $variantName: String!) {
     graph(id: $graphId) {
       variant(name: $variantName) {
         launchHistory {
           graphArtifact {
             completedAt
             status
             location {
               uri
             }
           }
         }
       }
     }
   }
   ```

   Specify your graph ID and variant name for the query:

   ```json title=Variables
   {
     "graphId": "my-graph-id",
     "variantName": "production"
   }
   ```

   In the response, find the `graphArtifact` with the latest `completedAt` value and a `status` of `GRAPH_ARTIFACT_COMPLETED`. The value of its `location.uri` field is the most recent artifact reference. Write the URI to your router's configuration during deployment to make sure it runs that specific schema version. Example response:

   ```json title=ExampleResponse
   {
     "data": {
       "graph": {
         "variant": {
           "launchHistory": [
             {
               "graphArtifact": {
                 "completedAt": "2025-09-30T19:22:02.684293Z",
                 "status": "GRAPH_ARTIFACT_COMPLETED",
                 "location": {
                   "uri": "artifact.api.apollographql.com/my-graph-id@sha256:157be07b693c50376853f3cfaf4abb9fa61c9996f2f10912ffa1d0e92361b461"
                 }
               }
             },
             {
               "graphArtifact": {
                 "completedAt": "2025-09-29T17:12:43.036755Z",
                 "status": "GRAPH_ARTIFACT_COMPLETED",
                 "location": {
                   "uri": "artifact.api.apollographql.com/my-graph-id@sha256:613750b0cf4f9fed76af65cf79d7be21bb5262de65e011dc469d51755c69ed49"
                 }
               }
             }
           ]
         }
       }
     }
   }
   ```

2. Configure the router to run the graph artifact by setting the `APOLLO_GRAPH_ARTIFACT_REFERENCE` environment variable or specifying the `--graph-artifact-reference` router command line argument.

3. If problems arise, repeat step 2 to roll back using the reference URI of a known-good graph artifact.

## Deploy with the Apollo GraphOS Operator for Kubernetes

If your routers run on Kubernetes, the [Apollo GraphOS Operator](https://www.apollographql.com/docs/apollo-operator) is an alternative to the CI/CD pipeline approach above. Rather than having your pipeline imperatively fetch and write an artifact URI, you declare the desired artifact reference in a `Supergraph` custom resource. The Operator then provisions and manages the router Deployment, Service, ConfigMap, and Secret, and Kubernetes handles the orchestration. Go to the [Apollo GraphOS Operator docs](https://www.apollographql.com/docs/apollo-operator) for more information.
