enhance: Union types construct class instances in ctrl.fetch() resolution value #3063
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.
Motivation
ctrl.fetch() resolution should always be denormalized if possible. Previously, we would skip class instantiation (and other denorm things) with Polymorphic types, as they use a special normalized format to select the schema for denormalization.
Solution
Polymorphic (Union) types should still denormalize when handling passthrough (non-normalized) data
When denormalizing non-normalized (like return of ctrl.fetch), it is still expected to handle
all steps like constructing class instances if possible. However, to do this for Polymorphic
types we need to fallback to using part of the normalize process to find out which schema
to use for the remainder of denormalization.
This also removes extra console.warn that would appear when using useSuspense() or other hooks, even though the normalize+denormalize worked fine - since ctrl.fetch() always runs denormalize in 'passthrough' mode (without entities or normalized input).
Before
After