How to get group ids by ids of elements of group content? I use the Group module and I have created several groups and assigned several nodes as content of these groups.

For example, I know id of some node. How can I figure out which groups contain this node ?  That is, how to get group ids by nid, if this node is a content of these groups ? And I don't want to use SQL for it. Are there methods of classes for it ?
The way Group module maintainer recommended:

use Drupal\group\Entity\GroupContent;

function getGroupIdsByEntity($entity) {
  $group_ids = [];

  $group_contents = GroupContent::loadByEntity($entity);
  foreach ($group_contents as $group_content) {
    $group_ids[] = $group_content-&gt;getGroup()-&gt;id();
  }

  return $group_ids;
}