The Apollo CLI

Installation guide with npm


⚠️ caution
All apollo service:* commands are now deprecated in favor of commands in the Rover CLI .

The Apollo CLI provides commands for interacting with different components of the Apollo platform, including Apollo Client, Apollo Server, and GraphOS.

Download and install

The Apollo CLI is available as an npm package.

If your project uses npm, we recommend installing the Apollo CLI locally by adding it to your project's devDependencies, like so:

Bash
1npm install -D apollo

This helps make sure that all of your project's collaborators have the same version of the CLI installed.

Global installation

You can install the CLI globally in your development environment with the following command:

Bash
1npm install -g apollo

Provide an API key

Like all other tools, the Apollo CLI requires an API key to communicate with GraphOS. For each of your projects, obtain a graph API key for the project's associated graph, and set that key as the value of APOLLO_KEY in your application's .env file:

JavaScript
.env
1APOLLO_KEY=service:docs-example-graph:NYKgCqwfCyYPIm84WVXCdw

Alternatively, you can provide an API key to individual CLI commands with the --key option:

Text
1apollo client:check --graph=MyGraph --key=service:docs-example-graph:NYKgCqwfCyYPIm84WVXCdw

Supported commands

Most of the Apollo CLI's commands are in the following namespaces:

  • client (such as apollo client:codegen) for interactions involving Apollo Client and GraphOS Studio

  • service (such as apollo service:check) for interactions involving Apollo Server and GraphOS Studio

    ⚠️ caution
    All apollo service:* commands are now deprecated in favor of commands in the Rover CLI .

For a full list of commands in a particular namespace, use the apollo help command:

 note
Omit npx from the example commands below if you installed the Apollo CLI globally .
Text
1$ npx apollo help client
2Check a client project against a pushed service
3
4USAGE
5  $ apollo client:COMMAND
6
7COMMANDS
8  client:check            Check a client project against a pushed service
9  client:codegen          Generate static types for GraphQL queries. Can use the
10                          published schema in the Apollo registry or a
11                          downloaded schema.
12  client:download-schema  Download a schema from Apollo or a GraphQL endpoint in
13                          JSON or SDL format
14  client:extract          Extract queries from a client
15  client:push             Register operations with Apollo, adding them to the
16                          safelist

You can also obtain the full set of options for an individual command like so:

Text
1$ npx apollo help client:codegen