enhance: improve helpers to create GraphQLError easier#650
enhance: improve helpers to create GraphQLError easier#650kamilkisiela merged 5 commits intomainfrom
GraphQLError easier#650Conversation
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 enhances 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 is a nice enhancement that improves the ergonomics of creating GraphQLError instances. By introducing from_message_and_code and making other helpers generic over Into<String>, you've reduced boilerplate and increased flexibility across the codebase. The changes significantly improve readability and maintainability.
I've found one area in lib/executor/src/execution/error.rs where the new implementation introduces a minor performance regression by unnecessarily cloning strings. I've provided a suggestion to resolve this while retaining the benefits of the new builder pattern, in line with the repository's performance-first style guide.
✅
|
|
🐋 This PR was built and pushed to the following Docker images: Image Names: Platforms: Image Tags: Docker metadata{
"buildx.build.ref": "builder-eca4b233-8934-406b-aa91-68ed6b953b21/builder-eca4b233-8934-406b-aa91-68ed6b953b210/h3x6z08eiwb72axphtw5w3teq",
"containerimage.descriptor": {
"mediaType": "application/vnd.oci.image.index.v1+json",
"digest": "sha256:be7407147a822e440c4ffbc4aec7135231ee7f8a9494745a553c80e46b0fb287",
"size": 1609
},
"containerimage.digest": "sha256:be7407147a822e440c4ffbc4aec7135231ee7f8a9494745a553c80e46b0fb287",
"image.name": "ghcr.io/graphql-hive/router:pr-650,ghcr.io/graphql-hive/router:sha-fc32bd4"
} |
91ebaa3 to
d32fac4
Compare
306cff0 to
fc698aa
Compare
fc698aa to
9d70842
Compare
|
Merged your PR! Thanks @kamilkisiela ! |
**Before**
```rust
impl From<PlanExecutionError> for GraphQLError {
fn from(val: PlanExecutionError) -> Self {
let mut error = GraphQLError::from_message_and_code(val.to_string(), val.error_code());
if let Some(subgraph_name) = val.subgraph_name() { // Returns &Option<String>
error = error.add_subgraph_name(subgraph_name); // Clones via Into<String>
}
if let Some(affected_path) = val.affected_path() { // Returns &Option<String>
error = error.add_affected_path(affected_path); // Clones via Into<String>
}
error
}
}
```
What happens:
1. `val.subgraph_name()` returns `&Option<String>`
2. `add_subgraph_name<TStr: Into<String>>()` expects an `Into<String>`
3. When Rust sees `&String` -> `Into<String>`, it uses the impl that
clones the String
4. Same issue for `affected_path`
We end up with 2 unnecessary heap allocations per error conversion.
**After**
I moved owned values out of the structure, to the `add_subgraph_name`
and `add_affected_path` methods.
When Rust sees `Stirng` -> `Into<String>`, it will just use the owned
String, so no clones.
9d70842 to
dd59f05
Compare
Extracted from #628
Introduces
pub fn from_message_and_codeto create an error with an error code in the extensions which reduce the code a lot in different places.Helpers that take
&strorStringare replaced withInto<String>so that extra.to_string()or.into()calls for different variations of string can be avoided.Benefits;
.to_string(),.clone()and.into()for different variations of stringGraphQLErrorExtensions::from_codethanks tomessage_and_codehelper