rover

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Apollo Rover CLI Guide

Apollo Rover CLI 使用指南

Rover is the official CLI for Apollo GraphOS. It helps you manage schemas, run composition locally, publish to GraphOS, and develop supergraphs on your local machine.
Rover是Apollo GraphOS的官方CLI工具,可帮助你管理模式、在本地执行组合操作、发布到GraphOS,以及在本地机器上开发超级图。

Quick Start

快速开始

Step 1: Install

步骤1:安装

bash
undefined
bash
undefined

macOS/Linux

macOS/Linux

npm (cross-platform)

npm(跨平台)

npm install -g @apollo/rover
npm install -g @apollo/rover

Windows PowerShell

Windows PowerShell

Step 2: Authenticate

步骤2:身份验证

bash
undefined
bash
undefined

Interactive authentication (opens browser)

交互式身份验证(打开浏览器)

rover config auth
rover config auth

Or set environment variable

或设置环境变量

export APOLLO_KEY=your-api-key
undefined
export APOLLO_KEY=your-api-key
undefined

Step 3: Verify Installation

步骤3:验证安装

bash
rover --version
rover config whoami
bash
rover --version
rover config whoami

Core Commands Overview

核心命令概览

CommandDescriptionUse Case
rover subgraph publish
Publish subgraph schema to GraphOSCI/CD, schema updates
rover subgraph check
Validate schema changesPR checks, pre-deploy
rover subgraph fetch
Download subgraph schemaLocal development
rover supergraph compose
Compose supergraph locallyLocal testing
rover dev
Local supergraph developmentDevelopment workflow
rover graph publish
Publish monograph schemaNon-federated graphs
命令描述使用场景
rover subgraph publish
将子图模式发布到GraphOSCI/CD、模式更新
rover subgraph check
验证模式变更PR检查、预部署
rover subgraph fetch
下载子图模式本地开发
rover supergraph compose
本地组合超级图本地测试
rover dev
本地超级图开发开发工作流
rover graph publish
发布单体图模式非联邦式图

Graph Reference Format

图引用格式

Most commands require a graph reference in the format:
<GRAPH_ID>@<VARIANT>
Examples:
  • my-graph@production
  • my-graph@staging
  • my-graph@current
    (default variant)
Set as environment variable:
bash
export APOLLO_GRAPH_REF=my-graph@production
大多数命令需要采用以下格式的图引用:
<GRAPH_ID>@<VARIANT>
示例:
  • my-graph@production
  • my-graph@staging
  • my-graph@current
    (默认变体)
设置为环境变量:
bash
export APOLLO_GRAPH_REF=my-graph@production

Subgraph Workflow

子图工作流

Publishing a Subgraph

发布子图

bash
undefined
bash
undefined

From schema file

从模式文件发布

rover subgraph publish my-graph@production
--name products
--schema ./schema.graphql
--routing-url https://products.example.com/graphql
rover subgraph publish my-graph@production
--name products
--schema ./schema.graphql
--routing-url https://products.example.com/graphql

From running server (introspection)

从运行中的服务器发布(自省)

rover subgraph publish my-graph@production
--name products
--schema <(rover subgraph introspect http://localhost:4001/graphql)
--routing-url https://products.example.com/graphql
undefined
rover subgraph publish my-graph@production
--name products
--schema <(rover subgraph introspect http://localhost:4001/graphql)
--routing-url https://products.example.com/graphql
undefined

Checking Schema Changes

检查模式变更

bash
undefined
bash
undefined

Check against production traffic

针对生产流量检查

rover subgraph check my-graph@production
--name products
--schema ./schema.graphql
undefined
rover subgraph check my-graph@production
--name products
--schema ./schema.graphql
undefined

Fetching Schema

获取模式

bash
undefined
bash
undefined

Fetch from GraphOS

从GraphOS获取

rover subgraph fetch my-graph@production --name products
rover subgraph fetch my-graph@production --name products

Introspect running server

自省运行中的服务器

rover subgraph introspect http://localhost:4001/graphql
undefined
rover subgraph introspect http://localhost:4001/graphql
undefined

Supergraph Composition

超级图组合

Local Composition

本地组合

Create
supergraph.yaml
:
yaml
federation_version: =2.9.0
subgraphs:
  products:
    routing_url: http://localhost:4001/graphql
    schema:
      file: ./products/schema.graphql
  reviews:
    routing_url: http://localhost:4002/graphql
    schema:
      subgraph_url: http://localhost:4002/graphql
Compose:
bash
rover supergraph compose --config supergraph.yaml > supergraph.graphql
创建
supergraph.yaml
yaml
federation_version: =2.9.0
subgraphs:
  products:
    routing_url: http://localhost:4001/graphql
    schema:
      file: ./products/schema.graphql
  reviews:
    routing_url: http://localhost:4002/graphql
    schema:
      subgraph_url: http://localhost:4002/graphql
执行组合:
bash
rover supergraph compose --config supergraph.yaml > supergraph.graphql

Fetch Composed Supergraph

获取已组合的超级图

bash
rover supergraph fetch my-graph@production
bash
rover supergraph fetch my-graph@production

Local Development with
rover dev

使用
rover dev
进行本地开发

Start a local Router with automatic schema composition:
bash
undefined
启动带有自动模式组合的本地Router:
bash
undefined

Start with supergraph config

使用超级图配置启动

rover dev --supergraph-config supergraph.yaml
rover dev --supergraph-config supergraph.yaml

Start with GraphOS variant as base

以GraphOS变体为基础启动

rover dev --graph-ref my-graph@staging --supergraph-config local.yaml
undefined
rover dev --graph-ref my-graph@staging --supergraph-config local.yaml
undefined

With MCP Integration

与MCP集成

bash
undefined
bash
undefined

Start with MCP server enabled

启用MCP服务器启动

rover dev --supergraph-config supergraph.yaml --mcp
undefined
rover dev --supergraph-config supergraph.yaml --mcp
undefined

Reference Files

参考文档

Detailed documentation for specific topics:
  • Subgraphs - fetch, publish, check, lint, introspect, delete
  • Graphs - monograph commands (non-federated)
  • Supergraphs - compose, fetch, config format
  • Dev - rover dev for local development
  • Configuration - install, auth, env vars, profiles
特定主题的详细文档:
  • Subgraphs - 获取、发布、检查、Lint、自省、删除
  • Graphs - 单体图命令(非联邦式)
  • Supergraphs - 组合、获取、配置格式
  • Dev - 用于本地开发的rover dev
  • Configuration - 安装、身份验证、环境变量、配置文件

Common Patterns

常见模式

CI/CD Pipeline

CI/CD流水线

bash
undefined
bash
undefined

1. Check schema changes

1. 检查模式变更

rover subgraph check $APOLLO_GRAPH_REF
--name $SUBGRAPH_NAME
--schema ./schema.graphql
rover subgraph check $APOLLO_GRAPH_REF
--name $SUBGRAPH_NAME
--schema ./schema.graphql

2. If check passes, publish

2. 检查通过后发布

rover subgraph publish $APOLLO_GRAPH_REF
--name $SUBGRAPH_NAME
--schema ./schema.graphql
--routing-url $ROUTING_URL
undefined
rover subgraph publish $APOLLO_GRAPH_REF
--name $SUBGRAPH_NAME
--schema ./schema.graphql
--routing-url $ROUTING_URL
undefined

Schema Linting

模式Lint检查

bash
undefined
bash
undefined

Lint against GraphOS rules

针对GraphOS规则执行Lint检查

rover subgraph lint --name products ./schema.graphql
rover subgraph lint --name products ./schema.graphql

Lint monograph

对单体图执行Lint检查

rover graph lint my-graph@production ./schema.graphql
undefined
rover graph lint my-graph@production ./schema.graphql
undefined

Output Formats

输出格式

bash
undefined
bash
undefined

JSON output for scripting

用于脚本的JSON输出

rover subgraph fetch my-graph@production --name products --format json
rover subgraph fetch my-graph@production --name products --format json

Plain output (default)

纯文本输出(默认)

rover subgraph fetch my-graph@production --name products --format plain
undefined
rover subgraph fetch my-graph@production --name products --format plain
undefined

Ground Rules

基本原则

  • ALWAYS authenticate before using GraphOS commands (
    rover config auth
    or
    APOLLO_KEY
    )
  • ALWAYS use the correct graph reference format:
    graph-id@variant
  • PREFER
    rover subgraph check
    before
    rover subgraph publish
    in CI/CD
  • USE
    rover dev
    for local supergraph development instead of running Router manually
  • NEVER commit
    APOLLO_KEY
    to version control; use environment variables
  • USE
    --format json
    when parsing output programmatically
  • SPECIFY
    federation_version
    explicitly in supergraph.yaml for reproducibility
  • USE
    rover subgraph introspect
    to extract schemas from running services
  • 使用GraphOS命令前务必完成身份验证(
    rover config auth
    或设置
    APOLLO_KEY
  • 务必使用正确的图引用格式:
    graph-id@variant
  • 在CI/CD中,优先执行
    rover subgraph check
    再执行
    rover subgraph publish
  • 使用
    rover dev
    进行本地超级图开发,而非手动运行Router
  • 切勿
    APOLLO_KEY
    提交到版本控制系统;请使用环境变量
  • 以编程方式解析输出时,使用
    --format json
  • 在supergraph.yaml中显式指定
    federation_version
    以确保可复现性
  • 使用
    rover subgraph introspect
    从运行中的服务提取模式