fix(graphql): avoid partial field declarations from inherited metadata with cli plugin #3270
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.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
The former logic was accessing the inherited metadata factory, I guess when the current class didn't have one.
The parent class could have fields that the plugin cannot determine, and are explicitly declared with
@Field
decorators.The partial info & the type from decorator are merged together for that base type.
But here when the subclass was redefining this field it only had partial info, no type.
This caused the complication logic to fail, because the
typeFn
would be missing.Instead, we only want to look for the own metadata factory, and ignore if there is none.
Just to note: inherited fields are merged elsewhere (in factories), so this doesn't need to try.
A minimal reproduction is
With this example,
Person
&Entity
will have metadata loaded /_GRAPHQL_METADATA_FACTORY
property assigned.The problem is that
resolves to
Entity
's_GRAPHQL_METADATA_FACTORY
💥 , but it's registered as theLivingBeingClass
type.⭐ The logic should be to skip because no
_GRAPHQL_METADATA_FACTORY
is declared forLivingBeingClass
.Entity
's metadata is merged with the decorator, so the plugin doesn't provide thetype
, but the decorator does.However,
LivingBeingClass
does not have this field metadata merged since theEntity.id
decorator is not its own (guessing on why).The factories throw because
LivingBeingClass.id
does not have atype
even though its parent class does.The metadata should ignore this field for this intermediate class since it doesn't do anything with it - it just inherits.
What is the new behavior?
Error is avoided. Fields are still merged/inherited as expected.
Does this PR introduce a breaking change?
Other information
I also added a check to avoid merging metadata for common parents.
i.e.
TypeMetadataStorage.addClassFieldMetadata
would previous be called forEntity.id
for every concrete type extendingEntity
. Which is redundant work after the first time.