rover
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseApollo 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
undefinedbash
undefinedmacOS/Linux
macOS/Linux
curl -sSL https://rover.apollo.dev/nix/latest | sh
curl -sSL https://rover.apollo.dev/nix/latest | sh
npm (cross-platform)
npm(跨平台)
npm install -g @apollo/rover
npm install -g @apollo/rover
Windows PowerShell
Windows PowerShell
iwr 'https://rover.apollo.dev/win/latest' | iex
undefinediwr 'https://rover.apollo.dev/win/latest' | iex
undefinedStep 2: Authenticate
步骤2:身份验证
bash
undefinedbash
undefinedInteractive authentication (opens browser)
交互式身份验证(打开浏览器)
rover config auth
rover config auth
Or set environment variable
或设置环境变量
export APOLLO_KEY=your-api-key
undefinedexport APOLLO_KEY=your-api-key
undefinedStep 3: Verify Installation
步骤3:验证安装
bash
rover --version
rover config whoamibash
rover --version
rover config whoamiCore Commands Overview
核心命令概览
| Command | Description | Use Case |
|---|---|---|
| Publish subgraph schema to GraphOS | CI/CD, schema updates |
| Validate schema changes | PR checks, pre-deploy |
| Download subgraph schema | Local development |
| Compose supergraph locally | Local testing |
| Local supergraph development | Development workflow |
| Publish monograph schema | Non-federated graphs |
| 命令 | 描述 | 使用场景 |
|---|---|---|
| 将子图模式发布到GraphOS | CI/CD、模式更新 |
| 验证模式变更 | PR检查、预部署 |
| 下载子图模式 | 本地开发 |
| 本地组合超级图 | 本地测试 |
| 本地超级图开发 | 开发工作流 |
| 发布单体图模式 | 非联邦式图 |
Graph Reference Format
图引用格式
Most commands require a graph reference in the format:
<GRAPH_ID>@<VARIANT>Examples:
my-graph@productionmy-graph@staging- (default variant)
my-graph@current
Set as environment variable:
bash
export APOLLO_GRAPH_REF=my-graph@production大多数命令需要采用以下格式的图引用:
<GRAPH_ID>@<VARIANT>示例:
my-graph@productionmy-graph@staging- (默认变体)
my-graph@current
设置为环境变量:
bash
export APOLLO_GRAPH_REF=my-graph@productionSubgraph Workflow
子图工作流
Publishing a Subgraph
发布子图
bash
undefinedbash
undefinedFrom schema file
从模式文件发布
rover subgraph publish my-graph@production
--name products
--schema ./schema.graphql
--routing-url https://products.example.com/graphql
--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
--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
--name products
--schema <(rover subgraph introspect http://localhost:4001/graphql)
--routing-url https://products.example.com/graphql
undefinedrover subgraph publish my-graph@production
--name products
--schema <(rover subgraph introspect http://localhost:4001/graphql)
--routing-url https://products.example.com/graphql
--name products
--schema <(rover subgraph introspect http://localhost:4001/graphql)
--routing-url https://products.example.com/graphql
undefinedChecking Schema Changes
检查模式变更
bash
undefinedbash
undefinedCheck against production traffic
针对生产流量检查
rover subgraph check my-graph@production
--name products
--schema ./schema.graphql
--name products
--schema ./schema.graphql
undefinedrover subgraph check my-graph@production
--name products
--schema ./schema.graphql
--name products
--schema ./schema.graphql
undefinedFetching Schema
获取模式
bash
undefinedbash
undefinedFetch 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
undefinedrover subgraph introspect http://localhost:4001/graphql
undefinedSupergraph Composition
超级图组合
Local Composition
本地组合
Create :
supergraph.yamlyaml
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/graphqlCompose:
bash
rover supergraph compose --config supergraph.yaml > supergraph.graphql创建:
supergraph.yamlyaml
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.graphqlFetch Composed Supergraph
获取已组合的超级图
bash
rover supergraph fetch my-graph@productionbash
rover supergraph fetch my-graph@productionLocal Development with rover dev
rover dev使用rover dev
进行本地开发
rover devStart a local Router with automatic schema composition:
bash
undefined启动带有自动模式组合的本地Router:
bash
undefinedStart 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
undefinedrover dev --graph-ref my-graph@staging --supergraph-config local.yaml
undefinedWith MCP Integration
与MCP集成
bash
undefinedbash
undefinedStart with MCP server enabled
启用MCP服务器启动
rover dev --supergraph-config supergraph.yaml --mcp
undefinedrover dev --supergraph-config supergraph.yaml --mcp
undefinedReference 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
undefinedbash
undefined1. Check schema changes
1. 检查模式变更
rover subgraph check $APOLLO_GRAPH_REF
--name $SUBGRAPH_NAME
--schema ./schema.graphql
--name $SUBGRAPH_NAME
--schema ./schema.graphql
rover subgraph check $APOLLO_GRAPH_REF
--name $SUBGRAPH_NAME
--schema ./schema.graphql
--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
--name $SUBGRAPH_NAME
--schema ./schema.graphql
--routing-url $ROUTING_URL
undefinedrover subgraph publish $APOLLO_GRAPH_REF
--name $SUBGRAPH_NAME
--schema ./schema.graphql
--routing-url $ROUTING_URL
--name $SUBGRAPH_NAME
--schema ./schema.graphql
--routing-url $ROUTING_URL
undefinedSchema Linting
模式Lint检查
bash
undefinedbash
undefinedLint 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
undefinedrover graph lint my-graph@production ./schema.graphql
undefinedOutput Formats
输出格式
bash
undefinedbash
undefinedJSON 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
undefinedrover subgraph fetch my-graph@production --name products --format plain
undefinedGround Rules
基本原则
- ALWAYS authenticate before using GraphOS commands (or
rover config auth)APOLLO_KEY - ALWAYS use the correct graph reference format:
graph-id@variant - PREFER before
rover subgraph checkin CI/CDrover subgraph publish - USE for local supergraph development instead of running Router manually
rover dev - NEVER commit to version control; use environment variables
APOLLO_KEY - USE when parsing output programmatically
--format json - SPECIFY explicitly in supergraph.yaml for reproducibility
federation_version - USE to extract schemas from running services
rover subgraph introspect
- 使用GraphOS命令前务必完成身份验证(或设置
rover config auth)APOLLO_KEY - 务必使用正确的图引用格式:
graph-id@variant - 在CI/CD中,优先执行再执行
rover subgraph checkrover subgraph publish - 使用进行本地超级图开发,而非手动运行Router
rover dev - 切勿将提交到版本控制系统;请使用环境变量
APOLLO_KEY - 以编程方式解析输出时,使用
--format json - 在supergraph.yaml中显式指定以确保可复现性
federation_version - 使用从运行中的服务提取模式
rover subgraph introspect