Skip to content

Commit 8f81218

Browse files
josef.wagnersoyuka
authored andcommitted
fix(graphql): query nullish ManyToOne-Relation
1 parent 67524b8 commit 8f81218

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/GraphQl/Resolver/Factory/ResolverFactory.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
use ApiPlatform\Metadata\GraphQl\Mutation;
1818
use ApiPlatform\Metadata\GraphQl\Operation;
1919
use ApiPlatform\Metadata\GraphQl\Query;
20-
use ApiPlatform\State\Pagination\ArrayPaginator;
2120
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
21+
use ApiPlatform\State\Pagination\ArrayPaginator;
2222
use ApiPlatform\State\ProcessorInterface;
2323
use ApiPlatform\State\ProviderInterface;
2424
use GraphQL\Type\Definition\ResolveInfo;
@@ -34,17 +34,19 @@ public function __construct(
3434
public function __invoke(?string $resourceClass = null, ?string $rootClass = null, ?Operation $operation = null, ?PropertyMetadataFactoryInterface $propertyMetadataFactory = null): callable
3535
{
3636
return function (?array $source, array $args, $context, ResolveInfo $info) use ($resourceClass, $rootClass, $operation, $propertyMetadataFactory) {
37-
if ($body = $source[$info->fieldName] ?? null) {
38-
// special treatment for nested resources without a resolver/provider
39-
40-
return $body;
41-
}
42-
4337
if (\array_key_exists($info->fieldName, $source ?? [])) {
4438
$body = $source[$info->fieldName];
4539

40+
// special treatment for nested resources without a resolver/provider
4641
if ($operation instanceof Query && $operation->getNested() && !$operation->getResolver() && (!$operation->getProvider() || NoopProvider::class === $operation->getProvider())) {
47-
return $this->resolve($source, $args, $info, $rootClass, $operation, new ArrayPaginator($body, 0, \count($body)));
42+
return \is_array($body) ? $this->resolve(
43+
$source,
44+
$args,
45+
$info,
46+
$rootClass,
47+
$operation,
48+
new ArrayPaginator($body, 0, \count($body))
49+
) : $body;
4850
}
4951

5052
$propertyMetadata = $rootClass ? $propertyMetadataFactory?->create($rootClass, $info->fieldName) : null;

0 commit comments

Comments
 (0)