Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update hive-apollo-router-plugin to be compatible with apollo-router v2 #6535

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yanns
Copy link

@yanns yanns commented Feb 19, 2025

Background

The Apollo Federation Router was released in version 2 with some incompatible changes: https://github.com/apollographql/router/releases/tag/v2.0.0

Description

This PR updates the different hive plugins to be compatible with the new version of the router.
It does not change the version. I don't know what will be your policy here.

Copy link
Contributor

coderabbitai bot commented Feb 19, 2025

📝 Walkthrough

Summary by CodeRabbit

  • Chores

    • Upgraded several underlying libraries to newer versions, enhancing overall performance and stability.
    • Added additional components for improved HTTP handling.
  • Refactor

    • Streamlined request processing and error handling, resulting in more robust and efficient operations for end-user experiences.

Walkthrough

This pull request updates dependency versions and refactors request handling in the router package. In the Cargo.toml, several dependencies are updated—including major version upgrades for apollo-router, hyper, and tower—and new dependencies such as axum-core, http, and http-body-util are added. In the Rust source file, the PersistedDocumentsPlugin is refactored by replacing a checkpoint method, altering the request body collection from to_bytes() to collect(), and introducing a helper function for body conversion. The error handling for body read failures is also updated.

Changes

File Change Summary
packages/libraries/router/Cargo.toml - Updated apollo-router from ^1.13.0 to ^2.0.0
- Added new dependencies: axum-core = "0.5", http = "1", and http-body-util = "0.1"
- Upgraded hyper from 0.14.28 to 1 and tower from 0.4.13 to 0.5
- Reformatted reqwest and jsonschema feature lists
packages/libraries/router/src/.../persisted_documents.rs - Changed router_service to use checkpoint_async instead of oneshot_checkpoint_async
- Modified body handling: using .collect() on the body and adding body_from_bytes helper for conversion
- Updated error type in FailedToReadBody from hyper::Error to axum_core::Error
- Adjusted imports and formatting

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant P as PersistedDocumentsPlugin
    participant S as Checkpoint Service

    C->>P: Send HTTP Request
    P->>S: Invoke checkpoint_async(request)
    S-->>P: Return Response or Error
    alt Successful Response
        P->>P: Collect body using .collect()
        P->>P: Convert bytes using body_from_bytes
        P-->>C: Return Processed Response
    else Error Occurred
        P-->>C: Return FailedToReadBody (axum_core::Error)
    end
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
packages/libraries/router/src/persisted_documents.rs (4)

114-118: Be mindful of large request bodies

Collecting the entire body into memory may be expensive if requests can be large. If your usage involves large payloads, consider streaming or buffering in chunks to avoid memory spikes.


207-211: Add a docstring for body_from_bytes?

This helper function is a good utility. Consider adding a short docstring clarifying its purpose, especially since it handles infallible conversions.


281-292: Security caution with danger_accept_invalid_certs

Enabling invalid SSL acceptance can be useful for testing or special environments but may be risky in production. Ensure it’s disabled in live deployments to avoid MITM vulnerabilities.


370-370: Avoid logging entire response body on failure

Logging the raw body can leak sensitive data or cause memory overhead. Consider partial logging or omitting the body altogether if it can contain private information.

Also applies to: 372-375

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 21572b9 and d573329.

⛔ Files ignored due to path filters (1)
  • configs/cargo/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • packages/libraries/router/Cargo.toml (2 hunks)
  • packages/libraries/router/src/persisted_documents.rs (19 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`packages/libraries/**`: Most of the dirs here are NPM packa...

packages/libraries/**: Most of the dirs here are NPM packages that provides our customers an integration library, in order to get/fetch data from Hive Console API or Hive CDN.

  • packages/libraries/router/src/persisted_documents.rs
  • packages/libraries/router/Cargo.toml
🔇 Additional comments (19)
packages/libraries/router/src/persisted_documents.rs (13)

12-15: LGTM on new imports

These added imports from http_body_util, reqwest_middleware, and environment usage appear consistent with the updated approach for body handling and retry logic. No concerns found.

Also applies to: 17-18, 21-21


110-110: Confirm the behavior change to .checkpoint_async

Switching from the older .oneshot_... approach to .checkpoint_async aligns with Apollo Router v2 changes. Ensure downstream services are tested to confirm no breakage in request flow.


132-135: Neat usage of body_from_bytes

Using body_from_bytes to rewrap the modified request payload is a clean approach and promotes code reuse. Great job.

Also applies to: 181-181


229-229: Error type change acknowledged

Switching to axum_core::Error is consistent with other refactors in this file. Verify that all error handling paths are updated accordingly in the rest of the codebase.


257-258: Extension code for CDN responses

Defining "FAILED_TO_READ_CDN_RESPONSE" is clear and consistent with other error codes. No issues found.


334-338: Consider robust null checks

The code calls .unwrap() on self.config.endpoint. Even though you set defaults elsewhere, ensure at runtime this never becomes None. Otherwise, the service might panic.


353-356: Check CDN response size

Reading the entire CDN response at once might affect memory usage if documents become large. Confirm that the maximum persisted document size is reasonable.


416-416: Import in tests looks good

The introduction of hyper::body::Bytes for test usage is consistent. No issues found.


499-499: Test approach to read full body

Collecting the entire body is acceptable here for unit tests. No issues found.


505-505: Documentation improvement in tests

The added inline comments clarify the test purpose well. Looks good.

Also applies to: 507-507


742-743: No issues with test config

Setting the key and endpoint in test configs matches the typical mock usage. Approved.


750-751: Variable passing in persisted request

Including variables is a good thoroughness check. This correctly tests passing additional request parameters.


768-772: Plugin instantiation in tests is consistent

The test config properly sets up the plugin with mocking. No concerns found.

packages/libraries/router/Cargo.toml (6)

20-21: Major bump to apollo-router & new axum-core dependency

Upgrading to ^2.0.0 for Apollo Router and adding axum-core is aligned with the new plugin architecture. Ensure you’ve followed the v2 migration guidelines.


23-27: reqwest features reconfigured

Enabling "blocking" might raise questions in async contexts, but it could be required if your code does synchronous tasks. Verify no performance regressions or deadlock risk.


33-33: hyper updated to 1

Confirm that any existing code dependent on the 0.14.* hyper APIs has been updated.


40-42: tower, http, and http-body-util updates

All appear necessary for Router v2. Good alignment with the new request handling mechanics.


45-46: graphql-tools features reorganized

Reformatting the feature list is fine. No issues.


54-55: jsonschema feature additions

Allowing resolve-file is useful if needed for more advanced usage. Confirm no unexpected runtime overhead.

@dotansimha
Copy link
Member

Thanks @yanns ! I'll be the one reviewing this PR. I've approved the workflow, but it might fail anyway because of some security requirements (Docker images can't be pushed to registry from forks...)

I'll be reviewing and testing this very soon, thank you for contributing!

@dotansimha dotansimha self-requested a review February 19, 2025 17:00
@dotansimha dotansimha changed the title update to router v2 update hive-apollo-router-plugin to be compatible with apollo-router v2 Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants