fix(doctrine): changed BackedEnumFilterTrait from integer to int#7869
Open
xterr wants to merge 4 commits intoapi-platform:4.3from
Open
fix(doctrine): changed BackedEnumFilterTrait from integer to int#7869xterr wants to merge 4 commits intoapi-platform:4.3from
xterr wants to merge 4 commits intoapi-platform:4.3from
Conversation
…rm#7817) Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
BackedEnumFilterTrait::getDescription() returns 'integer' as the type for int-backed enum filters. FieldsBuilder::getFilterArgs() (in api-platform/graphql) checks this against TypeIdentifier::values() which contains 'int', not 'integer'. The mismatch causes the type to be treated as Type::object('integer'), which fails resolution in TypeConverter::convertPhpType(), throwing InvalidTypeException. This exception is silently caught in getResourceFieldConfiguration(), causing the entire QueryCollection to be dropped from the GraphQL schema.
Contributor
Author
|
Or better yet, the filter parameter can be strongly typed --- /dev/null
+++ ../Filter/BackedEnumFilterTrait.php
@@ -60,7 +60,7 @@
$isCollection = str_ends_with($filterParameterName, '[]');
$enumValues = array_map(static fn (\BackedEnum $case) => $case->value, $this->enumTypes[$property]::cases());
- $enumType = \is_int($enumValues[0] ?? null) ? 'int' : 'string';
+ $enumType = $this->enumTypes[$property];
$schema = $isCollection
? ['type' => 'array', 'items' => ['type' => $enumType, 'enum' => $enumValues]]--- /dev/null
+++ ../Type/TypeConverter.php
@@ -29,6 +29,7 @@
use GraphQL\Language\Parser;
use GraphQL\Type\Definition\NullableType;
use GraphQL\Type\Definition\Type as GraphQLType;
use Symfony\Component\PropertyInfo\Type as LegacyType;
use Symfony\Component\TypeInfo\Type;
use Symfony\Component\TypeInfo\Type\CollectionType;
@@ -168,6 +169,14 @@
try {
$resourceMetadataCollection = $this->resourceMetadataCollectionFactory->create($resourceClass);
} catch (ResourceClassNotFoundException) {
+ if (\is_a($resourceClass, \BackedEnum::class, true)) {
+ $enumOperation = (new Query())
+ ->withClass($resourceClass)
+ ->withShortName((new \ReflectionClass($resourceClass))->getShortName());
+
+ return $this->typeBuilder->getEnumType($enumOperation);
+ }
+
return null;
}
|
Member
|
@MeronNagy @mremi would you have an opinion on this? I don't use backed enums that much. |
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.
BackedEnumFilterTrait::getDescription() returns 'integer' as the type for int-backed enum filters. FieldsBuilder::getFilterArgs() (in api-platform/graphql) checks this against TypeIdentifier::values() which contains 'int', not 'integer'. The mismatch causes the type to be treated as Type::object('integer'), which fails resolution in TypeConverter::convertPhpType(), throwing InvalidTypeException. This exception is silently caught in getResourceFieldConfiguration(), causing the entire QueryCollection to be dropped from the GraphQL schema.
Branch: