Projections: Support selecting only __typename on union types #8716
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary of the changes (Less than 80 chars)
Closes #8252 (in this specific format)
Background:
If no 'real' member of an entity was requested as part of the selection set, like in
the projected query currenty looks like this:
However,
new ConcreteType1 {}
cannot be translated to SQL, which leads to the following exception:I fixed this by transforming the query into:
This approach selects the entire record, so it indeed overfetches. Anyways, it seems to be the simplest solution that works in all cases.
I considered selecting just one property instead, but that seems to be hacky and tricky since we cant know for sure whether a property is actually part of the table or just a calculated helper property. Because we’re only selecting the values of the base type and also do not eager load navigation properties, I believe the performance penalty from this overfetching is negligible compared to correctness. Also this seems to be a rare edge case.
However, if another approach is preferred - like the one with just selecting one property-, please let me know and I can reevaluate this.