Skip to content

Allow namespace projects to be queried by ids with GraphQL

Max Orefice requested to merge mo-filter-group-projects-by-ids-graphql into master

Ref: #296665 (closed)

What does this MR do?

This MR allows to query projects by ids at the namespace level with our GraphQL API.

It includes the following items:

  • New scope to query group projects with code coverage
  • Add new argument (ids: [gids]) to our namespace projects graphql endpoint

This MR implement our feature, we will follow up and refactor our existing NamespaceProjectsResolver to use a proper finder in #322917 (closed).

Why are we doing this?

We are working to improve our analytic page aggregating our code coverage data at the group level.

We are currently displaying all projects in our dropdown projects as you can see below 👇

Repositories_Analytics___GitLab.org___GitLab_2021-02-22_17-03-13

After this MR, we will be able filter projects having a code coverage data by ids at the namespace level.

This implementation is similar to our existing one to filter projects by ids except this time we do it at the group level:

Screenshots

GraphQL request Response
{
  group(fullPath: "gitlab-org") {
      projects(hasCodeCoverage: true, ids: ["gid://gitlab/Project/1"]) {
      nodes {
        id
        name
          codeCoverageSummary {
          averageCoverage
          coverageCount
          lastUpdatedOn
        }
      }
    }
  }
}
{
  "data": {
    "group": {
      "projects": {
        "nodes": [
          {
            "id": "gid://gitlab/Project/1",
            "name": "Gitlab Test",
            "codeCoverageSummary": {
              "averageCoverage": 99.9,
              "coverageCount": 1,
              "lastUpdatedOn": "2020-10-21"
            }
          }
        ]
      }
    }
  }
}

Database review

Query

SELECT
    projects.*
FROM
    projects
WHERE
    projects.namespace_id = 9970
    AND projects.id = 278964

Execution plan

 Index Scan using index_projects_on_namespace_id_and_id on public.projects  (cost=0.44..3.46 rows=1 width=720) (actual time=5.762..9.315 rows=1 loops=1)
   Index Cond: ((projects.namespace_id = 9970) AND (projects.id = 278964))
   Buffers: shared hit=1 read=5 dirtied=2
   I/O Timings: read=8.206

Cold cache

Time: 13.953 ms  
  - planning: 4.575 ms  
  - execution: 9.378 ms  
    - I/O read: 8.206 ms  
    - I/O write: N/A  
  
Shared buffers:  
  - hits: 1 (~8.00 KiB) from the buffer pool  
  - reads: 5 (~40.00 KiB) from the OS file cache, including disk I/O  
  - dirtied: 2 (~16.00 KiB)  
  - writes: 0  

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team

Merge request reports