Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(metadata): get graphql operation when available #4522

Merged
merged 1 commit into from
Oct 25, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Bridge/Doctrine/Odm/State/CollectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function provide(string $resourceClass, array $identifiers = [], ?string

$resourceMetadata = $this->resourceMetadataCollectionFactory->create($resourceClass);
try {
$operation = $context['operation'] ?? (isset($context['graphql_operation_name']) ? $resourceMetadata->getGraphQlOperation($operationName) : $resourceMetadata->getOperation($operationName));
$operation = $context['operation'] ?? $resourceMetadata->getOperation($operationName);
$attribute = $operation->getExtraProperties()['doctrine_mongodb'] ?? [];
} catch (OperationNotFoundException $e) {
$attribute = $resourceMetadata->getOperation(null, true)->getExtraProperties()['doctrine_mongodb'] ?? [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function getCollection(string $resourceClass, string $operationName = nul

$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
try {
$operation = $context['operation'] ?? (isset($context['graphql_operation_name']) ? $resourceMetadata->getGraphQlOperation($operationName) : $resourceMetadata->getOperation($operationName));
$operation = $context['operation'] ?? $resourceMetadata->getOperation($operationName);
$attribute = $operation->getExtraProperties()['doctrine_mongodb'] ?? [];
} catch (OperationNotFoundException $e) {
$attribute = $resourceMetadata->getOperation(null, true)->getExtraProperties()['doctrine_mongodb'] ?? [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function applyToCollection(Builder $aggregationBuilder, string $resourceC
{
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
try {
$operation = isset($context['graphql_operation_name']) ? $resourceMetadata->getGraphQlOperation($operationName) : $resourceMetadata->getOperation($operationName);
$operation = $resourceMetadata->getOperation($operationName);
$resourceFilters = $operation->getFilters();
} catch (OperationNotFoundException $e) {
$resourceFilters = $resourceMetadata->getOperation(null, true)->getFilters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function applyToCollection(Builder $aggregationBuilder, string $resourceC
} else {
$metadata = $this->resourceMetadataFactory->create($resourceClass);
try {
$defaultOrder = isset($context['graphql_operation_name']) ? $metadata->getGraphQlOperation($operationName)->getOrder() : $metadata->getOperation($operationName)->getOrder();
$defaultOrder = $metadata->getOperation($operationName)->getOrder();
} catch (OperationNotFoundException $e) {
$defaultOrder = $metadata->getOperation(null, true)->getOrder();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function getResult(Builder $aggregationBuilder, string $resourceClass, st

$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
try {
$operation = $context['operation'] ?? (isset($context['graphql_operation_name']) ? $resourceMetadata->getGraphQlOperation($operationName) : $resourceMetadata->getOperation($operationName));
$operation = $context['operation'] ?? $resourceMetadata->getOperation($operationName);
$attribute = $operation->getExtraProperties()['doctrine_mongodb'] ?? [];
} catch (OperationNotFoundException $e) {
$attribute = $resourceMetadata->getOperation(null, true)->getExtraProperties()['doctrine_mongodb'] ?? [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function getSubresource(string $resourceClass, array $identifiers, array

$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
try {
$operation = $context['operation'] ?? (isset($context['graphql_operation_name']) ? $resourceMetadata->getGraphQlOperation($operationName) : $resourceMetadata->getOperation($operationName));
$operation = $context['operation'] ?? $resourceMetadata->getOperation($operationName);
$attribute = $operation->getExtraProperties()['doctrine_mongodb'] ?? [];
} catch (OperationNotFoundException $e) {
$attribute = $resourceMetadata->getOperation()->getExtraProperties()['doctrine_mongodb'] ?? [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private function apply(bool $collection, QueryBuilder $queryBuilder, QueryNameGe
if ($this->resourceMetadataFactory instanceof ResourceMetadataCollectionFactoryInterface) {
$resourceMetadataCollection = $this->resourceMetadataFactory->create($resourceClass);
try {
$operation = isset($context['graphql_operation_name']) ? $resourceMetadataCollection->getGraphQlOperation($operationName) : $resourceMetadataCollection->getOperation($operationName);
$operation = $resourceMetadataCollection->getOperation($operationName);
$forceEager = $operation->getForceEager() ?? $this->forceEager;
$fetchPartial = $operation->getFetchPartial() ?? $this->fetchPartial;
} catch (OperationNotFoundException $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGenerator
if ($this->resourceMetadataFactory instanceof ResourceMetadataCollectionFactoryInterface) {
$resourceMetadataCollection = $this->resourceMetadataFactory->create($resourceClass);
try {
$operation = isset($context['graphql_operation_name']) ? $resourceMetadataCollection->getGraphQlOperation($operationName) : $resourceMetadataCollection->getOperation($operationName);
$operation = $resourceMetadataCollection->getOperation($operationName);
$forceEager = $operation->getForceEager() ?? $this->forceEager;
} catch (OperationNotFoundException $e) {
// In some cases the operation may not exist
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Bridge/Doctrine/Orm/Extension/FilterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGenerator
$resourceFilters = $resourceMetadata->getCollectionOperationAttribute($operationName, 'filters', [], true);
} else {
try {
$operation = $context['operation'] ?? (isset($context['graphql_operation_name']) ? $resourceMetadata->getGraphQlOperation($operationName) : $resourceMetadata->getOperation($operationName));
$operation = $context['operation'] ?? $resourceMetadata->getOperation($operationName);
$resourceFilters = $operation->getFilters();
} catch (OperationNotFoundException $e) {
// In some cases the operation may not exist
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Bridge/Doctrine/Orm/Extension/OrderExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGenerator
if ($this->resourceMetadataFactory instanceof ResourceMetadataCollectionFactoryInterface) {
$resourceMetadataCollection = $this->resourceMetadataFactory->create($resourceClass);
try {
$defaultOrder = isset($context['graphql_operation_name']) ? ($resourceMetadataCollection->getGraphQlOperation($operationName)->getOrder() ?? []) : ($resourceMetadataCollection->getOperation($operationName)->getOrder() ?? []);
$defaultOrder = $resourceMetadataCollection->getOperation($operationName)->getOrder() ?? [];
} catch (OperationNotFoundException $e) {
// In some cases the operation may not exist
$defaultOrder = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private function getPagination(QueryBuilder $queryBuilder, string $resourceClass
}
} elseif ($resourceMetadata instanceof ResourceMetadataCollection) {
try {
$operation = isset($context['graphql_operation_name']) ? $resourceMetadata->getGraphQlOperation($operationName) : $resourceMetadata->getOperation($operationName);
$operation = $resourceMetadata->getOperation($operationName);
$itemsPerPage = $operation->getPaginationItemsPerPage();
if ($operation->getPaginationClientItemsPerPage()) {
$maxItemsPerPage = $operation->getPaginationMaximumItemsPerPage() ?? $this->maximumItemPerPage;
Expand Down Expand Up @@ -373,7 +373,7 @@ private function shouldDoctrinePaginatorFetchJoinCollection(QueryBuilder $queryB
$fetchJoinCollection = $resourceMetadata->getCollectionOperationAttribute($operationName, 'pagination_fetch_join_collection', null, true);
} elseif ($resourceMetadata instanceof ResourceMetadataCollection) {
try {
$operation = isset($context['graphql_operation_name']) ? $resourceMetadata->getGraphQlOperation($operationName) : $resourceMetadata->getOperation($operationName);
$operation = $resourceMetadata->getOperation($operationName);
$fetchJoinCollection = $operation->getPaginationFetchJoinCollection();
} catch (OperationNotFoundException $e) {
// In some cases the operation may not exist
Expand Down Expand Up @@ -427,7 +427,7 @@ private function shouldDoctrinePaginatorUseOutputWalkers(QueryBuilder $queryBuil
$useOutputWalkers = $resourceMetadata->getCollectionOperationAttribute($operationName, 'pagination_use_output_walkers', null, true);
} elseif ($resourceMetadata instanceof ResourceMetadataCollection) {
try {
$operation = isset($context['graphql_operation_name']) ? $resourceMetadata->getGraphQlOperation($operationName) : $resourceMetadata->getOperation($operationName);
$operation = $resourceMetadata->getOperation($operationName);
$useOutputWalkers = $operation->getPaginationUseOutputWalkers();
} catch (OperationNotFoundException $e) {
// In some cases the operation may not exist
Expand Down
10 changes: 5 additions & 5 deletions src/Core/DataProvider/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function getLimit(string $resourceClass = null, string $operationName = n
$clientLimit = $resourceMetadata->getCollectionOperationAttribute($operationName, 'pagination_client_items_per_page', $clientLimit, true);
} else {
try {
$operation = $graphql ? $resourceMetadata->getGraphQlOperation($operationName) : $resourceMetadata->getOperation($operationName);
$operation = $resourceMetadata->getOperation($operationName);
$limit = $operation->getPaginationItemsPerPage() ?? $limit;
$clientLimit = $operation->getPaginationClientItemsPerPage() ?? $clientLimit;
} catch (OperationNotFoundException $e) {
Expand Down Expand Up @@ -170,7 +170,7 @@ public function getLimit(string $resourceClass = null, string $operationName = n
$maxItemsPerPage = $resourceMetadata->getCollectionOperationAttribute($operationName, 'pagination_maximum_items_per_page', $maxItemsPerPage ?? $this->options['maximum_items_per_page'], true);
} elseif ($resourceMetadata instanceof ResourceMetadataCollection) {
try {
$operation = $graphql ? $resourceMetadata->getGraphQlOperation($operationName) : $resourceMetadata->getOperation($operationName);
$operation = $resourceMetadata->getOperation($operationName);
$maxItemsPerPage = $operation->getPaginationMaximumItemsPerPage() ?? $this->options['maximum_items_per_page'];
} catch (OperationNotFoundException $e) {
$maxItemsPerPage = $this->options['maximum_items_per_page'];
Expand Down Expand Up @@ -246,7 +246,7 @@ public function getGraphQlPaginationType(string $resourceClass, string $operatio
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);

if ($resourceMetadata instanceof ResourceMetadataCollection) {
$operation = $resourceMetadata->getGraphQlOperation($operationName);
$operation = $resourceMetadata->getOperation($operationName);

return $operation->getPaginationType() ?? 'cursor';
}
Expand All @@ -272,7 +272,7 @@ private function getEnabled(array $context, string $resourceClass = null, string

if ($resourceMetadata instanceof ResourceMetadataCollection) {
try {
$operation = isset($context['graphql_operation_name']) ? $resourceMetadata->getGraphQlOperation($operationName) : $resourceMetadata->getOperation($operationName);
$operation = $resourceMetadata->getOperation($operationName);
$enabled = ($partial ? $operation->getPaginationPartial() : $operation->getPaginationEnabled()) ?? $enabled;
$clientEnabled = ($partial ? $operation->getPaginationClientPartial() : $operation->getPaginationClientEnabled()) ?? $clientEnabled;
} catch (OperationNotFoundException $e) {
Expand Down Expand Up @@ -300,7 +300,7 @@ private function getGraphQlEnabled(?string $resourceClass, ?string $operationNam
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);

if ($resourceMetadata instanceof ResourceMetadataCollection) {
$operation = $resourceMetadata->getGraphQlOperation($operationName);
$operation = $resourceMetadata->getOperation($operationName);

return $operation->getPaginationEnabled() ?? $enabled;
}
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQl/Resolver/Factory/CollectionResolverFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function __invoke(?string $resourceClass = null, ?string $rootClass = nul

$resourceMetadataCollection = $this->resourceMetadataCollectionFactory->create($resourceClass);
try {
$operation = $resourceMetadataCollection->getGraphQlOperation($operationName);
$operation = $resourceMetadataCollection->getOperation($operationName);
$queryResolverId = $operation->getResolver();
} catch (OperationNotFoundException $e) {
$queryResolverId = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function __invoke(?string $resourceClass = null, ?string $rootClass = nul
$item = ($this->deserializeStage)($item, $resourceClass, $operationName, $resolverContext);

$resourceMetadataCollection = $this->resourceMetadataCollectionFactory->create($resourceClass);
$operation = $resourceMetadataCollection->getGraphQlOperation($operationName);
$operation = $resourceMetadataCollection->getOperation($operationName);

$mutationResolverId = $operation->getResolver();
if (null !== $mutationResolverId) {
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQl/Resolver/Factory/ItemResolverFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function __invoke(?string $resourceClass = null, ?string $rootClass = nul

$resourceClass = $this->getResourceClass($item, $resourceClass);
$resourceMetadataCollection = $this->resourceMetadataCollectionFactory->create($resourceClass);
$operation = $resourceMetadataCollection->getGraphQlOperation($operationName);
$operation = $resourceMetadataCollection->getOperation($operationName);

$queryResolverId = $operation->getResolver();
if (null !== $queryResolverId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function __invoke(?string $resourceClass = null, ?string $rootClass = nul
$subscriptionId = $this->subscriptionManager->retrieveSubscriptionId($resolverContext, $result);

$resourceMetadataCollection = $this->resourceMetadataCollectionFactory->create($resourceClass);
$operation = $resourceMetadataCollection->getGraphQlOperation($operationName);
$operation = $resourceMetadataCollection->getOperation($operationName);

if ($subscriptionId && ($mercure = $operation->getMercure())) {
if (!$this->mercureSubscriptionIriGenerator) {
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQl/Resolver/Stage/DeserializeStage.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(ResourceMetadataCollectionFactoryInterface $resource
public function __invoke($objectToPopulate, string $resourceClass, string $operationName, array $context)
{
$resourceMetadataCollection = $this->resourceMetadataCollectionFactory->create($resourceClass);
$operation = $resourceMetadataCollection->getGraphQlOperation($operationName);
$operation = $resourceMetadataCollection->getOperation($operationName);
if (!($operation->canDeserialize() ?? true)) {
return $objectToPopulate;
}
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQl/Resolver/Stage/ReadStage.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __invoke(?string $resourceClass, ?string $rootClass, string $ope
{
$operation = null;
try {
$operation = $resourceClass ? $this->resourceMetadataCollectionFactory->create($resourceClass)->getGraphQlOperation($operationName) : null;
$operation = $resourceClass ? $this->resourceMetadataCollectionFactory->create($resourceClass)->getOperation($operationName) : null;
} catch (OperationNotFoundException $e) {
// ReadStage may be invoked without an existing operation
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(ResourceMetadataCollectionFactoryInterface $resource
public function __invoke(string $resourceClass, string $operationName, array $context): void
{
$resourceMetadataCollection = $this->resourceMetadataCollectionFactory->create($resourceClass);
$operation = $resourceMetadataCollection->getGraphQlOperation($operationName);
$operation = $resourceMetadataCollection->getOperation($operationName);
$isGranted = $operation->getSecurityPostDenormalize();

if (null !== $isGranted && null === $this->resourceAccessChecker) {
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQl/Resolver/Stage/SecurityPostValidationStage.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(ResourceMetadataCollectionFactoryInterface $resource
public function __invoke(string $resourceClass, string $operationName, array $context): void
{
$resourceMetadataCollection = $this->resourceMetadataCollectionFactory->create($resourceClass);
$operation = $resourceMetadataCollection->getGraphQlOperation($operationName);
$operation = $resourceMetadataCollection->getOperation($operationName);
$isGranted = $operation->getSecurityPostValidation();

if (null !== $isGranted && null === $this->resourceAccessChecker) {
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQl/Resolver/Stage/SecurityStage.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(ResourceMetadataCollectionFactoryInterface $resource
public function __invoke(string $resourceClass, string $operationName, array $context): void
{
$resourceMetadataCollection = $this->resourceMetadataCollectionFactory->create($resourceClass);
$operation = $resourceMetadataCollection->getGraphQlOperation($operationName);
$operation = $resourceMetadataCollection->getOperation($operationName);
$isGranted = $operation->getSecurity();

if (null !== $isGranted && null === $this->resourceAccessChecker) {
Expand Down
12 changes: 3 additions & 9 deletions src/GraphQl/Resolver/Stage/SerializeStage.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,12 @@ public function __invoke($itemOrCollection, string $resourceClass, string $opera
$isSubscription = $context['is_subscription'];

$resourceMetadataCollection = $this->resourceMetadataCollectionFactory->create($resourceClass);
try {
$shortName = $resourceMetadataCollection->getGraphQlOperation($operationName)->getShortName();
} catch (OperationNotFoundException $e) {
$shortName = $resourceMetadataCollection->getOperation()->getShortName();
}

$operation = null;

try {
$operation = $resourceMetadataCollection->getGraphQlOperation($operationName);
$operation = $resourceMetadataCollection->getOperation($operationName);
$shortName = $operation->getShortName();
} catch (OperationNotFoundException $e) {
// In some cases the operation may not exist
$shortName = $resourceMetadataCollection->getOperation()->getShortName();
}

if ($operation && !($operation->canSerialize() ?? true)) {
Expand Down