Skip to content

Commit defc50b

Browse files
author
Roman Skoropadsky
committed
fix: return null instead of throwing exception for GraphQL query operation when item not found
1 parent ac8031e commit defc50b

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/GraphQl/State/Provider/ReadProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use ApiPlatform\Metadata\CollectionOperationInterface;
2222
use ApiPlatform\Metadata\GraphQl\Mutation;
2323
use ApiPlatform\Metadata\GraphQl\Operation as GraphQlOperation;
24+
use ApiPlatform\Metadata\GraphQl\Query;
2425
use ApiPlatform\Metadata\GraphQl\QueryCollection;
2526
use ApiPlatform\Metadata\GraphQl\Subscription;
2627
use ApiPlatform\Metadata\IriConverterInterface;
@@ -68,6 +69,10 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
6869
$item = null;
6970
}
7071

72+
if ($operation instanceof Query && null === $item) {
73+
return $item;
74+
}
75+
7176
if ($operation instanceof Subscription || $operation instanceof Mutation) {
7277
if (null === $item) {
7378
throw new NotFoundHttpException(sprintf('Item "%s" not found.', $args['input']['id']));

0 commit comments

Comments
 (0)