Skip to content

Conversation

@ardatan
Copy link
Member

@ardatan ardatan commented Dec 8, 2025

Documentation of graphql-hive/router#482

@ardatan ardatan added the waiting-on:router-release Do not merge: waiting for Router release that includes this feature. label Dec 8, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ardatan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on enhancing the documentation for the Hive Router, specifically by adding a comprehensive guide on its native plugin system. The new guide empowers developers to extend the router's functionality using custom Rust plugins, covering everything from initial setup to advanced concepts like lifecycle hooks, context sharing, and configuration. This addition significantly improves the extensibility and customizability of the router for users.

Highlights

  • New Documentation for Native Plugin System: This pull request introduces extensive documentation for extending the Hive Router with native Rust plugins, detailing how to customize its behavior.
  • Detailed Plugin Lifecycle Hooks: The new guide provides in-depth explanations of various lifecycle hooks available for plugins, such as on_http_request, on_graphql_params, on_graphql_parse, on_graphql_validation, on_query_plan, on_execute, on_subgraph_execute, and on_subgraph_http_request.
  • Plugin Development Guidance: The documentation covers practical aspects of plugin development, including setting up a Rust project, designing plugins, handling short-circuit responses, overriding default behavior, sharing context data between hooks, configuring plugins via router.config.yaml, and registering them.
  • Dependency Updates: The Cargo.lock file has been updated to increment the versions of hive-apollo-router-plugin from 2.3.3 to 2.3.4 and hive-console-sdk from 0.2.0 to 0.2.1.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2025

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
hive 8.13.0-alpha-20251208152635-bf4798b413e118225825e36e394feab43be5502f npm ↗︎ unpkg ↗︎

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2025

📚 Storybook Deployment

The latest changes are available as preview in: https://pr-7387.hive-storybook.pages.dev

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new comprehensive documentation guide titled "Extending the Router," detailing how to create and configure custom Rust plugins for the Hive Router. The guide covers development setup, the router's plugin lifecycle hooks (e.g., on_http_request, on_graphql_params, on_execute, on_subgraph_execute), methods for short-circuiting responses, overriding default behavior, sharing context data between hooks, and configuring/registering plugins. Additionally, the PR includes minor version updates for hive-apollo-router-plugin and hive-console-sdk in Cargo.lock. Review comments primarily focus on enhancing the new documentation's quality by addressing inconsistent heading levels, correcting typos (e.g., an incorrect Rust version, "seperated"), fixing grammatical errors (e.g., "different the end," "different than"), rectifying comment syntax, and critically, recommending the replacement of unwrap() calls with graceful error handling in code examples to promote safer coding practices.

Comment on lines +637 to +642
let allowed_clients: Vec<String> = serde_json::from_str(
std::fs::read_to_string(self.allowed_ids_path.clone())
.unwrap()
.as_str(),
)
.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This code uses .unwrap() twice, which can cause the router to panic if the file doesn't exist, is not readable, or contains invalid JSON. In a production-grade plugin, this should be handled gracefully. Consider using match or if let to handle potential errors and log them instead of panicking.

                        let allowed_clients: Vec<String> = 
                            if let Ok(content) = std::fs::read_to_string(&self.allowed_ids_path) {
                                serde_json::from_str(&content).unwrap_or_else(|err| {
                                    tracing::error!("Failed to parse allowed clients file: {}", err);
                                    vec![]
                                })
                            } else {
                                tracing::error!("Failed to read allowed clients file");
                                vec![]
                            };


### Development Setup

## Create a new Rust project
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The heading level is inconsistent with the document structure. This heading is h2 (##), but it's a subsection of ### Development Setup (h3). It should be h3 (###) to maintain the correct hierarchy. This also applies to the other sub-headings in this section on lines 56, 80, and 88.

### Create a new Rust project

## Create a new Rust project

First, ensure you have the necessary development environment set up for
[Rust 1.91.1 or later](https://rust-lang.org/tools/install/). Then, you need to create a new Rust
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There seems to be a typo in the required Rust version. 1.91.1 is a future version of Rust. Please verify and correct the required version number.

Comment on lines +66 to +68
/// This is where you can register your custom plugins
let plugin_registry = PluginRegistry::new();
/// Start the Hive Router with the plugin registry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In Rust, /// is used for documentation comments that are part of the public API documentation. Inside a function body, regular comments // are more appropriate.

    // This is where you can register your custom plugins
    let plugin_registry = PluginRegistry::new();
    // Start the Hive Router with the plugin registry

parameters body expected by GraphQL-over-HTTP spec. But we still need to parse the operation into
AST.

On the start of this hooks, you can do the following things for example;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Typo: hooks should be singular hook.

On the start of this hook, you can do the following things for example;


On the end of this hook, you can do the following things for example;

- Prevent certain operations from being executed by checked the HTTP headers or other request
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Grammar: checked should be checking.

- Prevent certain operations from being executed by checking the HTTP headers or other request

ready along with the coerced variables. So you can block the operation, manipulate the result,
variables, etc.

This is different the end of `on_query_plan` hook because we don't have all the parameters ready
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Grammar: different the end should be different from the end.

This is different from the end of `on_query_plan` hook because we don't have all the parameters ready

variables, etc.

This is different the end of `on_query_plan` hook because we don't have all the parameters ready
like coerced variables, filling the introspection fields that are seperated from the actual planning
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Typo: seperated should be separated.

like coerced variables, filling the introspection fields that are separated from the actual planning

Comment on lines +293 to +294
But we still don't have the actual "HTTP" request that would be sent to the subgraph. So this is
different than `on_subgraph_http_request` hook. So this is before the serialization to HTTP request.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Grammar: different than should be different from.

different from `on_subgraph_http_request` hook. So this is before the serialization to HTTP request.

let new_header_value = format!("Hello {}", context_data_entry.incoming_data);
payload.execution_request.headers.insert(
"x-hello",
http::HeaderValue::from_str(&new_header_value).unwrap(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using .unwrap() in documentation can be risky as it might encourage unsafe practices. It's better to show robust error handling, especially in a plugin context where panics should be avoided. Consider using if let Ok(header_value) = ... to handle the potential error gracefully.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2025

💻 Website Preview

The latest changes are available as preview in: https://pr-7387.hive-landing-page.pages.dev

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2025

🐋 This PR was built and pushed to the following Docker images:

Targets: build

Platforms: linux/amd64

Image Tag: bf4798b413e118225825e36e394feab43be5502f

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2025

🐋 This PR was built and pushed to the following Docker images:

Targets: apollo-router-hive-build

Platforms: linux/arm64

Image Tag: 155b484b65b750fab1379ff6dd8c9508c3c9e6a1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-on:router-release Do not merge: waiting for Router release that includes this feature.

Development

Successfully merging this pull request may close these issues.

1 participant