Automattic\WooCommerce\Vendor\GraphQL\Type\Definition

ResolveInfo::foldSelectionSetprivateWC 1.0

Method of the class: ResolveInfo{}

No Hooks.

Returns

Array. bool>

Usage

// private - for code of main (parent) class only
$result = $this->foldSelectionSet( $selectionSet, $descend ): array;
$selectionSet(SelectionSetNode) (required)
.
$descend(int) (required)
.

ResolveInfo::foldSelectionSet() code WC 10.9.1

private function foldSelectionSet(SelectionSetNode $selectionSet, int $descend): array
{
    /** @var array<string, bool> $fields */
    $fields = [];

    foreach ($selectionSet->selections as $selection) {
        if ($selection instanceof FieldNode) {
            $fields[$selection->name->value] = $descend > 0 && $selection->selectionSet !== null
                ? array_merge_recursive(
                    $fields[$selection->name->value] ?? [],
                    $this->foldSelectionSet($selection->selectionSet, $descend - 1)
                )
                : true;
        } elseif ($selection instanceof FragmentSpreadNode) {
            $spreadName = $selection->name->value;
            $fragment = $this->fragments[$spreadName] ?? null;
            if ($fragment === null) {
                continue;
            }

            $fields = array_merge_recursive(
                $this->foldSelectionSet($fragment->selectionSet, $descend),
                $fields
            );
        } elseif ($selection instanceof InlineFragmentNode) {
            $fields = array_merge_recursive(
                $this->foldSelectionSet($selection->selectionSet, $descend),
                $fields
            );
        }
    }

    return $fields;
}