Skip to content

Allow Dictionary<TKey, T> as DataLoader return type - #10370

Merged
michaelstaib merged 1 commit into
mainfrom
mst/dataloader-refinements
Sep 8, 2026
Merged

michaelstaib merged 1 commit into
mainfrom
mst/dataloader-refinements

Conversation

@michaelstaib

Copy link
Copy Markdown
Member

No description provided.

Copilot AI lite review requested due to automatic review settings September 8, 2026 10:14
@github-actions github-actions Bot added 📚 documentation This issue is about working on our documentation. 🌶️ hot chocolate labels Sep 8, 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.

🟢 Approval recommended

The change is narrowly scoped, consistently applied across analyzer/model/docs, and covered by updated tests and snapshots for both valid and invalid cases.

Pull request overview

This PR expands the [DataLoader<T>] analyzer/source-generator contract validation to allow Dictionary<TKey, TValue> (in addition to IReadOnlyDictionary<TKey, TValue> and IDictionary<TKey, TValue>) as a valid batch DataLoader return type, and updates docs/tests accordingly.

Changes:

  • Accept Task<Dictionary<TKey, TValue>> / ValueTask<Dictionary<TKey, TValue>> as valid batch DataLoader return types in analyzer validation.
  • Add/adjust analyzer tests and snapshots to cover valid/invalid Dictionary<TKey, TValue> return types (including group loading).
  • Update HotChocolate documentation to reflect the expanded return-type contract.
File summaries
File Description
website/content/docs/hotchocolate/fetching-data/batching/dataloader.md Documents Dictionary<TKey, TValue> as an allowed batch DataLoader return type and updates the group-loading example.
src/HotChocolate/Core/test/Types.Analyzers.Tests/GenericDataLoaderAnalyzerTests.cs Adds valid/invalid Dictionary<TKey, TValue> return-type scenarios for the generic DataLoader analyzer.
src/HotChocolate/Core/test/Types.Analyzers.Tests/DataLoaderTests.cs Updates the generic contract test matrix to treat Task<Dictionary<,>> as a valid batch DataLoader contract.
src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/GenericDataLoaderAnalyzerTests.ValidGenericDataLoaderContracts_DoNotRaiseDiagnostics.md Updates generated-source snapshot to include DataLoaders based on Dictionary<TKey, TValue> return types.
src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/GenericDataLoaderAnalyzerTests.InvalidGenericDataLoaderContracts_RaiseExpectedDiagnostics.md Updates diagnostics snapshot message and adds new invalid-dictionary-key/value cases.
src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/GenericDataLoaderAnalyzerTests.ByRefGenericDataLoaderReturns_RaiseExpectedDiagnostics.md Updates diagnostics snapshot message to include Dictionary<TKey, TValue> as an allowed type (for the non-byref requirement cases).
src/HotChocolate/Core/src/Types.Analyzers/Models/GenericDataLoaderInfo.cs Updates the generator-side type checks to treat Dictionary<TKey, TValue> as an acceptable batch return dictionary shape.
src/HotChocolate/Core/src/Types.Analyzers/GenericDataLoaderAnalyzerHelper.cs Updates analyzer helper validation to allow Dictionary<TKey, TValue> return types for batch contracts.
src/HotChocolate/Core/src/Types.Analyzers/DataLoaderReturnTypeAnalyzer.cs Updates the reported diagnostic message for invalid batch return types to include Dictionary<TKey, TValue>.
Review details
  • Files reviewed: 9/9 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@michaelstaib
michaelstaib merged commit e559d2b into main Sep 8, 2026
151 of 152 checks passed
@michaelstaib
michaelstaib deleted the mst/dataloader-refinements branch September 8, 2026 10:24
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