Skip to content

Commit 4811130

Browse files
committed
fix(graphql): name converter with class (#6396)
* fix(graphql): name converter with class see symfony/symfony@d088047 * fix(serializer): metadata name converter bc layer
1 parent e4adc49 commit 4811130

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

src/GraphQl/Serializer/SerializerContextBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use ApiPlatform\Metadata\GraphQl\Subscription;
1919
use GraphQL\Type\Definition\ResolveInfo;
2020
use Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface;
21+
use Symfony\Component\Serializer\NameConverter\MetadataAwareNameConverter;
2122
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
2223

2324
/**
@@ -101,7 +102,7 @@ private function denormalizePropertyName(string $property, ?string $resourceClas
101102
if (null === $this->nameConverter) {
102103
return $property;
103104
}
104-
if ($this->nameConverter instanceof AdvancedNameConverterInterface) {
105+
if ($this->nameConverter instanceof AdvancedNameConverterInterface || $this->nameConverter instanceof MetadataAwareNameConverter) {
105106
return $this->nameConverter->denormalize($property, $resourceClass, null, $context);
106107
}
107108

src/GraphQl/Type/FieldsBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use Symfony\Component\Config\Definition\Exception\InvalidTypeException;
3939
use Symfony\Component\PropertyInfo\Type;
4040
use Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface;
41+
use Symfony\Component\Serializer\NameConverter\MetadataAwareNameConverter;
4142
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
4243

4344
/**
@@ -572,7 +573,7 @@ private function normalizePropertyName(string $property, string $resourceClass):
572573
if (null === $this->nameConverter) {
573574
return $property;
574575
}
575-
if ($this->nameConverter instanceof AdvancedNameConverterInterface) {
576+
if ($this->nameConverter instanceof AdvancedNameConverterInterface || $this->nameConverter instanceof MetadataAwareNameConverter) {
576577
return $this->nameConverter->normalize($property, $resourceClass);
577578
}
578579

src/Serializer/AbstractConstraintViolationListNormalizer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace ApiPlatform\Serializer;
1515

1616
use Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface;
17+
use Symfony\Component\Serializer\NameConverter\MetadataAwareNameConverter;
1718
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
1819
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
1920
use Symfony\Component\Serializer\Serializer;
@@ -76,7 +77,7 @@ protected function getMessagesAndViolations(ConstraintViolationListInterface $co
7677
foreach ($constraintViolationList as $violation) {
7778
$class = \is_object($root = $violation->getRoot()) ? $root::class : null;
7879

79-
if ($this->nameConverter instanceof AdvancedNameConverterInterface) {
80+
if ($this->nameConverter instanceof AdvancedNameConverterInterface || $this->nameConverter instanceof MetadataAwareNameConverter) {
8081
$propertyPath = $this->nameConverter->normalize($violation->getPropertyPath(), $class, static::FORMAT);
8182
} elseif ($this->nameConverter instanceof NameConverterInterface) {
8283
$propertyPath = $this->nameConverter->normalize($violation->getPropertyPath());

src/Symfony/Validator/Serializer/ValidationExceptionNormalizer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ApiPlatform\Serializer\CacheableSupportsMethodInterface;
1717
use ApiPlatform\Symfony\Validator\Exception\ValidationException;
1818
use Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface;
19+
use Symfony\Component\Serializer\NameConverter\MetadataAwareNameConverter;
1920
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
2021
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
2122
use Symfony\Component\Serializer\Serializer;
@@ -32,7 +33,7 @@ public function normalize(mixed $object, ?string $format = null, array $context
3233
foreach ($object->getConstraintViolationList() as $violation) {
3334
$class = \is_object($root = $violation->getRoot()) ? $root::class : null;
3435

35-
if ($this->nameConverter instanceof AdvancedNameConverterInterface) {
36+
if ($this->nameConverter instanceof AdvancedNameConverterInterface || $this->nameConverter instanceof MetadataAwareNameConverter) {
3637
$propertyPath = $this->nameConverter->normalize($violation->getPropertyPath(), $class, $format);
3738
} elseif ($this->nameConverter instanceof NameConverterInterface) {
3839
$propertyPath = $this->nameConverter->normalize($violation->getPropertyPath());

0 commit comments

Comments
 (0)