Skip to content

Add new fields to GroupType

Abdul Wadood requested to merge 420702-graphql-group-type-fields into master

What does this MR do and why?

This is part of the ongoing Organization work by the grouptenant scale group. Read the blueprint to learn more https://docs.gitlab.com/ee/architecture/blueprints/organization/index.html.

Fields introduced are:

  • descendantGroupsCount
  • groupMembersCount
  • projectsCount

Query plans

  1. https://console.postgres.ai/gitlab/gitlab-production-main/sessions/24623/commands/78338
Raw Query
SELECT COUNT(projects) AS "count_projects", "namespaces"."id" AS "namespaces_id"
FROM "namespaces"
         LEFT OUTER JOIN "projects" ON "projects"."archived" != TRUE AND "projects"."namespace_id" = "namespaces"."id"
WHERE "namespaces"."type" = 'Group'
  AND "namespaces"."id" IN
      (1755573, 1761696, 1793858, 1819570, 1920469, 2287432, 2351283, 2452873, 2593421, 2639717, 2750817, 2843837,
       2907304, 3345373, 3455548, 3887963, 3910297, 3925021, 3930213, 3952433)
GROUP BY "namespaces"."id";
  1. https://console.postgres.ai/gitlab/gitlab-production-main/sessions/24623/commands/78337
Raw Query
SELECT COUNT(members) AS "count_members", "namespaces"."id" AS "namespaces_id"
FROM "namespaces"
         LEFT OUTER JOIN "members" ON "members"."source_type" = 'Namespace' AND "members"."requested_at" IS NULL AND
                                      "members"."access_level" != 5 AND "members"."source_id" = "namespaces"."id" AND
                                      "members"."type" = 'GroupMember'
WHERE "namespaces"."type" = 'GROUP'
  AND "namespaces"."id" IN
      (1755573, 1761696, 1793858, 1819570, 1920469, 2287432, 2351283, 2452873, 2593421, 2639717, 2750817, 2843837,
       2907304, 3345373, 3455548, 3887963, 3910297, 3925021, 3930213, 3952433)
GROUP BY "namespaces"."id";
  1. https://console.postgres.ai/gitlab/gitlab-production-main/sessions/24623/commands/78336
Raw Query
SELECT COUNT(children_namespaces) AS "count_children_namespaces", "namespaces"."id" AS "namespaces_id"
FROM "namespaces"
         LEFT OUTER JOIN "namespaces" "children_namespaces" ON "children_namespaces"."type" = 'Group' AND
                                                               "children_namespaces"."parent_id" = "namespaces"."id"
WHERE "namespaces"."type" = 'Group'
  AND "namespaces"."id" IN
      (1755573, 1761696, 1793858, 1819570, 1920469, 2287432, 2351283, 2452873, 2593421, 2639717, 2750817, 2843837,
       2907304, 3345373, 3455548, 3887963, 3910297, 3925021, 3930213, 3952433)
GROUP BY "namespaces"."id";

How to set up and validate locally

Run the following query on GraphiQL https://gdk.test:3000/-/graphql-explorer:

Query
{
  organization(id: "gid://gitlab/Organizations::Organization/1") {
    id
    path
    groups(sort: NAME_DESC) {
      edges {
        node {
          id
          descendantGroupsCount
          groupMembersCount
          projectsCount
        }
      }
    }
  }
}
Output
{
  "data": {
    "organization": {
      "id": "gid://gitlab/Organizations::Organization/1",
      "path": "default",
      "groups": {
        "edges": [
          {
            "node": {
              "id": "gid://gitlab/Group/35",
              "descendantGroupsCount": 0,
              "groupMembersCount": 5,
              "projectsCount": 2
            }
          },
          {
            "node": {
              "id": "gid://gitlab/Group/31",
              "descendantGroupsCount": 0,
              "groupMembersCount": 5,
              "projectsCount": 1
            }
          },
          {
            "node": {
              "id": "gid://gitlab/Group/27",
              "descendantGroupsCount": 0,
              "groupMembersCount": 5,
              "projectsCount": 1
            }
          },
          {
            "node": {
              "id": "gid://gitlab/Group/24",
              "descendantGroupsCount": 0,
              "groupMembersCount": 4,
              "projectsCount": 2
            }
          },
          {
            "node": {
              "id": "gid://gitlab/Group/33",
              "descendantGroupsCount": 0,
              "groupMembersCount": 5,
              "projectsCount": 1
            }
          },
          {
            "node": {
              "id": "gid://gitlab/Group/29",
              "descendantGroupsCount": 0,
              "groupMembersCount": 5,
              "projectsCount": 1
            }
          },
          {
            "node": {
              "id": "gid://gitlab/Group/109",
              "descendantGroupsCount": 0,
              "groupMembersCount": 1,
              "projectsCount": 0
            }
          },
          {
            "node": {
              "id": "gid://gitlab/Group/110",
              "descendantGroupsCount": 0,
              "groupMembersCount": 1,
              "projectsCount": 0
            }
          },
          {
            "node": {
              "id": "gid://gitlab/Group/108",
              "descendantGroupsCount": 1,
              "groupMembersCount": 1,
              "projectsCount": 0
            }
          },
          {
            "node": {
              "id": "gid://gitlab/Group/107",
              "descendantGroupsCount": 2,
              "groupMembersCount": 1,
              "projectsCount": 0
            }
          }
        ]
      }
    }
  }
}

Related to #420702 (closed)

Edited by Abdul Wadood

Merge request reports