Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion features/filter/filter_validation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Feature: Validate filters based upon filter description
Scenario: Required filter should throw an error if not set
When I am on "/filter_validators"
Then the response status code should be 422
And the JSON node "detail" should be equal to 'required: This value should not be blank.\nrequired-allow-empty: The parameter "required-allow-empty" is required.'
And the JSON node "detail" should be equal to 'required: This value should not be blank.\nrequired-allow-empty: This value should not be null.'

Scenario: Required filter should not throw an error if set
When I am on "/array_filter_validators?arrayRequired[]=foo&indexedArrayRequired[foo]=foo"
Expand Down
2 changes: 1 addition & 1 deletion features/http_cache/headers.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Feature: Default values of HTTP cache headers
Then the response status code should be 200
And the header "Etag" should be equal to '"032297ac74d75a50"'
And the header "Cache-Control" should be equal to "max-age=60, public, s-maxage=3600"
And the header "Vary" should be equal to "Accept, Cookie"
And the header "Vary" should be equal to "Accept, Cookie, Accept-Language"
21 changes: 12 additions & 9 deletions src/Doctrine/Orm/Extension/ParameterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use ApiPlatform\Doctrine\Common\Filter\LoggerAwareInterface;
use ApiPlatform\Doctrine\Common\Filter\ManagerRegistryAwareInterface;
use ApiPlatform\Doctrine\Common\Filter\PropertyAwareFilterInterface;
use ApiPlatform\Doctrine\Common\ParameterValueExtractorTrait;
use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter;
use ApiPlatform\Doctrine\Orm\Filter\FilterInterface;
Expand Down Expand Up @@ -75,19 +76,21 @@ private function applyFilter(QueryBuilder $queryBuilder, QueryNameGeneratorInter
$filter->setLogger($this->logger);
}

if ($filter instanceof AbstractFilter && !$filter->getProperties()) {
if ($filter instanceof PropertyAwareFilterInterface) {
$properties = [];
$propertyKey = $parameter->getProperty() ?? $parameter->getKey();

if (str_contains($propertyKey, ':property')) {
$extraProperties = $parameter->getExtraProperties()['_properties'] ?? [];
foreach (array_keys($extraProperties) as $property) {
$properties[$property] = $parameter->getFilterContext();
if ($filter instanceof AbstractFilter) {
$properties = $filter->getProperties() ?? [];

if (str_contains($propertyKey, ':property')) {
$extraProperties = $parameter->getExtraProperties()['_properties'] ?? [];
foreach (array_keys($extraProperties) as $property) {
$properties[$property] = $parameter->getFilterContext();
}
}
} else {
$properties = [$propertyKey => $parameter->getFilterContext()];
}

$filter->setProperties($properties ?? []);
$filter->setProperties($properties + [$propertyKey => $parameter->getFilterContext()]);
}

$filter->apply($queryBuilder, $queryNameGenerator, $resourceClass, $operation,
Expand Down
8 changes: 6 additions & 2 deletions src/GraphQl/Type/FieldsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use ApiPlatform\Metadata\Util\PropertyInfoToTypeInfoHelper;
use ApiPlatform\Metadata\Util\TypeHelper;
use ApiPlatform\State\Pagination\Pagination;
use ApiPlatform\State\Util\StateOptionsTrait;
use GraphQL\Type\Definition\InputObjectType;
use GraphQL\Type\Definition\ListOfType;
use GraphQL\Type\Definition\NonNull;
Expand All @@ -55,6 +56,8 @@
*/
final class FieldsBuilder implements FieldsBuilderEnumInterface
{
use StateOptionsTrait;

private readonly ContextAwareTypeBuilderInterface $typeBuilder;

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())
Expand Down Expand Up @@ -85,7 +88,7 @@ public function getItemQueryFields(string $resourceClass, Operation $operation,
return [];
}

$fieldName = lcfirst('item_query' === $operation->getName() ? $operation->getShortName() : $operation->getName().$operation->getShortName());
$fieldName = lcfirst('item_query' === $operation->getName() ? ($operation->getShortName() ?? $operation->getName()) : $operation->getName().$operation->getShortName());

if ($fieldConfiguration = $this->getResourceFieldConfiguration(null, $operation->getDescription(), $operation->getDeprecationReason(), Type::nullable(Type::object($resourceClass)), $resourceClass, false, $operation)) {
$args = $this->resolveResourceArgs($configuration['args'] ?? [], $operation);
Expand Down Expand Up @@ -606,7 +609,8 @@ private function getFilterArgs(array $args, ?string $resourceClass, string $root
continue;
}

foreach ($this->filterLocator->get($filterId)->getDescription($resourceClass) as $key => $description) {
$entityClass = $this->getStateOptionsClass($resourceOperation, $resourceOperation->getClass());
foreach ($this->filterLocator->get($filterId)->getDescription($entityClass) as $key => $description) {
$filterType = \in_array($description['type'], TypeIdentifier::values(), true) ? Type::builtin($description['type']) : Type::object($description['type']);
if (!($description['required'] ?? false)) {
$filterType = Type::nullable($filterType);
Expand Down
14 changes: 7 additions & 7 deletions src/Laravel/ApiPlatformProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
use ApiPlatform\Laravel\Eloquent\PropertyAccess\PropertyAccessor as EloquentPropertyAccessor;
use ApiPlatform\Laravel\Eloquent\PropertyInfo\EloquentExtractor;
use ApiPlatform\Laravel\Eloquent\Serializer\EloquentNameConverter;
use ApiPlatform\Laravel\Eloquent\Serializer\Mapping\Loader\AttributeLoader as EloquentAttributeLoader;
use ApiPlatform\Laravel\Eloquent\Serializer\Mapping\Loader\RelationMetadataLoader;
use ApiPlatform\Laravel\Eloquent\Serializer\SerializerContextBuilder as EloquentSerializerContextBuilder;
use ApiPlatform\Laravel\GraphQl\Controller\EntrypointController as GraphQlEntrypointController;
use ApiPlatform\Laravel\GraphQl\Controller\GraphiQlController;
Expand Down Expand Up @@ -174,7 +176,6 @@
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
use Symfony\Component\Serializer\Mapping\Loader\LoaderChain;
use Symfony\Component\Serializer\Mapping\Loader\LoaderInterface;
use Symfony\Component\Serializer\NameConverter\MetadataAwareNameConverter;
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
use Symfony\Component\Serializer\NameConverter\SnakeCaseToCamelCaseNameConverter;
Expand Down Expand Up @@ -216,7 +217,6 @@ public function register(): void
return new ModelMetadata();
});

$this->app->bind(LoaderInterface::class, AttributeLoader::class);
$this->app->bind(ClassMetadataFactoryInterface::class, ClassMetadataFactory::class);
$this->app->singleton(ClassMetadataFactory::class, function (Application $app) {
/** @var ConfigRepository */
Expand All @@ -232,8 +232,8 @@ public function register(): void
$app->make(PropertyNameCollectionFactoryInterface::class),
$nameConverter
),
new AttributeLoader(),
// new RelationMetadataLoader($app->make(ModelMetadata::class)),
new EloquentAttributeLoader(new AttributeLoader()),
new RelationMetadataLoader($app->make(ModelMetadata::class)),
])
);
});
Expand Down Expand Up @@ -330,8 +330,8 @@ public function register(): void
);
});

$this->app->bind(PropertyAccessorInterface::class, function () {
return new EloquentPropertyAccessor();
$this->app->bind(PropertyAccessorInterface::class, function (Application $app) {
return new EloquentPropertyAccessor(null, $app->make(ModelMetadata::class));
});

$this->app->bind(NameConverterInterface::class, function (Application $app) {
Expand Down Expand Up @@ -467,7 +467,7 @@ public function register(): void
$config = $app['config'];
$defaultContext = $config->get('api-platform.serializer', []);

return new ObjectNormalizer(defaultContext: $defaultContext);
return new ObjectNormalizer($app->make(ClassMetadataFactoryInterface::class), defaultContext: $defaultContext);
});

$this->app->singleton(DateTimeNormalizer::class, function (Application $app) {
Expand Down
Loading
Loading