Skip to content

Commit 780d3cf

Browse files
jsampedro77soyuka
authored andcommitted
fix(graphql): stateOptions to get filter class
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 99718d9 commit 780d3cf

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
@@ -29,6 +29,7 @@
2929
use ApiPlatform\Metadata\ResourceClassResolverInterface;
3030
use ApiPlatform\Metadata\Util\Inflector;
3131
use ApiPlatform\State\Pagination\Pagination;
32+
use ApiPlatform\State\Util\StateOptionsTrait;
3233
use GraphQL\Type\Definition\InputObjectType;
3334
use GraphQL\Type\Definition\ListOfType;
3435
use GraphQL\Type\Definition\NonNull;
@@ -48,6 +49,8 @@
4849
*/
4950
final class FieldsBuilder implements FieldsBuilderEnumInterface
5051
{
52+
use StateOptionsTrait;
53+
5154
private readonly ContextAwareTypeBuilderInterface $typeBuilder;
5255

5356
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())
@@ -561,7 +564,8 @@ private function getFilterArgs(array $args, ?string $resourceClass, string $root
561564
continue;
562565
}
563566

564-
foreach ($this->filterLocator->get($filterId)->getDescription($resourceClass) as $key => $description) {
567+
$entityClass = $this->getStateOptionsClass($resourceOperation, $resourceOperation->getClass());
568+
foreach ($this->filterLocator->get($filterId)->getDescription($entityClass) as $key => $description) {
565569
$nullable = isset($description['required']) ? !$description['required'] : true;
566570
$filterType = \in_array($description['type'], Type::$builtinTypes, true) ? new Type($description['type'], $nullable) : new Type('object', $nullable, $description['type']);
567571
$graphqlFilterType = $this->convertType($filterType, false, $resourceOperation, $rootOperation, $resourceClass, $rootResource, $property, $depth);

0 commit comments

Comments
 (0)