Description
In our codebase we use a different createQueryBuilder, named createUserFilteredQueryBuilder, to make sure that no queries is generated without global constraint.
Since ApiPlatform enforce using a specific method we are forced to a lot of DI customization to override the limitation.
Possible Implementation
First thing first: I will provide a MR for this, but I'd like a feedback before start.
This is the line that need improvements:
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): iterable |
|
{ |
|
$entityClass = $this->getStateOptionsClass($operation, $operation->getClass(), Options::class); |
|
|
|
/** @var EntityManagerInterface $manager */ |
|
$manager = $this->managerRegistry->getManagerForClass($entityClass); |
|
|
|
$repository = $manager->getRepository($entityClass); |
|
if (!method_exists($repository, 'createQueryBuilder')) { |
|
throw new RuntimeException('The repository class must have a "createQueryBuilder" method.'); |
|
} |
|
|
|
$queryBuilder = $repository->createQueryBuilder('o'); |
(Same for Item Providers and ODM Providers)
If I understand the code correctly, I have to add a nullable option createQueryBuilderMethod to ApiPlatform\Doctrine\Common\State\Options, and than fallback to createQueryBuilder where it's used in the current codebase.
My questions are:
- Am I correct that "state options" is the right place? If so, can you confirm that no changes is required to the API metadata (and factories)?
- Have you any recommendation for testing this changes? I see only the
CollectionProviderTests and ItemProviderTest that seems related
Thank you!
Description
In our codebase we use a different
createQueryBuilder, namedcreateUserFilteredQueryBuilder, to make sure that no queries is generated without global constraint.Since ApiPlatform enforce using a specific method we are forced to a lot of DI customization to override the limitation.
Possible Implementation
First thing first: I will provide a MR for this, but I'd like a feedback before start.
This is the line that need improvements:
core/src/Doctrine/Orm/State/CollectionProvider.php
Lines 51 to 63 in 080574a
(Same for Item Providers and ODM Providers)
If I understand the code correctly, I have to add a nullable option
createQueryBuilderMethodtoApiPlatform\Doctrine\Common\State\Options, and than fallback tocreateQueryBuilderwhere it's used in the current codebase.My questions are:
CollectionProviderTests andItemProviderTestthat seems relatedThank you!