Apollo Router
Apollo Router is the Rust implementation of the Apollo Federation runtime.
Hive ships a custom build of Apollo Router, because that’s how native extensions works.
With the custom build, Apollo Router will poll the supergraph from the high availability CDN to ensure production deployments without interruptions.
Installation
Make sure you have published all your subgraph schemas to your Federation target on the Hive registry. Once you have all subgraph schemas published and the subgraphs can be composed, the latest valid supergraph is always available via the CDN.
You also need to create a CDN Access Token, that will be used for authenticating the supergraph polling from the CDN.
Download Apollo Router for Linux (x86_64), MacOS (x86_64) or Windows (x86_64). To download the latest version of the router, use the following script:
To download a specific version of the router, use the -v or --version flag:
The full list of releases can be found in the releases registry page
Start the router:
To run Apollo Router with Hive plugin, use the following Docker command.
Make sure to replace IMAGE_TAG_HERE with the image tag. You can use latest for development, or pick a specific version for production from the releases registry page.
Passing command-line arguments:
Creating a custom Apollo Router binary requires compiling it from source. To setup a project, please follow “Create a new project” section of “Creating a custom Apollo Router binary” guide.
Once your project is ready, update Cargo.toml file with the hive_apollo_router_plugin Crate dependency:
Alternatively, you can point to a Git if you need a specific commit or version of the plugin:
Next, update src/main.rs file with the following content to integrate with Hive Console:
Finally, build the binary and run it using HIVE_CDN_ENDPOINT and HIVE_CDN_KEY environment variables.
In case of any issues, please refer to the official guide or open an issue in the Hive Console repository.
Version Structure
The Docker image’s and the binary artifact’s versioning follows the pattern
routerX.Y.Z-pluginX.Y.Z, combining both the core
Apollo Router and
Hive plugin versions.
For example: router1.57.1-plugin1.0.0.
You can find the list of releases in the releases registry page.
Configuration
HIVE_CDN_ENDPOINT- the endpoint Hive generated for you in the previous stepHIVE_CDN_KEY- the access keyHIVE_CDN_POLL_INTERVAL- polling interval (default is 10 seconds)HIVE_CDN_ACCEPT_INVALID_CERTS- accepts invalid SSL certificates (default isfalse)HIVE_REGISTRY_LOG- defines the log level for the registry (default isINFO)HIVE_CDN_SCHEMA_FILE_PATH- where to download the supergraph schema (default is/<tmp-dir>/supergraph-schema.graphql)
Usage Reporting
You can send usage reporting to Hive registry by enabling hive.usage plugin in the config file
(router.yaml).
Configuration
HIVE_TOKEN(required) - Your Registry Access Token with write permission.HIVE_ENDPOINT(optional) - For self-hosting, you can override/usageendpoint (defaults tohttps://app.graphql-hive.com/usage)HIVE_TARGET_ID- A target ID, this can either be a slug following the format “$organizationSlug/$projectSlug/$targetSlug” (e.g “the-guild/graphql-hive/staging”) or an UUID (e.g. “a0f4c605-6541-4350-8cfe-b31f21a4bf80”). To be used whenHIVE_TOKENis configured with an organization access token.
Start the router:
To run Apollo Router with Hive plugin with usage reporting, use the following Docker command.
Make sure to replace IMAGE_TAG_HERE with the image tag. You can use latest for development, or pick a specific version for production from the releases registry page.
To follow the same convention as Apollo Router’s official Docker image, the config file is also located at /dist/config/router.yaml.
Creating a custom Apollo Router binary requires compiling it from source. To setup a project, please follow “Create a new project” section of “Creating a custom Apollo Router binary” guide.
Once your project is ready, update Cargo.toml file with the hive_apollo_router_plugin Crate dependency:
Alternatively, you can point to a Git if you need a specific commit or version of the plugin:
Next, update src/main.rs file with the following content to integrate with Hive Console:
Finally, build the binary and run it using HIVE_TOKEN, HIVE_CDN_ENDPOINT and HIVE_CDN_KEY environment variables.
Don’t forget to create router.yaml file with configuration for hive.usage plugin.
In case of any issues, please refer to the official guide or open an issue in the Hive Console repository.
The exclude option supports both the legacy array format and the dynamic expression object
format. For example, you can skip internal traffic based on a request header:
Expressions can also read the operation type from .request.operation.type ("query",
"mutation" or "subscription"):
For more details about the Hive Router expression syntax and available request fields used by this configuration, see Expressions.
Sampling
By default, every operation is reported. To reduce the volume of usage reports, set sample_rate to
a value between 0.0 (nothing is reported) and 1.0 (everything is reported).
Sampling is decided for each report, so with @defer or subscriptions every response chunk is
sampled on its own, rather than the request as a whole.
At-least-once sampling
A low sample_rate reduces volume, but it can completely miss operations that are rarely executed.
With at_least_once, the first operation for each unique key is always reported, and later
operations with the same key follow sample_rate. This keeps your report volume low while making
sure every distinct operation is visible in Hive Console at least once.
The key defines what makes an operation unique. It accepts one value or a list of:
operation_name- the name of the GraphQL operationoperation_type- the operation type (query,mutation,subscription)operation_body- the operation body
When you provide multiple values, they are combined into a single key.
Keys are tracked in memory (~16 bytes per key), up to max_distinct_keys (default 100000). When
the limit is reached, older keys are evicted, so a previously seen operation may be reported as
“first seen” again.
Persisted Documents (App Deployments)
To activate App Deployments in your Apollo Router, you need
to enable the hive.persisted_documents plugin. The plugin uses the HIVE_CDN_ENDPOINT and
HIVE_CDN_KEY environment variables to resolve the persisted documents IDs.
Once enabled, follow the App Deployments guide to send persisted document requests from your app, using the Hive CDN for resolving the document IDs.
Configuration
The following environment variables are required:
HIVE_CDN_ENDPOINT- the endpoint Hive generated for you in the previous step (for example:https://cdn.graphql-hive.com/artifacts/v1/TARGET_ID/supergraph)HIVE_CDN_KEY- the access key to Hive CDN
You may configure the plugin with the following options:
Use as library
You may also add the persisted-documents plugin:
Next, update src/main.rs file with the following content to integrate with Hive Console:
If you are using both plugins (usage and persisted operations), you’ll need to have a
register_plugin! call to both plugins.