Skip to content

Improve cross-chunk JSON serialization - #10092

Merged
michaelstaib merged 2 commits into
mainfrom
mst/imp-json-serialization
Jul 11, 2026
Merged

michaelstaib merged 2 commits into
mainfrom
mst/imp-json-serialization

Conversation

@michaelstaib

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings July 11, 2026 18:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves how SourceResultDocument writes large scalar values (strings/numbers) that span multiple underlying data chunks by avoiding the “gather into a contiguous scratch buffer” path when JSON output is not indented.

Changes:

  • Added JsonWriter.WriteRawValueEnd(JsonTokenType) to finalize multi-chunk raw writes while updating the writer token state.
  • Updated SourceResultDocument to stream cross-chunk scalar bytes directly into JsonWriter for minimized output, while keeping the pooled scratch-buffer path for indented output.
  • Added tests covering cross-chunk scalar formatting and validating that oversized values fail before writing any output.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/HotChocolate/Json/src/Json/JsonWriter.cs Adds a raw-write end overload that sets _tokenType for streamed scalar writes.
src/HotChocolate/Fusion/src/Fusion.Execution/Text/Json/SourceResultDocument.cs Streams cross-chunk scalar writes in minimized mode; adds max-token-size guard.
src/HotChocolate/Fusion/src/Fusion.Execution/Text/Json/ThrowHelper.cs Adds a helper to throw a consistent ArgumentException for oversized JSON values.
src/HotChocolate/Fusion/test/Fusion.Execution.Tests/Text/Json/SourceResultDocumentTests.cs Adds tests for cross-chunk scalar output and oversized-value validation behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

github-actions Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Patch coverage

100.0% of changed lines covered (66/66)

File Covered Changed Patch %
…/src/Fusion.Execution/Text/Json/SourceResultDocument.cs 55 55 100.0% 🟢
…/Fusion/src/Fusion.Execution/Text/Json/ThrowHelper.cs 6 6 100.0% 🟢
src/HotChocolate/Json/src/Json/JsonWriter.cs 5 5 100.0% 🟢

Project coverage: 53.4% (227699/426465 lines)

@michaelstaib
michaelstaib merged commit 34f39e5 into main Jul 11, 2026
12 of 13 checks passed
@michaelstaib
michaelstaib deleted the mst/imp-json-serialization branch July 11, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants