Skip to content

fix(doctrine): changed BackedEnumFilterTrait from integer to int#7869

Open
xterr wants to merge 4 commits intoapi-platform:4.3from
xterr:patch-1
Open

fix(doctrine): changed BackedEnumFilterTrait from integer to int#7869
xterr wants to merge 4 commits intoapi-platform:4.3from
xterr:patch-1

Conversation

@xterr
Copy link
Copy Markdown
Contributor

@xterr xterr commented Mar 24, 2026

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:

  • the stable/latest 4.x for bug fixes
  • main for new features

soyuka and others added 4 commits March 5, 2026 11:20
…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.
@xterr xterr changed the title Patch 1 Changed BackedEnumFilterTrait from integer to int Mar 24, 2026
@xterr xterr changed the title Changed BackedEnumFilterTrait from integer to int fix(doctrine): changed BackedEnumFilterTrait from integer to int Mar 24, 2026
@xterr
Copy link
Copy Markdown
Contributor Author

xterr commented Mar 24, 2026

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;
         }
 

@soyuka
Copy link
Copy Markdown
Member

soyuka commented Mar 25, 2026

@MeronNagy @mremi would you have an opinion on this? I don't use backed enums that much.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants