Skip to content

refactor: Execution pipeline without HTTP request dependency and better accept header parsing#665

Merged
enisdenjo merged 70 commits intomainfrom
accept-and-no-http
Jan 20, 2026
Merged

refactor: Execution pipeline without HTTP request dependency and better accept header parsing#665
enisdenjo merged 70 commits intomainfrom
accept-and-no-http

Conversation

@enisdenjo
Copy link
Member

@enisdenjo enisdenjo commented Jan 12, 2026

Ref ROUTER-240

execution_pipeline does not depend on the HTTP anymore, graphql_request_handler does all of the HTTP request handling.

As a result, this allows the execution_pipeline and all of its dependencies to return HTTP request independant errors, simplifying the error handling and removing the PipelineError leaving only PipelineErrorVariant (mostly already done in #637).

Also, this PR allows the upcoming subscriptions PR (#620) to include also WebSockets implementation1 and not be too huge for review. Because of this PR being a prerequisite, there's some subscriptions stuff with a // coming soon just to expidite the process of subscriptions and to have better understanding on whats coming.

Besides the WS stuff, removing the HTTP request dependency from execution_pipeline allows us to have onit tests for the pipeline as well as mocking (which might be a thing when we get the #305).

Furthermore we now use headers-accept crate to negotiate the content type as per the official HTTP spec (correct parameter handling and q-weighting).

Bonus points go to: expose query plan dry-run is now really dry. Also added tests.

Why do we return both single and streaming accepted content type when parsing the accept header?

Some clients (like Apollo) sends Accept: multipart/mixed;subscriptionSpec="1.0", application/json headers indicating that the client can also stream. This enables router to send single results as JSON responses but stream multiple results as multipart. Router will inteligently choose one or the other.

As a bonus, it also allows the router to stream single responses.

TODOs

  • Changesets

Footnotes

  1. At the time of writing feat: Subscriptions #620 does not implement WebSockets, but merging this PR will allow it inthe PR.

@enisdenjo enisdenjo requested review from dotansimha and kamilkisiela and removed request for dotansimha January 12, 2026 21:12
@enisdenjo enisdenjo assigned ardatan and unassigned ardatan Jan 12, 2026
@enisdenjo enisdenjo requested a review from ardatan January 12, 2026 21:12
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @enisdenjo, 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 significantly refactors the GraphQL execution pipeline to separate HTTP concerns from the core logic. By centralizing HTTP request processing in a dedicated handler and making the pipeline functions operate on more abstract data, the codebase becomes more modular and easier to extend. This change not only simplifies error management but also lays crucial groundwork for implementing advanced features like GraphQL subscriptions over WebSockets and other streaming protocols, improving the router's flexibility and future capabilities.

Highlights

  • Decoupled Execution Pipeline: The core GraphQL execution pipeline no longer directly depends on ntex::web::HttpRequest, making it HTTP-agnostic. All HTTP-specific handling is now centralized within the graphql_request_handler.
  • Simplified Error Handling: The PipelineError wrapper struct and PipelineErrorFromAcceptHeader trait have been removed. Pipeline functions now directly return PipelineErrorVariant, simplifying error propagation and handling.
  • Enhanced Accept Header Parsing: Introduced new SingleContentType and StreamContentType enums and a robust parsing mechanism for the Accept header, allowing for better negotiation of response formats, including streaming protocols.
  • Subscription Readiness: This refactoring is a prerequisite for the upcoming subscriptions PR (feat: Subscriptions #620), enabling future WebSockets implementation and other streaming transports by abstracting HTTP concerns.
  • Centralized HTTP Logic: HTTP-specific checks such as CSRF prevention, GET mutation validation, and query plan exposure header parsing have been moved into the graphql_request_handler.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

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 is a significant and valuable refactoring that successfully decouples the core execution pipeline from HTTP-specific concerns. The simplification of error handling and the much-improved Accept header parsing logic are excellent changes that enhance modularity and robustness.

My main feedback is regarding the graphql_request_handler function in bin/router/src/pipeline/mod.rs, which has grown quite large as it now orchestrates all the pre-execution steps. I've left a comment suggesting ways to break it down into smaller, more focused functions to improve maintainability, in line with the repository's style guide.

Regarding your question in the PR description, I agree that renaming PipelineErrorVariant to PipelineError would be a good cleanup step now that the old PipelineError struct is gone.

@github-actions
Copy link

github-actions bot commented Jan 12, 2026

k6-benchmark results

     ✓ response code was 200
     ✓ no graphql errors
     ✓ valid response structure

     █ setup

     checks.........................: 100.00% ✓ 248361      ✗ 0    
     data_received..................: 7.2 GB  241 MB/s
     data_sent......................: 97 MB   3.2 MB/s
     http_req_blocked...............: avg=2.69µs   min=657ns   med=1.71µs  max=12.89ms  p(90)=2.46µs  p(95)=2.79µs  
     http_req_connecting............: avg=139ns    min=0s      med=0s      max=2.34ms   p(90)=0s      p(95)=0s      
     http_req_duration..............: avg=17.72ms  min=1.61ms  med=16.72ms max=211.92ms p(90)=24.51ms p(95)=27.66ms 
       { expected_response:true }...: avg=17.72ms  min=1.61ms  med=16.72ms max=211.92ms p(90)=24.51ms p(95)=27.66ms 
     http_req_failed................: 0.00%   ✓ 0           ✗ 82807
     http_req_receiving.............: avg=162.72µs min=25.48µs med=41.75µs max=161.69ms p(90)=79.12µs p(95)=370.13µs
     http_req_sending...............: avg=22.61µs  min=4.32µs  med=9.81µs  max=23.95ms  p(90)=14.42µs p(95)=21.58µs 
     http_req_tls_handshaking.......: avg=0s       min=0s      med=0s      max=0s       p(90)=0s      p(95)=0s      
     http_req_waiting...............: avg=17.53ms  min=1.54ms  med=16.59ms max=55.37ms  p(90)=24.24ms p(95)=27.36ms 
     http_reqs......................: 82807   2755.193831/s
     iteration_duration.............: avg=18.11ms  min=5.41ms  med=17.03ms max=240.74ms p(90)=24.93ms p(95)=28.15ms 
     iterations.....................: 82787   2754.528381/s
     vus............................: 50      min=50        max=50 
     vus_max........................: 50      min=50        max=50 

@github-actions
Copy link

github-actions bot commented Jan 12, 2026

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

Image Names: ghcr.io/graphql-hive/router

Platforms: linux/amd64,linux/arm64

Image Tags: ghcr.io/graphql-hive/router:pr-665 ghcr.io/graphql-hive/router:sha-38f6694

Docker metadata
{
"buildx.build.ref": "builder-a3a09607-20cb-4804-940e-76e63dd8ff47/builder-a3a09607-20cb-4804-940e-76e63dd8ff470/unsvemggwgcfkhl03hyiibhch",
"containerimage.descriptor": {
  "mediaType": "application/vnd.oci.image.index.v1+json",
  "digest": "sha256:63f653716f55bb46a49fef7dd662aaf9170df3f470325951711425051ae8072b",
  "size": 1609
},
"containerimage.digest": "sha256:63f653716f55bb46a49fef7dd662aaf9170df3f470325951711425051ae8072b",
"image.name": "ghcr.io/graphql-hive/router:pr-665,ghcr.io/graphql-hive/router:sha-38f6694"
}

Copy link
Member

@dotansimha dotansimha left a comment

Choose a reason for hiding this comment

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

LGTM. changesets are missing (for internal changes that matters, and dry-run fix).

Let's wait for @kamilkisiela 's response as well before merging

@enisdenjo enisdenjo requested a review from dotansimha January 19, 2026 16:32
Comment on lines +40 to +51
fn try_from(media_type: &MediaType) -> Result<Self, Self::Error> {
let essence_media_type_string = media_type.essence().to_string();
if essence_media_type_string == SingleContentType::GraphQLResponseJSON.as_ref() {
Ok(SingleContentType::GraphQLResponseJSON)
} else if essence_media_type_string == SingleContentType::JSON.as_ref() {
Ok(SingleContentType::JSON)
} else {
Err("Unsupported single content type")
}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

We could avoid allocating the String by laveraging those individual components https://github.com/picoHz/mediatype/blob/8150f29ff62a0214cb9ee534f9a63ce694723987/src/media_type.rs#L34-L41 to match the media type with the enum variant.

That's one allocation that does not dot affect performance too much, so it's fine to keep as is.

Copy link
Contributor

Choose a reason for hiding this comment

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

I did some numbers and it'd be 4x faster, but we're talking 70-113 ns vs 16-36 ns

Copy link
Member Author

@enisdenjo enisdenjo Jan 20, 2026

Choose a reason for hiding this comment

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

I originally used consts everywhere, which is the most optimal way. But I had to fork the crate, because of this since the maintainer does not budge.

On @dotansimha's request I removed the fork dependency and refactored all this in
90c2657.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you think we should go back to the fork @kamilkisiela?

Copy link
Member Author

Choose a reason for hiding this comment

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

Or just avoid the String alloc?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's fine as is :) there's a way to improve it, but we're talking about 4x speed-up on a small number, so it does not affect the overall performance noticeably anyway

Copy link
Contributor

Choose a reason for hiding this comment

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

if we ever see this being a culprit (I don't think we ever will), we will fight it

Copy link
Member Author

Choose a reason for hiding this comment

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

let's not leave anything up to chance. I changed it to avoid allocations, wdyt?

da38835

Copy link
Contributor

Choose a reason for hiding this comment

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

Perfect!

@kamilkisiela
Copy link
Contributor

@enisdenjo if @dotansimha 's comments are covered, feel free to merge it

@enisdenjo enisdenjo merged commit 3408dd9 into main Jan 20, 2026
23 checks passed
@enisdenjo enisdenjo deleted the accept-and-no-http branch January 20, 2026 13:29
ardatan pushed a commit that referenced this pull request Jan 22, 2026
…weight (#705)

Closes #704

Now the `ResponseMode` introduced at #665 will also consider the
`GraphiQL` response mode and negotiate accordingly with browsers that
accept both JSON and HTML, but prefer HTML as per the q-weight.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants