Projections: Support selecting only __typename on union types#8716
Closed
N-Olbert wants to merge 1 commit intoChilliCream:mainfrom
Closed
Projections: Support selecting only __typename on union types#8716N-Olbert wants to merge 1 commit intoChilliCream:mainfrom
N-Olbert wants to merge 1 commit intoChilliCream:mainfrom
Conversation
Member
|
@N-Olbert we at the moment do not touch anything regarding HotChocolate.Data or GreenDonut.Data as we plan to bring them together. We will pull out the projections engine and rearchitecture it. I can involve you into that process, but it will be somewhere in November as we are focused on Fusion at this point. |
Contributor
Author
|
@michaelstaib sure, ping me then. Do you think it makes sense to add the (failing or skipped) tests now, so that this case won't be forgotten then? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
{ foo { items { # This is a union of ConcreteType1|ConcreteType2 __typename ... on ConcreteType2 { foo } } } }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.