Sourcegraph DocsSourcegraph Docs
Theme
  1. Docs
  2. admin
  3. how-to
  4. manage-feature-flags-with-graphql

How to manage feature flags with the GraphQL API

Some Sourcegraph instances do not expose the feature flag admin UI. In those cases, site admins can manage feature flags through the GraphQL API using the src CLI.

Prerequisites

  • Install src by following the src-cli installation instructions.
  • Sign in to your instance:
BASH
src login https://your-sourcegraph-instance.com

List all feature flags

BASH
src api -query=' query { featureFlags { ... on FeatureFlagBoolean { name value } ... on FeatureFlagRollout { name rolloutBasisPoints } } }'

Get a single feature flag

BASH
src api -query=' query { featureFlag(name: "my-feature-flag") { ... on FeatureFlagBoolean { name value } ... on FeatureFlagRollout { name rolloutBasisPoints } } }'

Update a feature flag

Update a boolean flag:

BASH
src api -query=' mutation { updateFeatureFlag(name: "my-feature-flag", value: false) { ... on FeatureFlagBoolean { name value } } }'

Update a rollout flag:

BASH
src api -query=' mutation { updateFeatureFlag(name: "my-rollout-flag", rolloutBasisPoints: 5000) { ... on FeatureFlagRollout { name rolloutBasisPoints } } }'

rolloutBasisPoints uses basis points where 10000 = 100% and 5000 = 50%.

Delete a feature flag

BASH
src api -query=' mutation { deleteFeatureFlag(name: "my-feature-flag") { alwaysNil } }'

Create a user or organization override

BASH
src api -query=' mutation { createFeatureFlagOverride( namespace: "VXNlcjox" flagName: "my-feature-flag" value: true ) { id value } }'

The namespace argument must be the GraphQL ID of a user or organization.

Use a query like this to discover IDs:

BASH
src api -query=' query { users(first: 10) { nodes { id username } } }'

Related docs

  • GraphQL API reference
  • src CLI references

On this page

  1. How to manage feature flags with the GraphQL API

    1. Prerequisites
    1. List all feature flags
    1. Get a single feature flag
    1. Update a feature flag
    1. Delete a feature flag
    1. Create a user or organization override
    1. Related docs

Edit this page on GitHub
View as Markdown