Repository navigation
Fix input-object validation issue - #1215
Merged
Merged
Conversation
murtukov
marked this pull request as draft
November 3, 2025 06:14
* Adjust validation for nested and partial input objects. * Refactor metadata handling in `InputValidator`. * Add test for `partialInputObjectsCollectionValidation`. * Remove test `testOnlyPassedFieldsValidated`. * Update validation constraints in YAML configuration files.
* Add missing trailing commas to array elements.
murtukov
force-pushed
the
fix-validation-bug
branch
from
November 4, 2025 19:48
eecaaee to
8b32024
Compare
murtukov
marked this pull request as ready for review
November 4, 2025 19:49
input-object validation issue
murtukov
commented
Nov 4, 2025
Comment on lines
+127
to
+139
| private function getMetadata(ValidationNode $rootObject): ObjectMetadata | ||
| { | ||
| // Return existing metadata if present | ||
| if ($this->metadataFactory->hasMetadataFor($rootObject)) { | ||
| return $this->metadataFactory->getMetadataFor($rootObject); | ||
| } | ||
|
|
||
| // Create new metadata and add it to the factory | ||
| $metadata = new ObjectMetadata($rootObject); | ||
| $this->metadataFactory->addMetadata($metadata); | ||
|
|
||
| return $metadata; | ||
| } |
Contributor
Author
There was a problem hiding this comment.
This method reuses metadata if it was already created for the input-object of the same type
murtukov
commented
Nov 4, 2025
| $metadata->addPropertyConstraint($property, $valid); | ||
|
|
||
| // Skip the rest as the validation was delegated to the nested object. | ||
| continue; |
Contributor
Author
There was a problem hiding this comment.
There is no need to proceed and add any more constraints if it was set to cascade
murtukov
commented
Nov 4, 2025
Comment on lines
+186
to
+188
| if ($metadata->hasPropertyMetadata($property)) { | ||
| continue; | ||
| } |
Contributor
Author
There was a problem hiding this comment.
If constraints were set for the property, don't add them the second time
murtukov
commented
Nov 4, 2025
Comment on lines
+383
to
+422
| $query = ' | ||
| mutation { | ||
| partialInputObjectsCollectionValidation( | ||
| addresses: [ | ||
| { | ||
| street: "Washington Street" | ||
| city: "Berlin" | ||
| zipCode: 10000 | ||
| # Country is present, but the language is invalid | ||
| country: { | ||
| name: "Germany" | ||
| officialLanguage: "ru" | ||
| } | ||
| # Period is completely missing, skip validation | ||
| }, | ||
| { | ||
| street: "Washington Street" | ||
| city: "New York" | ||
| zipCode: 10000 | ||
| # Country is partially present | ||
| country: { | ||
| name: "" # Name should not be blank | ||
| # language is missing | ||
| } | ||
| period: { | ||
| startDate: "2000-01-01" | ||
| endDate: "1990-01-01" | ||
| } | ||
| }, | ||
| { | ||
| street: "Washington Street" | ||
| city: "New York" | ||
| zipCode: 10000 | ||
| country: {} # Empty input object, skip validation | ||
| period: {} # Empty input object, skip validation | ||
| } | ||
| ] | ||
| ) | ||
| } | ||
| '; |
Contributor
Author
There was a problem hiding this comment.
A new test case to cover scenarios when input objects (country and period) have all fields, partial fields, or no fields at all.
Contributor
Author
|
@mcg-web, since you already approved the same PR for the branch 0.13, I will consider this one approved as well. |
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.
As mentioned in the ticket, there was an issue with the validation metadata for collections of input objects: only the metadata of the last item in the collection was used to validate all items in the collection.
This change introduces metadata caching, so that the same object is used for all elements in the collection.