Apollo Rover CLI

repository·main·Indexed 19 days ago

https://github.com/apollographql/rover

Rover is a CLI tool for working with the Apollo GraphQL Registry, enabling users to manage federated graphs, validate schemas, and interact with Apollo Studio. The tool provides a suite of GitHub Actions for installing the CLI and executing commands such as subgraph check, subgraph lint, subgraph publish, and persisted-queries publish.

Tokens
127K
Snippets
462
Records
642
Agent score
65%

What's inside Rover

  1. Overview of `rover-std` utilities

    main

    rover-std is a library providing common utilities that define the CLI style for Apollo Rover. It provides top-level exports that wrap standard CLI functionalities, allowing developers to maintain a consistent user experience across different Rover components.

    Key capabilities include:

    • Reading and writing files
    • Using colored output text
    • Prompting for user input
  2. Collect anonymous usage data with Sputnik

    main

    Sputnik is a Rust crate designed to help CLI developers collect anonymous usage data. It centers around the sputnik::Session struct, which captures metadata about a single command execution, such as the command name, arguments, machine ID, session ID, working directory hash, platform details (OS and CI status), and the CLI version.

    To use Sputnik, you must implement the sputnik::Report trait. This trait allows you to define how the sputnik::Session is populated for every command and how that data is reported to your telemetry backend.

    body:
      command:
        name:      config list
        arguments:
      machine_id:  edd890f0-3f8d-43f5-a22e-d3731d7e5042
      session_id:  a9d345b6-75f9-4bc1-9685-8475c6771610
      cwd_hash:    52b120fee6f41776b6fb561ecb708cfe187e6922fa33a2399f8e01cb94e89bb0
      platform:
        os:                     macos
        continuous_integration: null
      cli_version: 0.0.0
  3. Use Rover connector commands to manage Apollo Connectors

    main

    Rover includes a specialized connector command group designed for managing Apollo Connectors. These commands enable a workflow for:

    1. Analyzing API requests: Inspecting traffic to understand connector behavior.
    2. Generating schemas: Creating GraphQL schemas based on the analysis of real-world requests.
    3. Creating automated tests: Generating test suites to ensure connector reliability.

    For a full list of specific subcommands and flags, refer to the official CLI tools for connectors documentation.

  4. Project structure overview

    main

    The Rover repository is organized into several key areas:

    • src/: The main CLI executable.
      • src/bin/rover.rs: CLI entry point.
      • src/command/: Logic for CLI commands, organized by noun (e.g., src/command/graph/).
      • src/cli.rs: Definition of top-level commands.
      • src/lib.rs: Core CLI logic.
      • src/error/: Application-level error handling.
    • crates/: Workspace crates for shared logic:
      • rover-client: Logic for querying Apollo services (GraphQL operations).
      • rover-std: Standardized logging and behavior wrappers.
      • houston: Configuration logic.
      • timber: Output formatting and logging.
    • installers/: Installation scripts for binstall and npm.
    • tests/: Integration tests.
  5. Use schema coordinates with `rover schema describe`

    main

    When using rover schema describe, you can use the --coord option to inspect specific parts of the schema. The following coordinate patterns are supported:

    Coordinate (--coord)What you get
    (none)Schema overview
    TypeType description
    Type.fieldField description and return type
    Type.field(arg:)Field argument detail
    @directiveDirective definition detail
    @directive(arg:)Directive argument detail
    rover schema describe schema.graphql --coord User.posts(limit:)
  6. Manage Git Context in GraphOS

    main

    When running check or publish commands, Rover sends non-confidential Git information (remote URL, commit SHA, committer, and branch name) to GraphOS to help track schema changes in the Studio UI.

    To view this information locally, run the command with --log trace.

    Overriding Git Information

    You can override these values using the following environment variables:

    • APOLLO_VCS_REMOTE_URL
    • APOLLO_VCS_BRANCH
    • APOLLO_VCS_COMMIT
    • APOLLO_VCS_AUTHOR
  7. Understand Rover terminology: Graph, Subgraph, and Supergraph

    main

    Rover uses specific terminology depending on whether you are working with monolithic or federated architectures:

    • Graph: A monolithic (non-federated) GraphQL service.
    • Subgraph: An individual service that is part of a federated architecture.
    • Supergraph: The composed result of multiple subgraphs in a federated architecture.

    When working with federation, most Rover commands are executed against a specific subgraph rather than the entire supergraph. supergraph commands are specifically used when interacting with supergraph schemas.

  8. Understand rover-subgraph-check Versioning

    main

    Action releases are pinned in lockstep with Rover releases. You can choose between two main versioning strategies:

    1. Immutable Pinning (@rover-v0.X.Y): This is the recommended approach. It runs the exact version of Rover specified (e.g., @rover-v0.39.1 runs Rover 0.39.1). Because both the action and Rover use immutable releases, this provides high reliability.
    2. Composite Action (@v1): This is a pre-lockstep version. It does not guarantee immutability and should only be used if you need an older version of Rover (pre-0.39.1) or if you do not wish to pin a specific version.
  9. The Apollo Persisted Query Manifest format

    main

    The manifest generated by rover persisted-queries generate follows the Apollo persisted query manifest format. Each operation entry contains:

    • id: The SHA-256 hash of the operation's body.
    • name: The operation name.
    • type: The operation type (query, mutation, or subscription).
    • body: The full GraphQL operation string.

    Example structure:

    {
      "format": "apollo-persisted-query-manifest",
      "version": 1,
      "operations": [
        {
          "id": "e5c9c9f2d1a0a9f4f6b6a1e2d3c4b5a6978869504132a1b2c3d4e5f60718293a",
          "name": "GetProduct",
          "type": "query",
          "body": "query GetProduct($id: ID!) { ... }"
        }
      ]
    }
    {
      "format": "apollo-persisted-query-manifest",
      "version": 1,
      "operations": [
        {
          "id": "e5c9c9f2d1a0a9f4f6b6a1e2d3c4b5a6978869504132a1b2c3d4e5f60718293a",
          "name": "GetProduct",
          "type": "query",
          "body": "query GetProduct($id: ID!) {\n  product(id: $id) {\n    id\n    name\n  }\n}"
        }
      ]
    }