Skip to content

Add MaxBatchSize support on source-generated DataLoader - #10023

Merged
michaelstaib merged 3 commits into
mainfrom
mst/dl-maxbatch-size
Jul 1, 2026
Merged

michaelstaib merged 3 commits into
mainfrom
mst/dl-maxbatch-size

Conversation

@michaelstaib

@michaelstaib michaelstaib commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

Implements #9897

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 implements issue #9897 by adding MaxBatchSize support to source-generated DataLoaders, flowing the value from [DataLoader(MaxBatchSize = ...)] through the analyzer model into generated DataLoader constructors (via DataLoaderOptions).

Changes:

  • Add MaxBatchSize to DataLoaderAttribute and extract it in the analyzer (DataLoaderInfo / DataLoaderAttributeHelper).
  • Update the source generator to emit an options wrapper (CreateOptions) that applies MaxBatchSize when specified.
  • Add analyzer snapshot tests and an integration test verifying runtime batching splits keys according to MaxBatchSize.

Reviewed changes

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

Show a summary per file
File Description
src/HotChocolate/Core/test/Types.Analyzers.Tests/DataLoaderTests.cs Adds snapshot-based analyzer tests for MaxBatchSize codegen.
src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/DataLoaderTests.GenerateSource_BatchDataLoader_With_MaxBatchSize_MatchesSnapshot.md Snapshot verifying generated batch DataLoader applies MaxBatchSize via options.
src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/DataLoaderTests.GenerateSource_CacheDataLoader_With_MaxBatchSize_MatchesSnapshot.md Snapshot verifying generated cache DataLoader applies MaxBatchSize via options.
src/HotChocolate/Core/test/Types.Analyzers.Integration.Tests/DataLoaderTests.cs Integration test asserting dispatched batch sizes match MaxBatchSize splitting behavior.
src/HotChocolate/Core/src/Types.Analyzers/Models/DataLoaderInfo.cs Adds MaxBatchSize to the analyzer model.
src/HotChocolate/Core/src/Types.Analyzers/Helpers/DataLoaderAttributeHelper.cs Extracts MaxBatchSize from attribute named arguments.
src/HotChocolate/Core/src/Types.Analyzers/Generators/DataLoaderGenerator.cs Passes MaxBatchSize into the file builder when generating constructors.
src/HotChocolate/Core/src/Types.Analyzers/FileBuilders/DataLoaderFileBuilder.cs Generates CreateOptions(options) and sets local.MaxBatchSize when specified.
src/GreenDonut/src/GreenDonut.Abstractions/Attributes/DataLoaderAttribute.cs Adds MaxBatchSize to the public attribute API (docs + property).

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

Comment on lines +31 to +36
/// <summary>
/// Gets or sets the maximum number of keys that are dispatched to the fetch method in a
/// single batch. When not set, the DataLoader uses the default batch size. A value of
/// <c>0</c> disables batch splitting so that all buffered keys are dispatched together.
/// </summary>
public int MaxBatchSize { get; set; }
@michaelstaib
michaelstaib merged commit 3f90806 into main Jul 1, 2026
6 of 7 checks passed
@michaelstaib
michaelstaib deleted the mst/dl-maxbatch-size branch July 1, 2026 19:52
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Patch coverage

97.0% of changed lines covered (32/33)

File Covered Changed Patch %
…/GreenDonut.Abstractions/Attributes/DataLoaderAttribute.cs 0 1 0.0% 🔴
…/src/Types.Analyzers/FileBuilders/DataLoaderFileBuilder.cs 20 20 100.0% 🟢
…/Core/src/Types.Analyzers/Generators/DataLoaderGenerator.cs 2 2 100.0% 🟢
…/src/Types.Analyzers/Helpers/DataLoaderAttributeHelper.cs 8 8 100.0% 🟢
…/Core/src/Types.Analyzers/Models/DataLoaderInfo.cs 2 2 100.0% 🟢
Uncovered changed lines (JSON)
{
  "sha": "931fe6402feb0fea7308299e7401dcbcd67fa82e",
  "files": [
    { "path": "src/GreenDonut/src/GreenDonut.Abstractions/Attributes/DataLoaderAttribute.cs", "ranges": [[36, 36]] }
  ]
}

Project coverage: 52.5% (217057/413246 lines)

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