Skip to content

Conversation

@murtukov
Copy link
Contributor

@murtukov murtukov commented Nov 2, 2025

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Documented? no
Fixed tickets #1168
License MIT

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.

@murtukov 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 murtukov marked this pull request as ready for review November 4, 2025 19:49
@murtukov murtukov changed the title [WIP] Refactor validation mappings and tests Refactor validation mappings and tests Nov 4, 2025
@murtukov murtukov changed the title Refactor validation mappings and tests Fix input-object validation issue Nov 4, 2025
@murtukov murtukov added the bug label Nov 4, 2025
@murtukov murtukov linked an issue Nov 4, 2025 that may be closed by this pull request
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;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method reuses metadata if it was already created for the input-object of the same type

$metadata->addPropertyConstraint($property, $valid);

// Skip the rest as the validation was delegated to the nested object.
continue;
Copy link
Contributor Author

@murtukov murtukov Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to proceed and add any more constraints if it was set to cascade

Comment on lines +186 to +188
if ($metadata->hasPropertyMetadata($property)) {
continue;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If constraints were set for the property, don't add them the second time

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
}
]
)
}
';
Copy link
Contributor Author

@murtukov murtukov Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new test case to cover scenarios when input objects (country and period) have all fields, partial fields, or no fields at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multi level Input-object validation issue

3 participants