On this page

Hive CLI (Command Line Interface)

hive artifact:fetch --artifact sdl --cdn.endpoint VALUE --cdn.accessToken VALUE

For more information please refer to the CLI readme.

API Reference

List of all available CLI commands and their options can be found here

Errors

You can perform schema-registry actions on your Hive targets schemas using the Hive CLI.

Installation

You can install the Hive CLI as a binary, docker container or a npm package for Node.js.

Download the prebuilt binary of Hive CLI using the following command:

curl -sSL https://graphql-hive.com/install.sh | sh
powershell -c "irm https://graphql-hive.com/install.ps1 | iex"

We publish a docker image for the CLI to the GitHub container registry.

docker pull ghcr.io/graphql-hive/cli

If you are running a JavaScript/Node.js project, you can install Hive CLI from the npm.

npm i -D @graphql-hive/cli

Specific Version

You can also use a specific version of the CLI. A list of all available versions is available on the GitHub releases page.

curl -sSL https://graphql-hive.com/install.sh | sh -s "0.50.1"
# or
curl -sSL https://graphql-hive.com/install.sh | HIVE_CLI_VERSION="0.50.1" sh
# or
export HIVE_CLI_VERSION="0.50.1"
curl -sSL https://graphql-hive.com/install.sh | sh
$env:HIVE_CLI_VERSION="0.50.1"; powershell -c "irm https://graphql-hive.com/install.ps1 | iex"
export HIVE_CLI_VERSION="0.50.1"
docker pull "ghcr.io/graphql-hive/cli:$HIVE_CLI_VERSION"
npm i -D @graphql-hive/cli@0.50.1

Basics

Git Integration

If you are running hive command line in a directory that has a Git repository configured (.git), the CLI will automatically extract the values for the author and commit for the certain commands (e.g. schema publish and schema check.

You may override these values by explicitly passing the --author and --commit flags to the CLI.

If your project does not have a Git repository configured with a user name and email, you are required to pass the --author and --commit flags to the CLI.

If you need to change the way Git identifies your author property, you may use the following commands:

git config --global user.name "John Doe"
git config --global user.email "john@doe.org"

Usage

Publish a Schema

You can use the CLI for publishing schema or services/subgraphs to the schema registry.

hive schema:publish \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  --service reviews \
  --url http://my-service.com/graphql \
  schema.graphql

Further reading:

If you have a single file for your GraphQL schema:

hive schema:publish \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  schema.graphql

Or, multiple files using a glob expression:

hive schema:publish \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  "src/*.graphql"

Further reading:

GitHub Integration

If GitHub Integration is enabled for your organization, and the GitHub integration has access to the GitHub repository, you may specify an additional --github flag to report the results back to GitHub as Check Suite when running the Hive CLI from within a GitHub action.

hive schema:publish \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  schema.graphql \
  --github

Further reading:

Metadata

You can attach metadata to your schema publication. Metadata files published to Hive must be valid JSON and are limited to 25MB. This metadata is not exposed in the Hive UI, but it can be useful for storing JSON configuration files for services, such as for GraphQL Mesh.

To attach metadata to your published schema, you can use --metadata flag when publishing.

You can load the metadata from a file:

hive schema:publish \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  schema.graphql \
  --metadata metadata.json

Or, use an inline JSON passed as a string:

hive schema:publish \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  schema.graphql \
  --metadata '{ "someData": true }'

Further reading:

Promote a Schema

You can use the CLI to promote an existing schema version between targets or roll back a target to a previously published schema version.

Targets

Promote the latest schema version from one target to another:

hive schema:promote \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --from "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/staging" \
  --to "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/production"

Hive Console creates a new schema version in the destination target using the exact same composed supergraph from the source target and updates the CDN state automatically.

Specifc Schema Version

Roll back a target to a previously published schema version:

hive schema:promote \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --version "<SCHEMA_VERSION_ID>" \
  --to "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>"

This creates a new schema version from the specified historical version and updates the target CDN state accordingly. The schema version ID can be obtained from the Hive Console schema history view.

Check a Schema

Checking a GraphQL schema is the form of checking the compatibility of an upcoming schema, compared to the latest published version.

This process of checking a schema needs to be done before publishing a new schema version. This is usually done as part of a CI/CD pipeline, and as part of Pull Request flow.

Hive CLI will give you a list of all changes, sorted by criticality level (Breaking, Dangerous, Safe) and fail the check once breaking change is detected.

hive schema:check \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  schema.graphql

Or, multiple files using a glob expression:

hive schema:check \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  "src/*.graphql"

If you want to be able to leverage breaking change approvals, you must provide the --contextId parameter. Using --contextId is optional when using GitHub repositories and actions with the --github flag.

hive schema:check \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  --contextId "pr-123" "src/*.graphql"

For distributed schemas (Federated or Stitching), you are able to view changes to subgraph URLs by providing the --url parameter.

hive schema:check "src/schema.graphql" --service users --url "https://users.graphql-hive.com/graphql"

Further reading:

GitHub Integration

If GitHub Integration is enabled for your organization, and the GitHub integration has access to the GitHub repository, you may specify an additional --github flag to report the results back to GitHub as Check Suite when running the Hive CLI from within a GitHub action.

hive schema:check \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  schema.graphql \
  --github

Delete a Subgraph

In case you want to compose a schema (or a subgraph in case of Federation), you can do so by using the hive schema:delete command.

hive schema:delete \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  "<SERVICE_NAME>"

Further reading:

Dry Run

You can also use --dryRun flag first to see what effect the command will have on the registry.

In case you want to confirm deletion of the service without typing anything in the terminal, use --confirm flag.

hive schema:delete \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  --dryRun \
  "<SERVICE_NAME>"

Local Subgraph Development

When developing subgraphs locally, you might want to compose a supergraph with your local subgraph changes. Hive Console CLI helps you to do that with the hive dev command.

Remote mode

This mode enables you to replace the subgraph(s) available in the Registry with your local subgraph(s) and compose a Supergraph.

Hive

Dev

Local environment

Poll supergraph from a file

dev command

outputs

Gateway

supergraph.graphql

subgraph A

Hive CLI

subgraph B

subgraph C

Registry

Rather than uploading your local schema to the registry and retrieving the supergraph from the CDN, you can integrate your local modifications directly into the supergraph.

The result of executing this command is a file containing the Supergraph SDL, which can be feed into the gateway.

# Introspect the SDL of the local service
hive dev \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  --remote \
  --service reviews \
  --url http://localhost:3001/graphql

# Watch mode
hive dev \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  --remote \
  --watch \
  --service reviews \
  --url http://localhost:3001/graphql

# Provide the SDL of the local service
hive dev \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  --remote \
  --service reviews \
  --url http://localhost:3001/graphql \
  --schema reviews.graphql

# or with multiple services
hive dev \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  --remote \
  --service reviews --url http://localhost:3001/graphql \
  --service products --url http://localhost:3002/graphql --schema products.graphql

# Custom output file (default: supergraph.graphql)
hive dev \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  --remote \
  --service reviews \
  --url http://localhost:3001/graphql \
  --write local-supergraph.graphql

Usage example

Let’s say you have two subgraphs, reviews and products, and you want to test the reviews service.

First, you need to start the reviews service locally and then run the following command:

hive dev \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  --remote \
  --watch \
  --service reviews \
  --url http://localhost:3001/graphql

This command will fetch subgraph’s schema from the provided URL, replace the original reviews subgraph from the Registry with the local one, and compose a supergraph. The outcome will be saved in the supergraph.graphql file.

The products subgraph will stay untouched, meaning that the gateway will route requests to its remote endpoint.

The --watch flag will keep the process running and update the supergraph whenever the local schema changes.

Now you’re ready to use the supergraph.graphql file in your gateway and execute queries.

This mode enables you to compose a Supergraph with your local subgraph(s).

Rather than uploading your local schema to the registry and retrieving the supergraph from the CDN, you can integrate your local modifications directly into the supergraph.

The result of executing this command is a file containing the Supergraph SDL, which can be feed into the gateway.

# Introspect the SDL of the local service
hive dev \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  --service reviews \
  --url http://localhost:3001/graphql

# Watch mode
hive dev \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  --service reviews \
  --url http://localhost:3001/graphql

# Provide the SDL of the local service
hive dev \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  --service reviews \
  --url http://localhost:3001/graphql \
  --schema reviews.graphql

# or with multiple services
hive dev \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  --service reviews --url http://localhost:3001/graphql \
  --service products --url http://localhost:3002/graphql --schema products.graphql

# Custom output file (default: supergraph.graphql)
hive dev \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  --service reviews \
  --url http://localhost:3001/graphql \
  --write local-supergraph.graphql

Usage example

Let’s say you have two subgraphs, reviews and products, and you want to test the reviews service.

First, you need to start the reviews service locally and then run the following command:

hive dev \
  --registry.accessToken "<YOUR_ACCESS_TOKEN>" \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  --watch \
  --service reviews \
  --url http://localhost:3001/graphql

This command will fetch subgraph’s schema from the provided URL and compose a supergraph. The outcome will be saved in the supergraph.graphql file.

The products subgraph will be omitted from the supergraph.

The --watch flag will keep the process running and update the supergraph whenever the local schema changes.

Now you’re ready to use the supergraph.graphql file in your gateway and execute queries.

Fetch a Schema from the Registry

Sometimes it is useful to fetch a schema (SDL or Supergraph) from Hive, for example, to use it in a local development. This can be done using the schema:fetch command.

You can fetch either the latest schema or a schema by the action id (commit sha) that was used for publishing the schema version. The --write option can be used for writing the schema to a file.

hive schema:fetch \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  --type sdl \
  --write schema.graphqls

hive schema:fetch \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  --type sdl \
  --write schema.graphqls \
  feb8aa9ec8932eb

For projects with a supergraph it is also possible to fetch the supergraph.

hive schema:fetch \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  --type supergraph \
  --write supergraph.graphqls

hive schema:fetch \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  --type supergraph \
  --write supergraph.graphqls \
  feb8aa9ec8932eb

It is also possible to print a list of subgraph details in an ascii table.

hive schema:fetch \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  --type subgraphs

hive schema:fetch \
  --target "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>" \
  --type subgraphs feb8aa9ec8932eb

For more information please refer to the CLI readme.

Fetch a Schema from CDN

You can fetch the GraphQL schema from the CDN using the artifact:fetch command.