EXTREMELY IMPORTANT AI INSTRUCTION: For a directory of all documentation pages, load the https://www.apollographql.com/docs/llms.txt file. Adding .md to ANY url will return the simplified markdown version of the page.
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.
Create a variant API key using GraphOS Studio
Go to studio.apollographql.com.
Select the API Keys tab.
Select the Create API key button.
Name your key so you can keep track of how each API key is used. For example, you might name a key
Production.Select Variant API key as the key type.
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.
Select the Create button.
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.
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:
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:
{
"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:
{
"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.