Skip to content

Commit

Permalink
fix(graphql): query nullish ManyToOne-Relation
Browse files Browse the repository at this point in the history
  • Loading branch information
josef.wagner authored and soyuka committed Apr 5, 2024
1 parent 67524b8 commit 8f81218
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/GraphQl/Resolver/Factory/ResolverFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
use ApiPlatform\Metadata\GraphQl\Mutation;
use ApiPlatform\Metadata\GraphQl\Operation;
use ApiPlatform\Metadata\GraphQl\Query;
use ApiPlatform\State\Pagination\ArrayPaginator;
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
use ApiPlatform\State\Pagination\ArrayPaginator;
use ApiPlatform\State\ProcessorInterface;
use ApiPlatform\State\ProviderInterface;
use GraphQL\Type\Definition\ResolveInfo;
Expand All @@ -34,17 +34,19 @@ public function __construct(
public function __invoke(?string $resourceClass = null, ?string $rootClass = null, ?Operation $operation = null, ?PropertyMetadataFactoryInterface $propertyMetadataFactory = null): callable

Check warning on line 34 in src/GraphQl/Resolver/Factory/ResolverFactory.php

View check run for this annotation

Codecov / codecov/patch

src/GraphQl/Resolver/Factory/ResolverFactory.php#L34

Added line #L34 was not covered by tests
{
return function (?array $source, array $args, $context, ResolveInfo $info) use ($resourceClass, $rootClass, $operation, $propertyMetadataFactory) {
if ($body = $source[$info->fieldName] ?? null) {
// special treatment for nested resources without a resolver/provider

return $body;
}

if (\array_key_exists($info->fieldName, $source ?? [])) {
$body = $source[$info->fieldName];

Check warning on line 38 in src/GraphQl/Resolver/Factory/ResolverFactory.php

View check run for this annotation

Codecov / codecov/patch

src/GraphQl/Resolver/Factory/ResolverFactory.php#L36-L38

Added lines #L36 - L38 were not covered by tests

// special treatment for nested resources without a resolver/provider
if ($operation instanceof Query && $operation->getNested() && !$operation->getResolver() && (!$operation->getProvider() || NoopProvider::class === $operation->getProvider())) {
return $this->resolve($source, $args, $info, $rootClass, $operation, new ArrayPaginator($body, 0, \count($body)));
return \is_array($body) ? $this->resolve(
$source,
$args,
$info,
$rootClass,
$operation,
new ArrayPaginator($body, 0, \count($body))
) : $body;

Check warning on line 49 in src/GraphQl/Resolver/Factory/ResolverFactory.php

View check run for this annotation

Codecov / codecov/patch

src/GraphQl/Resolver/Factory/ResolverFactory.php#L42-L49

Added lines #L42 - L49 were not covered by tests
}

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

0 comments on commit 8f81218

Please sign in to comment.