Skip to content

Add GraphQL fields `star_count` `forks_count` to CiCatalogResource

Leaminn Ma requested to merge add-ci-catalog-stats-graphql into master

What does this MR do and why?

Added star_count and forks_count fields to ciCatalogResource in GraphQL. Utilized the existing methods from ProjectType.

Note that project.forks_count is a method that already uses Batch loading. We just need to wrap it for GraphQL.

Partially resolves #407382 (closed)

How to set up and validate locally

  1. In the Rails console, run Feature.enable(:ci_private_catalog_beta) and Feature.enable(:ci_namespace_catalog_experimental).
  2. Create a Catalog Resource with an existing or new Project:
::Ci::Catalog::Resource.create(project: Project.find(<project_id>))
  1. Star (aka "Favorite") and fork your Project.
  2. Go to http://gdk.test:3000/-/graphql-explorer and run the following query (adjust the projectPath as necessary):
query getCiCatalogResources {
  ciCatalogResources(projectPath: "group-a/project-catalog-resource-1") {
    nodes {
      id
      name
      starCount
      forksCount
    }
  }
}
  1. Observe that the output shows the Catalog Resource data with the correct star and forks count.
Screenshot Screenshot_2023-05-01_at_3.33.34_PM

MR acceptance checklist

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

Related to #407382 (closed)

Edited by Leaminn Ma

Merge request reports