28 lines
582 B
PHP
28 lines
582 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KupShop\GraphQLBundle\ApiShared\Util;
|
|
|
|
use GraphQL\Type\Definition\ResolveInfo;
|
|
|
|
class GraphQLUtil
|
|
{
|
|
public function lookAhead(ResolveInfo $resolveInfo, array $path): ?array
|
|
{
|
|
$queryPlan = $resolveInfo->lookAhead()->queryPlan();
|
|
|
|
if (!($current = $queryPlan[array_shift($path)] ?? null)) {
|
|
return null;
|
|
}
|
|
|
|
foreach ($path as $item) {
|
|
if (!($current = $current['fields'][$item] ?? null)) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
return $current;
|
|
}
|
|
}
|