Skip to content

Add graphql query to get project members count by role

Sashi Kumar Kumaresan requested to merge sk/379059-add-role-count into master

What does this MR do and why?

Addresses #379059 (closed)

As a part of Support Role Based Approval Action for Scan Res... (&8018 - closed) we need to show the number of users in a project belonging to a role like in this design:

Screenshot_2023-02-22_at_7.38.55_PM

This change introduces a new graphql query projectMembersCountByRole within a project type that returns the count of users with their roles.

Graphql Query

query {
  project(fullPath:"flightjs/Flight") {
    projectMembersCountByRole {
      developer
      guest
      maintainer
      owner
      reporter
    }
  }
}

Response

{
  "data": {
    "project": {
      "projectMembersCountByRole": {
        "developer": 1,
        "guest": 1,
        "maintainer": 3,
        "owner": 2,
        "reporter": 1
      }
    }
  }
}

Database query

SELECT
    COUNT(*) AS count_all,
    "project_authorizations"."access_level" AS project_authorizations_access_level 
FROM
    "project_authorizations" 
WHERE
    "project_authorizations"."project_id" = 278964
GROUP BY
    "project_authorizations"."access_level"

Plan

  HashAggregate  (cost=2278.36..2278.41 rows=5 width=12) (actual time=5804.915..5804.918 rows=5 loops=1)
   Group Key: project_authorizations.access_level
   Buffers: shared hit=148 read=2207 dirtied=56
   I/O Timings: read=5724.579 write=0.000
   ->  Index Scan using index_unique_project_authorizations_on_project_id_user_id on public.project_authorizations  (cost=0.57..2270.83 rows=1505 width=4) (actual time=58.818..5792.339 rows=2358 loops=1)
         Index Cond: (project_authorizations.project_id = 278964)
         Buffers: shared hit=148 read=2207 dirtied=56
         I/O Timings: read=5724.579 write=0.000

console.postgres.ai

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Luke Duncalfe

Merge request reports