enhance(executor): refactor subgraph executor return type#651
enhance(executor): refactor subgraph executor return type#651kamilkisiela merged 6 commits intomainfrom
Conversation
Summary of ChangesHello @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 significantly refactors the subgraph execution process by centralizing deserialization within the Highlights
🧠 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 AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request effectively refactors the SubgraphExecutor to return a SubgraphResponse containing the deserialized data, which simplifies the execution plan logic. Moving deserialization into the HTTPSubgraphExecutor is a good separation of concerns. The removal of the redundant Arc<Bytes> is also a nice cleanup. I've found one critical issue where subgraph errors could be silently dropped, and a high-severity issue with an incorrect safety comment for an unsafe block that should be addressed.
✅
|
|
🐋 This PR was built and pushed to the following Docker images: Image Names: Platforms: Image Tags: Docker metadata{
"buildx.build.ref": "builder-44795178-363d-4c3b-a49e-703d557730c3/builder-44795178-363d-4c3b-a49e-703d557730c30/jfxyuloaedg5l9p90uptlugh5",
"containerimage.descriptor": {
"mediaType": "application/vnd.oci.image.index.v1+json",
"digest": "sha256:39ac5b07e658f652e5bf0d70d0842fba4472bb16dfc65d31574201e6adabbffb",
"size": 1609
},
"containerimage.digest": "sha256:39ac5b07e658f652e5bf0d70d0842fba4472bb16dfc65d31574201e6adabbffb",
"image.name": "ghcr.io/graphql-hive/router:pr-651,ghcr.io/graphql-hive/router:sha-a227493"
} |
f4def7a to
670e8e1
Compare
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
83d7b18 to
280fd69
Compare
| // underlying data remains alive as long as the `SubgraphResponse` does. | ||
| // The `data` field of `SubgraphResponse` contains values that borrow from this buffer, | ||
| // creating a self-referential struct, which is why `unsafe` is required. | ||
| let bytes_ref: &'a [u8] = unsafe { std::mem::transmute(bytes_ref) }; |
There was a problem hiding this comment.
I'm not sure if it's a good idea and it won't kick us in the nuts at some point.
Previously, we passed Bytes to a function that both added the bytes to a response storage (so we knew how long the response is hold in memory) AND did this unsafe transmute trick (to match the storage response's lifetime).
It was safe unsafe, as we knew exactly the lifetime of both things and now we have a structure that enforces a certain lifetime on an object that is gone at the end of the function call, but also cloned.
I guess that's okay... as least we cover that in a description, and explain the behaviour there.
|
@ardatan can you resolve the conflict and ping me? |
|
@kamilkisiela Fixed the conflicts |
…cutor (#652) Extracted from #628 Combining with #651 , the aim is to reduce the number of extra structs. Today, `PlanExecutionOutput` which is the return type of `execute_query_plan` in `executor/execution/plan.rs`, returns `body: Vec<u8>` and `headers: http::HeaderMap`. Then, in the `router/pipeline`, `ResponseBuilder` is called with `Bytes::from` of `PlanExecutionOutput.body` and `PlanExecutionOutput.headers` is converted to `ntex::HeaderMap`, then `content_type` is set here. With this PR, the response aggregator is sent with `PlanExecutionOutput`, and during the response build, the response headers aggregator sets the headers into `ResponseBuilder` directly. So now `modify_client_headers` helper accepts `ResponseBuilder`, not `http:HeaderMap`. And since this throws `HeaderPropagationError` in the pipeline executor, I had to add `HeaderPropagationError` to `PipelineError`. I also extracted `PipelineError` to `FailedExecutionResult` logic to a `From` trait so that other future implementations that serializes and sets the body in a different way can use it and serialize `FailedExecutionResult` on their own. Currently it is used here only -> https://github.com/graphql-hive/router/pull/652/changes#diff-f3dc2f2d579374645281d6950414266d8984195dbf45c00f0a754ceca8550aadR95 ---- Update: After recent changes, I see that `project_by_operation` is used for `dry_run` but it is actually unnecessary as we just need to serialize `extensions` which has nothing to do with projection since it uses `sonic_rs::Value`.
Extracted from #628 Now `SubgraphExecutor` can throw `SubgraphExecutorError` which will be coerced to `PlanExecutorError`. So that the execution related errors and the errors propagated from the subgraph can be distinguished. Combining this with #651, we no longer need to generate dummy subgraph response objects with `GraphQLError`s. It was a bit complicated before because in different levels, helpers like `error_to_graphql_bytes` and `internal_server_error_response` were handling those errors in different places, so it was hard to debug it. Right now the subgraph response will be the actual subgraph response while the rest of the execution errors thrown by us will be handled as `PlanExecutionError`. Of course an error in a plan node will not stop the request entirely for such cases like a subgraph is down etc which is tested in an E2E test added with this PR. To summarize the idea is to take the responsibility of `error` to `response` conversion from the subgraph executor to the plan executor. I also removed unused methods; - HeaderRuleCompileError.new_expression_build - HeaderRuleRuntimeError.new_value_conversion And removed unnecessary methods; - HeaderRuleRuntimeError.new_expression_evaluation
Extracted from #628
SubgraphExecutornow returnsSubgraphResponsethat has the deserialized response in it withbytes: Bytesto be stored in the response storage later on.HTTPSubgraphExecutoris now responsible of deserialization instead of Plan executor.Arc<Bytes>becauseBytesalready usesArcinternally so it has 0 cost of cloningWhy?
In the plugin system's
on_subgraph_executehook is expected to returnSubgraphResponsewhich is basicallydata,errorsandextensions(of course together with an optionalbytesandheaders).In order to have a better DX, I wanted to make this flow's return value
SubgraphResponsewhile keepingHttpResponseason_subgraph_http_request's return value.In this way
SubgraphResponsebecomes HTTP-independent, and it will be easy to handle errors and etc without generating bytes and doing deserialization and serialization work etc for prebuilt responses.For example
graphql_error_to_bytesis no longer needed with this. It can be justSubgraphResponse { errors: vec![error], ...Default:default()