code: public function buildSelectionSet($fields)
      {
          $selections[] = new FieldNode([
              'name' => new NameNode(['value' => '__typename']),
          ]);
          $this->currentLeafFields++;
  
          foreach ($fields as $field) {
              if ($this->currentLeafFields >= $this->maxLeafFields) {
                  break;
              }
  
              $type = $field->getType();
  
              if ($type instanceof WrappingType) {
                  $type = $type->getWrappedType(true);
              }
  
              if ($type instanceof ObjectType || $type instanceof InterfaceType) {
                  $selectionSet = $this->buildSelectionSet($type->getFields());
              } else {
                  $selectionSet = null;
                  $this->currentLeafFields++;
              }
  
              $selections[] = new FieldNode([
                  'name' => new NameNode(['value' => $field->name]),
                  'selectionSet' => $selectionSet,
              ]);
          }
  
          $selectionSet = new SelectionSetNode([
              'selections' => $selections,
          ]);
  
          return $selectionSet;
      }
docs: @param FieldDefinition[] $fields
  
  @return SelectionSetNode