private function foldSelectionSet(SelectionSetNode $selectionSet, $descend)
{
$fields = [];
foreach ($selectionSet->selections as $selectionNode) {
if ($selectionNode instanceof FieldNode) {
$fields[$selectionNode->name->value] = $descend > 0 && !empty($selectionNode->selectionSet) ? $this->foldSelectionSet($selectionNode->selectionSet, $descend - 1) : true;
} else {
if ($selectionNode instanceof FragmentSpreadNode) {
$spreadName = $selectionNode->name->value;
if (isset($this->fragments[$spreadName])) {
/** @var FragmentDefinitionNode $fragment */
$fragment = $this->fragments[$spreadName];
$fields += $this->foldSelectionSet($fragment->selectionSet, $descend);
}
}
}
}
return $fields;
}