Skip to content

Commit c89d93d

Browse files
committed
Use stateOptionsTrait to get real entity name
The resource filters were lost when using a DTO as Resource and using stateOptions with 'entityClass' to specify which is the real doctrine class.
1 parent 8c27606 commit c89d93d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/GraphQl/Type/FieldsBuilder.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use ApiPlatform\Metadata\Util\PropertyInfoToTypeInfoHelper;
3232
use ApiPlatform\Metadata\Util\TypeHelper;
3333
use ApiPlatform\State\Pagination\Pagination;
34+
use ApiPlatform\State\Util\StateOptionsTrait;
3435
use GraphQL\Type\Definition\InputObjectType;
3536
use GraphQL\Type\Definition\ListOfType;
3637
use GraphQL\Type\Definition\NonNull;
@@ -55,6 +56,8 @@
5556
*/
5657
final class FieldsBuilder implements FieldsBuilderEnumInterface
5758
{
59+
use StateOptionsTrait;
60+
5861
private readonly ContextAwareTypeBuilderInterface $typeBuilder;
5962

6063
public function __construct(private readonly PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, private readonly PropertyMetadataFactoryInterface $propertyMetadataFactory, private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory, private readonly ResourceClassResolverInterface $resourceClassResolver, private readonly TypesContainerInterface $typesContainer, ContextAwareTypeBuilderInterface $typeBuilder, private readonly TypeConverterInterface $typeConverter, private readonly ResolverFactoryInterface $resolverFactory, private readonly ContainerInterface $filterLocator, private readonly Pagination $pagination, private readonly ?NameConverterInterface $nameConverter, private readonly string $nestingSeparator, private readonly ?InflectorInterface $inflector = new Inflector())
@@ -606,7 +609,8 @@ private function getFilterArgs(array $args, ?string $resourceClass, string $root
606609
continue;
607610
}
608611

609-
foreach ($this->filterLocator->get($filterId)->getDescription($resourceClass) as $key => $description) {
612+
$entityClass = $this->getStateOptionsClass($resourceOperation, $resourceOperation->getClass());
613+
foreach ($this->filterLocator->get($filterId)->getDescription($entityClass) as $key => $description) {
610614
$filterType = \in_array($description['type'], TypeIdentifier::values(), true) ? Type::builtin($description['type']) : Type::object($description['type']);
611615
if (!($description['required'] ?? false)) {
612616
$filterType = Type::nullable($filterType);

0 commit comments

Comments
 (0)