Skip to content

Commit 85a4dc0

Browse files
authored
Merge 8f244a3 into fc9122c
2 parents fc9122c + 8f244a3 commit 85a4dc0

File tree

15 files changed

+306
-147
lines changed

15 files changed

+306
-147
lines changed

features/hydra/docs.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ Feature: Documentation support
7676
And the value of the node "@type" of the operation "GET" of the Hydra class "Dummy" contains "hydra:Operation"
7777
And the value of the node "@type" of the operation "GET" of the Hydra class "Dummy" contains "schema:FindAction"
7878
And the value of the node "hydra:method" of the operation "GET" of the Hydra class "Dummy" is "GET"
79-
And the value of the node "hydra:title" of the operation "GET" of the Hydra class "Dummy" is "Retrieves Dummy resource."
80-
And the value of the node "rdfs:label" of the operation "GET" of the Hydra class "Dummy" is "Retrieves Dummy resource."
79+
And the value of the node "hydra:title" of the operation "GET" of the Hydra class "Dummy" is "Retrieves a Dummy resource."
80+
And the value of the node "rdfs:label" of the operation "GET" of the Hydra class "Dummy" is "Retrieves a Dummy resource."
8181
And the value of the node "returns" of the operation "GET" of the Hydra class "Dummy" is "#Dummy"
8282
And the value of the node "hydra:title" of the operation "PUT" of the Hydra class "Dummy" is "Replaces the Dummy resource."
8383
And the value of the node "hydra:title" of the operation "DELETE" of the Hydra class "Dummy" is "Deletes the Dummy resource."

src/Api/IdentifiersExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,6 @@ private function resolveIdentifierValue($item, string $class, string $property)
113113
}
114114
}
115115

116-
throw new \RuntimeException('Not able to retrieve identifiers.');
116+
throw new RuntimeException('Not able to retrieve identifiers.');
117117
}
118118
}

src/Core/Bridge/Doctrine/Orm/Extension/PaginationExtension.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,9 @@ private function getPagination(QueryBuilder $queryBuilder, string $resourceClass
199199
}
200200

201201
if (null === $request) {
202-
if (!$this->pagination->isEnabled($resourceClass, $operationName, $context)) {
203-
return null;
204-
}
202+
$enabled = isset($context['graphql_operation_name']) ? $this->pagination->isGraphQlEnabled($resourceClass, $operationName, $context) : $this->pagination->isEnabled($resourceClass, $operationName, $context);
205203

206-
if (($context['graphql_operation_name'] ?? false) && !$this->pagination->isGraphQlEnabled($resourceClass, $operationName, $context)) {
204+
if (!$enabled) {
207205
return null;
208206
}
209207

src/Core/Bridge/Symfony/Bundle/Resources/config/data_provider.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<service id="ApiPlatform\Core\DataProvider\SubresourceDataProviderInterface" alias="api_platform.subresource_data_provider" />
2929

3030
<service id="api_platform.pagination" class="ApiPlatform\Core\DataProvider\Pagination">
31-
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
31+
<argument type="service" id="api_platform.metadata.resource.metadata_collection_factory" />
3232
<argument>%api_platform.collection.pagination%</argument>
3333
<argument>%api_platform.graphql.collection.pagination%</argument>
3434
</service>

src/Core/Bridge/Symfony/Bundle/Resources/config/hydra.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<argument type="service" id="api_platform.resource_class_resolver" />
1313
<argument>null</argument>
1414
<argument type="service" id="api_platform.router" />
15-
<argument type="service" id="api_platform.subresource_operation_factory" />
15+
<argument>null</argument>
1616
<argument type="service" id="api_platform.name_converter" on-invalid="ignore" />
1717

1818
<tag name="serializer.normalizer" priority="-800" />

src/Core/Bridge/Symfony/Bundle/Resources/config/metadata/metadata.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
</service>
7070

7171
<service id="api_platform.metadata.property.metadata_factory.serializer" class="ApiPlatform\Metadata\Property\Factory\SerializerPropertyMetadataFactory" decorates="api_platform.metadata.property.metadata_factory" decoration-priority="30" public="false">
72-
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
72+
<argument>null</argument>
7373
<argument type="service" id="serializer.mapping.class_metadata_factory" />
7474
<argument type="service" id="api_platform.metadata.property.metadata_factory.serializer.inner" />
7575
<argument type="service" id="api_platform.resource_class_resolver" />

src/Core/DataProvider/Pagination.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,13 @@ public function getLimit(string $resourceClass = null, string $operationName = n
135135
$limit = $resourceMetadata->getCollectionOperationAttribute($operationName, 'pagination_items_per_page', $limit, true);
136136
$clientLimit = $resourceMetadata->getCollectionOperationAttribute($operationName, 'pagination_client_items_per_page', $clientLimit, true);
137137
} else {
138-
$operation = $resourceMetadata->getOperation($operationName);
139-
$limit = $operation->getPaginationItemsPerPage() ?? $limit;
140-
$clientLimit = $operation->getPaginationClientItemsPerPage() ?? $clientLimit;
138+
try {
139+
$operation = $graphql ? $resourceMetadata->getGraphQlOperation($operationName) : $resourceMetadata->getOperation($operationName);
140+
$limit = $operation->getPaginationItemsPerPage() ?? $limit;
141+
$clientLimit = $operation->getPaginationClientItemsPerPage() ?? $clientLimit;
142+
} catch (OperationNotFoundException $e) {
143+
// GraphQl operation may not exist
144+
}
141145
}
142146
}
143147

@@ -165,8 +169,12 @@ public function getLimit(string $resourceClass = null, string $operationName = n
165169
}
166170
$maxItemsPerPage = $resourceMetadata->getCollectionOperationAttribute($operationName, 'pagination_maximum_items_per_page', $maxItemsPerPage ?? $this->options['maximum_items_per_page'], true);
167171
} elseif ($resourceMetadata instanceof ResourceMetadataCollection) {
168-
$operation = $resourceMetadata->getOperation($operationName);
169-
$maxItemsPerPage = $operation->getPaginationMaximumItemsPerPage() ?? $this->options['maximum_items_per_page'];
172+
try {
173+
$operation = $graphql ? $resourceMetadata->getGraphQlOperation($operationName) : $resourceMetadata->getOperation($operationName);
174+
$maxItemsPerPage = $operation->getPaginationMaximumItemsPerPage() ?? $this->options['maximum_items_per_page'];
175+
} catch (OperationNotFoundException $e) {
176+
$maxItemsPerPage = $this->options['maximum_items_per_page'];
177+
}
170178
}
171179

172180
if (null !== $maxItemsPerPage && $limit > $maxItemsPerPage) {
@@ -263,9 +271,13 @@ private function getEnabled(array $context, string $resourceClass = null, string
263271
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
264272

265273
if ($resourceMetadata instanceof ResourceMetadataCollection) {
266-
$operation = $resourceMetadata->getOperation($operationName);
267-
$enabled = $partial ? $operation->getPaginationPartial() : $operation->getPaginationEnabled();
268-
$clientEnabled = $partial ? $operation->getPaginationClientPartial() : $operation->getPaginationClientEnabled();
274+
try {
275+
$operation = isset($context['graphql_operation_name']) ? $resourceMetadata->getGraphQlOperation($operationName) : $resourceMetadata->getOperation($operationName);
276+
$enabled = ($partial ? $operation->getPaginationPartial() : $operation->getPaginationEnabled()) ?? $enabled;
277+
$clientEnabled = ($partial ? $operation->getPaginationClientPartial() : $operation->getPaginationClientEnabled()) ?? $clientEnabled;
278+
} catch (OperationNotFoundException $e) {
279+
// GraphQl operation may not exist
280+
}
269281
} else {
270282
$enabled = $resourceMetadata->getCollectionOperationAttribute($operationName, $partial ? 'pagination_partial' : 'pagination_enabled', $enabled, true);
271283
$clientEnabled = $resourceMetadata->getCollectionOperationAttribute($operationName, $partial ? 'pagination_client_partial' : 'pagination_client_enabled', $clientEnabled, true);

0 commit comments

Comments
 (0)