Apollo GraphOS Platform
OverviewQuickstart
APIs and Tools
Schema Management
Explorer IDE
Graph Security
Metrics and Insights
Access Management
Graph Management
Production Readiness
Platform Limits

Variant API Keys

Authenticate CI/CD and automation to specific variants in GraphOS


A variant API key provides access to a specific variant within a graph. When you create the key using GraphOS Studio, only contracts that exist for the variant at the time of key creation are included in the scope by default.

Use variant keys when you need to publish updates to variant schemas, run checks on subgraphs, or create subgraphs in CI/CD pipelines. Create one variant API key per pipeline workflow.

Variant keys expire one year from creation.

note
Only organization members with the Org Admin or Graph Admin role on an Enterprise plan or Standard plan can create variant API keys. Only organization members with the Org Admin role can manage variant API keys in the following ways: view all variant keys, view a single variant key, and delete a variant key.

Create a variant API key using GraphOS Studio

  1. Go to studio.apollographql.com.

  2. Select the API Keys tab.

  3. Select the Create API key button.

  4. Name your key so you can keep track of how each API key is used. For example, you might name a key Production.

  5. Select Variant API key as the key type.

  6. From the Resources section, select the graph and variant(s) you want to grant access to. All contract variants associated with that variant are automatically included. You can't create a variant API key for a contract variant, or have multiple variants from different graphs included in the same key.

  7. Select the Create button.

  8. Copy the key's value and store it in a secure location. For security reasons, you can't view an API key's value again after you close the modal.

note
If you create new contract variants after you create the variant API key, the new variants aren't included in the variant API key. You must replace the variant API key to cover any new contract variants.

Create a variant API key using the Platform API

To create a variant API key, use the createKey mutation from the Platform API.

Before you begin, make sure you have:

  • Your organization ID, from the Organization tab in Studio

  • The variant you want to grant access to (graph ID and variant)

  • Any contract variants you want to grant access to

Use this mutation:

GraphQL
mutation Mutation($organizationId: ID!, $name: String!, $type: GraphOsKeyType!, $resources: ApiKeyResourceInput) {
  organization(id: $organizationId) {
    createKey(name: $name, type: $type, resources: $resources) {
      keyName
      id
      token
    }
  }
}

Include a request payload with the following properties, using your own values:

GraphQL
Request payload
{
  "name": <YOUR_VARIANT_API_KEY_NAME>,
  "type": "VARIANT",
  "organizationId": <YOUR_ORGANIZATION_ID>,
  "resources": {
    "variants": [
      {
        "graphId": <YOUR_GRAPH_ID>,
        "variantName": <YOUR_VARIANT_NAME_1>
      },
      {
        "graphId": <YOUR_GRAPH_ID>,
        "variantName": <YOUR_VARIANT_NAME_2>
      }
    ]
  }
}

Example response payload:

GraphQL
Response payload
{
  "data": {
    "organization": {
      "createKey": {
        "keyName": "Variant test key",
        "id": "6ca72032-535a-4bba-b816-fa8d88823863",
        "token": "ak_v2_RkZFMjE4ODYtMzk5Qy00QkMzLUExRDYtMDRBMjE5NTdFNTdF_MUU3M0MxQ0MtMjY5OS00QjhBLTk4MjYtQzVFMUJFRjFBQUZB"
     }
    }
  }
}

Copy the key's value and store it in a secure location. You can't view an API key's value again.

For an overview of all key types, see API Keys.