Skip to content

Fix source-generated batch resolvers with a keyed service not compiling - #10442

Merged
glen-84 merged 1 commit into
mainfrom
gai/batch-resolver-keyed-service-literal
Sep 28, 2026
Merged

glen-84 merged 1 commit into
mainfrom
gai/batch-resolver-keyed-service-literal

Conversation

@glen-84

@glen-84 glen-84 commented Sep 28, 2026

Copy link
Copy Markdown
Member

Summary

  • A source-generated [BatchResolver] with a keyed [Service("greeting")] parameter emitted contexts[0].Service<T>(""greeting""), which does not compile. The service key reaches the file builder as a formatted C# literal, and the batch path wrapped it in a second pair of quotes. The batch path now emits the literal as-is, the same as the regular resolver path.
  • The key became a formatted literal in Add keyed service support to DataLoaders #10314, so this affects the 16.7 previews only.

Test plan

  • Added BatchResolver_With_KeyedService_MatchesSnapshot. Its snapshot shows Service<GreetingService>("greeting") and no diagnostics. With the fix reverted, the same test fails with CS1003 and CS0103 in the emitted assembly.
  • Types.Analyzers.Tests and Types.Analyzers.Integration.Tests pass on net10.0.

Copilot AI lite review requested due to automatic review settings September 28, 2026 15:06

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.

Copilot review overview

🟢 Approval recommended

No unresolved issues were identified that would block approval.

Review effort: Lite
Findings: None

What changed in this PR

Fixes source-generated batch resolvers with keyed services by emitting preformatted service keys correctly.

Changes:

  • Removes duplicate quoting in batch resolver generation.
  • Adds a keyed-service regression snapshot test.
  • Updates the expected generated source snapshot.
File Description
src/​HotChocolate/​Core/​test/​Types.Analyzers.Tests/​ObjectTypeTests.cs Updated as part of this pull request.
src/​HotChocolate/​Core/​test/​Types.Analyzers.Tests/​__snapshots__/​ObjectTypeTests.BatchResolver_With_KeyedService_MatchesSnapshot.md Updated as part of this pull request.
src/​HotChocolate/​Core/​src/​Types.Analyzers/​FileBuilders/​TypeFileBuilderBase.cs Updated as part of this pull request.

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

@github-actions

Copy link
Copy Markdown
Contributor

Patch coverage

100.0% of changed lines covered (1/1)

File Covered Changed Patch %
…/Core/src/Types.Analyzers/FileBuilders/TypeFileBuilderBase.cs 1 1 100.0% 🟢

Project coverage: 58.8% (298893/508115 lines)

@glen-84
glen-84 merged commit 7448823 into main Sep 28, 2026
306 of 308 checks passed
@glen-84
glen-84 deleted the gai/batch-resolver-keyed-service-literal branch September 28, 2026 15:22
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