Skip to content

Commit

Permalink
fix(metadata): graphql can be disabled but with an existing operation
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Oct 4, 2024
1 parent ab71ee5 commit 14e2c8e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Laravel/ApiPlatformProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ public function register(): void
$config->get('api-platform.graphql.enabled'),
),
)
)
),
$config->get('api-platform.graphql.enabled')
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
final class LinkResourceMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface
{
public function __construct(private readonly LinkFactoryInterface $linkFactory, private readonly ?ResourceMetadataCollectionFactoryInterface $decorated = null)
public function __construct(private readonly LinkFactoryInterface $linkFactory, private readonly ?ResourceMetadataCollectionFactoryInterface $decorated = null, private bool $graphQlEnabled = false)
{
}

Expand All @@ -37,6 +37,10 @@ public function create(string $resourceClass): ResourceMetadataCollection
$resourceMetadataCollection = $this->decorated->create($resourceClass);
}

if (!$this->graphQlEnabled) {
return $resourceMetadataCollection;
}

foreach ($resourceMetadataCollection as $i => $resource) {
$graphQlOperations = [];
foreach ($resource->getGraphQlOperations() ?? [] as $graphQlOperation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ private function buildResourceOperations(array $metadataCollection, string $reso
$resources[$index] = $resource = $resource->withOperations(new Operations($operations)); // @phpstan-ignore-line
}

$graphQlOperations = $resource->getGraphQlOperations();
if (!$this->graphQlEnabled) {
continue;
}

$graphQlOperations = $resource->getGraphQlOperations();
if (null === $graphQlOperations) {
if (!$hasApiResource) {
$resources[$index] = $resources[$index]->withGraphQlOperations([]);
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/Resources/config/metadata/resource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<service id="api_platform.metadata.resource.metadata_collection_factory.link" class="ApiPlatform\Metadata\Resource\Factory\LinkResourceMetadataCollectionFactory" decorates="api_platform.metadata.resource.metadata_collection_factory" decoration-priority="500" public="false">
<argument type="service" id="api_platform.metadata.resource.link_factory" />
<argument type="service" id="api_platform.metadata.resource.metadata_collection_factory.link.inner" />
<argument>%api_platform.graphql.enabled%</argument>
</service>

<!-- must run after uri template, do not change uriTemplate neither the operation names in < 500 priorities -->
Expand Down

0 comments on commit 14e2c8e

Please sign in to comment.