Skip to content

Fix batched multipart uploads on the server and in the Fusion gateway - #10888

Merged
glen-84 merged 4 commits into
mainfrom
gai/batched-multipart-uploads
Nov 12, 2026
Merged

glen-84 merged 4 commits into
mainfrom
gai/batched-multipart-uploads

Conversation

@glen-84

@glen-84 glen-84 commented Nov 12, 2026

Copy link
Copy Markdown
Member

Summary

  • Server: the multipart middleware accepts the operation-indexed map paths that the GraphQL multipart request spec uses for batches, such as { "0": ["0.variables.file"], "1": ["1.variables.files.0"] }, so every operation of a batch can receive files. A map that mixes paths with and without an operation index is rejected with HC0141, and, when request batching is enabled, a batch of more than one operation whose paths have no index is rejected with HC0142. Every parsed operation is disposed when the request is rejected.
  • Fusion: the source schema client maps batch results by the request body it sent. A request with several variable sets that carries a file goes out as an operation batch, and its results are now mapped by requestIndex, so each entity gets its own result instead of the first one. Operation batch results are mapped by requestIndex when they arrive out of order, and a batch that holds a single upload operation is sent as that operation with its own file map, so its file reaches the source schema.
  • Upgrade order: when a gateway forwards uploads into lookups, upgrade the gateway before or together with its source schemas. Behind an older gateway, a source schema with this change returns results that the gateway maps to the wrong entities.

The files.md docs page describes batched uploads and the new error codes, and drops the outdated warning about uploads through a gateway.

Test plan

  • HttpMultipartMiddlewareTests: the spec's batch example, a single operation sent as an array with and without an operation index, HC0141, HC0142, request batching disabled, and disposal of every parsed operation when a multipart request is rejected, tracked through ArrayPool events.
  • VariablePathTests and FileMapTrieTests: operation-indexed paths, invalid shapes, and mixed maps.
  • HttpSourceSchemaClientBufferedTests and HttpSourceSchemaClientTests: an upload request with several variable sets, an upload batch across requests, out-of-order results, a batch of one request, a whole-request error, and the parts sent for a batch with a single upload.
  • Fusion FileUploadTests: through a gateway with a Hot Chocolate source schema, a file forwarded into lookups for two products returns each product's own result.
  • AspNetCore.Tests, Fusion.Execution.Tests, and Fusion.AspNetCore.Tests pass in full.

Copilot AI lite review requested due to automatic review settings November 12, 2026 15:42
@github-actions github-actions Bot added 📚 documentation This issue is about working on our documentation. 🌶️ hot chocolate labels Nov 12, 2026

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.

🟡 Changes recommended

A critical active issue can cause mixed-upload batches to omit the multipart map, so file markers may be sent incorrectly.

1 open issue
1 file not reviewed
  • src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/Properties/AspNetCorePipelineResources.Designer.cs: Generated file
What changed in this PR

This PR adds support for batched multipart uploads across Hot Chocolate servers and Fusion source-schema clients, including operation-indexed file maps and improved result mapping.

Changes:

  • Supports indexed multipart paths, validates invalid batching combinations, and disposes parsed requests on rejection.
  • Updates Fusion upload batching and result mapping for flattened, out-of-order, and single-operation batches.
  • Adds server, Fusion, gateway, snapshot, documentation, and error-code coverage.
File Description
website/​content/​docs/​hotchocolate/​server/​files.md Documents batched multipart uploads and the new validation errors.
src/​HotChocolate/​Primitives/​src/​Primitives/​ErrorCodes.cs Defines the HC0141 and HC0142 multipart validation error codes.
src/​HotChocolate/​Fusion/​test/​Fusion.Execution.Tests/​Execution/​Clients/​HttpSourceSchemaClientTests.cs Tests multipart construction for a single upload operation.
src/​HotChocolate/​Fusion/​test/​Fusion.Execution.Tests/​Execution/​Clients/​HttpSourceSchemaClientBufferedTests.cs Tests Fusion upload batching, result mapping, ordering, errors, and single-request batches.
src/​HotChocolate/​Fusion/​test/​Fusion.AspNetCore.Tests/​FileUploadTests.cs Adds gateway coverage for forwarding one file across multiple entity lookups.
src/​HotChocolate/​Fusion/​test/​Fusion.AspNetCore.Tests/​__snapshots__/​FileUploadTests.Upload_Should_BindFile_When_LookupsForSeveralEntitiesShareTheFile.yaml Captures the gateway and source-schema multipart interaction.
src/​HotChocolate/​Fusion/​src/​Fusion.Execution/​Execution/​ThrowHelper.cs Removes obsolete flattened-index error handling.
src/​HotChocolate/​Fusion/​src/​Fusion.Execution/​Execution/​Clients/​HttpSourceSchemaClient.ResultMapping.cs Maps operation-batch results back to requests and variable sets.
src/​HotChocolate/​Fusion/​src/​Fusion.Execution/​Execution/​Clients/​HttpSourceSchemaClient.cs Passes request-body metadata to result mapping and constructs upload batches.
src/​HotChocolate/​Fusion/​src/​Fusion.Execution/​Execution/​Clients/​HttpSourceSchemaClient.Buffered.cs Applies the updated result-mapping logic to buffered execution.
src/​HotChocolate/​AspNetCore/​test/​AspNetCore.Tests/​Serialization/​VariablePathTests.cs Tests parsing and validation of operation-indexed variable paths.
src/​HotChocolate/​AspNetCore/​test/​AspNetCore.Tests/​Serialization/​FileMapTrieTests.cs Tests indexed paths, unindexed paths, and mixed-map rejection.
src/​HotChocolate/​AspNetCore/​test/​AspNetCore.Tests/​HttpMultipartMiddlewareTests.cs Tests multipart batching, validation errors, disabled batching, and request disposal.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​Utilities/​ThrowHelper.cs Adds exception helpers for multipart validation failures.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​Properties/​AspNetCorePipelineResources.resx Adds localized messages for multipart validation errors.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​Properties/​AspNetCorePipelineResources.Designer.cs Exposes generated accessors for the multipart validation resources.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​Parsers/​VariablePath.cs Parses optional operation indexes from multipart variable paths.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​HttpMultipartMiddleware.cs Applies indexed file maps to batched requests and disposes parsed requests on rejection.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​FileMapTrie.cs Tracks indexed and unindexed paths and rejects mixed maps.
dictionary.txt Adds the Unindexed terminology to the repository dictionary.

Review effort: Lite

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Patch coverage

96.5% of changed lines covered (164/170)

File Covered Changed Patch %
…/Execution/Clients/HttpSourceSchemaClient.ResultMapping.cs 80 86 93.0% 🟡
…/AspNetCore/src/AspNetCore.Pipeline/FileMapTrie.cs 14 14 100.0% 🟢
…/src/AspNetCore.Pipeline/HttpMultipartMiddleware.cs 19 19 100.0% 🟢
…/AspNetCore/src/AspNetCore.Pipeline/Parsers/VariablePath.cs 16 16 100.0% 🟢
…/AspNetCore/src/AspNetCore.Pipeline/Utilities/ThrowHelper.cs 10 10 100.0% 🟢
…/Execution/Clients/HttpSourceSchemaClient.Buffered.cs 8 8 100.0% 🟢
…/Fusion.Execution/Execution/Clients/HttpSourceSchemaClient.cs 17 17 100.0% 🟢
Uncovered changed lines (JSON)
{
  "sha": "14879a16ab281ee8069460fef60272a639730593",
  "files": [
    { "path": "src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Clients/HttpSourceSchemaClient.ResultMapping.cs", "ranges": [[100, 104], [107, 107]] }
  ]
}

Project coverage: 59.8% (326997/546544 lines)

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.

🟢 Approval recommended

No active issues were identified, and the change is supported by comprehensive coverage across multipart parsing, validation, disposal, result mapping, gateway behavior, and documentation.

No open issues 🎉

1 resolved since last review
1 file not reviewed
  • src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/Properties/AspNetCorePipelineResources.Designer.cs: Generated file

Review effort: Lite

@glen-84
glen-84 merged commit 38c207f into main Nov 12, 2026
160 checks passed
@glen-84
glen-84 deleted the gai/batched-multipart-uploads branch November 12, 2026 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📚 documentation This issue is about working on our documentation. 🌶️ hot chocolate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants