Skip to content

Conversation

@ardatan
Copy link
Member

@ardatan ardatan commented Jun 27, 2025

The previous version was never reaching primitive cases because for primitives selection is empty already.
This fixes that so it uses our serialization instead of serde_json.

@ardatan ardatan changed the base branch from main to no-preserve-order June 27, 2025 12:40
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.

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 fundamentally changes how GraphQL response data and certain internal data structures (like requires fields and ExecutionRequest bodies) are serialized within the system. It shifts from relying on serde_json's generic Value type and its default serialization to a custom, direct-to-string JSON generation approach. This change aims to resolve a bug related to primitive type serialization, enhance control over the output format, and potentially improve performance by reducing intermediate data representations.

Highlights

  • Custom JSON Serialization: I've implemented a custom, direct-to-string JSON serialization for GraphQL response data and requires fields. This moves away from serde_json::Value for these specific parts, addressing issues with primitive type serialization and likely improving performance by avoiding intermediate data representations.
  • ExecutionRequest Serialization Control: The ExecutionRequest struct is no longer fully serialized by serde_json. Instead, its HTTP request body is now manually constructed, allowing for precise control over the JSON format sent to subgraphs, particularly for representations.
  • New representations Field: I've introduced a representations: Option<String> field in ExecutionRequest to efficiently pass raw JSON string representations between execution steps and to subgraphs.
  • Projection Logic Refactor: The GraphQL response projection logic has been extracted and refactored into a dedicated projection.rs module, improving code organization and maintainability.
  • Dependency Updates: I've updated serde_json to version 1.0.140 across several Cargo.toml files and removed the preserve_order feature, indicating that the new custom serialization now manages object key order or that order preservation is no longer a critical requirement.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

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

The pull request modifies the serialization logic in project_requires_mut to handle cases where requires_selections is empty. It uses serde_json::to_string to serialize the entire entity when no selections are required. A review comment was added to consider the potential security implications of serializing the entire object, especially if it contains sensitive data.

Comment on lines +891 to +898
if requires_selections.is_empty() {
// It is probably a scalar with an object value, so we write it directly
write!(buffer, "{}", serde_json::to_string(entity_obj).unwrap()).unwrap();
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

If requires_selections is empty, the code serializes the entire entity_obj using serde_json::to_string. This might not be the desired behavior if only specific fields are intended to be serialized. Consider whether this serialization should be conditional based on the type of object or the context in which it's being used. This could lead to unexpected data exposure if the object contains sensitive information that should not be serialized in certain cases.

Suggested change
if requires_selections.is_empty() {
// It is probably a scalar with an object value, so we write it directly
write!(buffer, "{}", serde_json::to_string(entity_obj).unwrap()).unwrap();
return;
if requires_selections.is_empty() {
// It is probably a scalar with an object value, so we write it directly
// TODO: Verify if this serialization is safe and doesn't expose sensitive data.
write!(buffer, "{}", serde_json::to_string(entity_obj).unwrap()).unwrap();
return;
}

@github-actions
Copy link

Federation Audit Results

188 tests  ±0   151 ✅  - 26   3s ⏱️ ±0s
 41 suites ±0     0 💤 ± 0 
 41 files   ±0    37 ❌ +26 

For more details on these failures, see this check.

Results for commit bba61a5. ± Comparison against base commit 8dd9828.

@github-actions
Copy link

github-actions bot commented Jun 27, 2025

TestsPassed ☑️SkippedFailed ❌️Time ⏱
federation-audit | abstract-types.xml18 ran3 ✅15 ❌511ms
federation-audit | child-type-mismatch.xml4 ran1 ✅3 ❌126ms
federation-audit | circular-reference-interface.xml2 ran1 ✅1 ❌45ms
federation-audit | complex-entity-call.xml1 ran1 ✅82ms
federation-audit | corrupted-supergraph-node-id.xml10 ran8 ✅2 ❌134ms
federation-audit | enum-intersection.xml5 ran5 ✅69ms
federation-audit | fed1-external-extends-resolvable.xml1 ran1 ✅29ms
federation-audit | fed1-external-extends.xml4 ran4 ✅58ms
federation-audit | fed1-external-extension.xml4 ran4 ✅57ms
federation-audit | fed2-external-extends.xml4 ran4 ✅63ms
federation-audit | fed2-external-extension.xml4 ran4 ✅63ms
federation-audit | include-skip.xml4 ran4 ✅87ms
federation-audit | input-object-intersection.xml3 ran3 ✅38ms
federation-audit | interface-object-with-requires.xml7 ran3 ✅4 ❌121ms
federation-audit | keys-mashup.xml1 ran1 ✅33ms
federation-audit | mutations.xml4 ran4 ✅82ms
federation-audit | mysterious-external.xml2 ran2 ✅50ms
federation-audit | nested-provides.xml2 ran2 ✅35ms
federation-audit | node.xml1 ran1 ✅26ms
federation-audit | non-resolvable-interface-object.xml7 ran7 ✅85ms
federation-audit | null-keys.xml1 ran1 ❌37ms
federation-audit | override-type-interface.xml4 ran3 ✅1 ❌73ms
federation-audit | override-with-requires.xml4 ran4 ✅89ms
federation-audit | parent-entity-call-complex.xml1 ran1 ✅32ms
federation-audit | parent-entity-call.xml1 ran1 ✅26ms
federation-audit | provides-on-interface.xml2 ran2 ✅40ms
federation-audit | provides-on-union.xml2 ran1 ✅1 ❌45ms
federation-audit | requires-interface.xml5 ran5 ✅76ms
federation-audit | requires-requires.xml5 ran5 ✅113ms
federation-audit | requires-with-argument.xml5 ran3 ✅2 ❌116ms
federation-audit | requires-with-fragments.xml6 ran4 ✅2 ❌112ms
federation-audit | shared-root.xml2 ran2 ✅45ms
federation-audit | simple-entity-call.xml1 ran1 ✅23ms
federation-audit | simple-inaccessible.xml4 ran4 ✅53ms
federation-audit | simple-interface-object.xml13 ran8 ✅5 ❌189ms
federation-audit | simple-override.xml2 ran2 ✅37ms
federation-audit | simple-requires-provides.xml12 ran12 ✅184ms
federation-audit | typename.xml6 ran6 ✅71ms
federation-audit | unavailable-override.xml2 ran2 ✅34ms
federation-audit | union-interface-distributed.xml10 ran10 ✅110ms
federation-audit | union-intersection.xml12 ran12 ✅180ms

@github-actions
Copy link

github-actions bot commented Jun 27, 2025

k6-benchmark results

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

     █ setup

     checks.........................: 100.00% ✓ 8106      ✗ 0   
     data_received..................: 239 MB  7.9 MB/s
     data_sent......................: 3.2 MB  106 kB/s
     http_req_blocked...............: avg=71.37µs  min=1.42µs  med=3.7µs    max=8.25ms   p(90)=5.69µs   p(95)=7.05µs  
     http_req_connecting............: avg=65.31µs  min=0s      med=0s       max=8.22ms   p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=116.95ms min=4.73ms  med=97.61ms  max=738.35ms p(90)=182.86ms p(95)=237.35ms
       { expected_response:true }...: avg=116.95ms min=4.73ms  med=97.61ms  max=738.35ms p(90)=182.86ms p(95)=237.35ms
     http_req_failed................: 0.00%   ✓ 0         ✗ 2722
     http_req_receiving.............: avg=2.13ms   min=34.71µs med=62.06µs  max=239.7ms  p(90)=522.8µs  p(95)=1.78ms  
     http_req_sending...............: avg=459.55µs min=9µs     med=18.73µs  max=72.33ms  p(90)=43.03µs  p(95)=726.38µs
     http_req_tls_handshaking.......: avg=0s       min=0s      med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=114.36ms min=4.67ms  med=96.84ms  max=560.4ms  p(90)=182.16ms p(95)=236.05ms
     http_reqs......................: 2722    90.019215/s
     iteration_duration.............: avg=555.8ms  min=99.2ms  med=541.83ms max=1.39s    p(90)=657.9ms  p(95)=720.26ms
     iterations.....................: 2702    89.357796/s
     vus............................: 50      min=50      max=50
     vus_max........................: 50      min=50      max=50

@ardatan ardatan requested a review from kamilkisiela June 27, 2025 12:45
@ardatan ardatan force-pushed the fix-obj-empty-case branch from bba61a5 to 2818ac9 Compare June 27, 2025 13:31
@ardatan ardatan merged commit e3fe106 into no-preserve-order Jun 27, 2025
12 checks passed
@ardatan ardatan deleted the fix-obj-empty-case branch June 27, 2025 15:13
ardatan added a commit that referenced this pull request Jun 30, 2025
The previous version was never reaching primitive cases because for
primitives selection is empty already.
This fixes that so it uses our serialization instead of serde_json.
ardatan added a commit that referenced this pull request Jul 1, 2025
The previous version was never reaching primitive cases because for
primitives selection is empty already.
This fixes that so it uses our serialization instead of serde_json.
ardatan added a commit that referenced this pull request Jul 2, 2025
The previous version was never reaching primitive cases because for
primitives selection is empty already.
This fixes that so it uses our serialization instead of serde_json.
ardatan added a commit that referenced this pull request Jul 2, 2025
The previous version was never reaching primitive cases because for
primitives selection is empty already.
This fixes that so it uses our serialization instead of serde_json.
ardatan added a commit that referenced this pull request Jul 3, 2025
The previous version was never reaching primitive cases because for
primitives selection is empty already.
This fixes that so it uses our serialization instead of serde_json.
ardatan added a commit that referenced this pull request Jul 8, 2025
The previous version was never reaching primitive cases because for
primitives selection is empty already.
This fixes that so it uses our serialization instead of serde_json.
ardatan added a commit that referenced this pull request Jul 9, 2025
The previous version was never reaching primitive cases because for
primitives selection is empty already.
This fixes that so it uses our serialization instead of serde_json.
ardatan added a commit that referenced this pull request Jul 16, 2025
The previous version was never reaching primitive cases because for
primitives selection is empty already.
This fixes that so it uses our serialization instead of serde_json.
ardatan added a commit that referenced this pull request Jul 17, 2025
The previous version was never reaching primitive cases because for
primitives selection is empty already.
This fixes that so it uses our serialization instead of serde_json.
ardatan added a commit that referenced this pull request Jul 18, 2025
The previous version was never reaching primitive cases because for
primitives selection is empty already.
This fixes that so it uses our serialization instead of serde_json.
ardatan added a commit that referenced this pull request Jul 21, 2025
The previous version was never reaching primitive cases because for
primitives selection is empty already.
This fixes that so it uses our serialization instead of serde_json.
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.

1 participant