Skip to content

Fix AsSelector throwing on types with only non-public constructors#9998

Open
michaelstaib wants to merge 1 commit into
mainfrom
mst/fix-AsSelector
Open

Fix AsSelector throwing on types with only non-public constructors#9998
michaelstaib wants to merge 1 commit into
mainfrom
mst/fix-AsSelector

Conversation

@michaelstaib

@michaelstaib michaelstaib commented Jun 29, 2026

Copy link
Copy Markdown
Member

Closes #9666

Copilot AI review requested due to automatic review settings June 29, 2026 09:01

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

Fixes a failure in SelectionExpressionBuilder where AsSelector<T> could throw for entity types that can’t be reconstructed via public constructors / public setters (notably types with only non-public constructors), by falling back to reusing the source instance instead of throwing.

Changes:

  • Changed projection expression generation to return the source instance (context.Parent) as a last-resort fallback rather than throwing InvalidOperationException.
  • Added a regression test covering projection with AsSelector over a type that has only private constructors and private setters.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/HotChocolate/Data/test/Data.Tests/ResolveWithProjectionTests.cs Adds a regression test ensuring AsSelector works for types with only private constructors.
src/HotChocolate/Core/src/Execution.Projections/SelectionExpressionBuilder.cs Replaces the throw-on-unconstructable-types behavior with a safe identity/reuse fallback.

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

@github-actions

Copy link
Copy Markdown
Contributor

Patch coverage

100.0% of changed lines covered (1/1)

File Covered Changed Patch %
…/Core/src/Execution.Projections/SelectionExpressionBuilder.cs 1 1 100.0% 🟢

Project coverage: 52.4% (215339/411051 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