Skip to content

Add GraphQL field `versions` to CiCatalogResource

Leaminn Ma requested to merge add-graphql-versions-field into master

What does this MR do and why?

Added the versions field to ciCatalogResource in GraphQL.

This MR makes a few changes to the ReleasesFinder so that it can support an array of Projects as input. It also adapts the existing ReleasesResolver to use batch loading. These changes enable the use of the ReleasesResolver for the versions field.

This MR partially resolves #407382 (closed).

Data Context:

  • A Catalog Resource has a 1:1 relationship with Project.
  • A Project's "Releases" are equivalent to the Catalog Resource's "Versions".

How to set up and validate locally

  1. In the Rails console, run Feature.enable(:ci_private_catalog_beta) and then 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. Ensure that the Project has a non-empty description and also has a README file. (This is required for you to successfully create a Release on the Catalog Resource.)
  2. Create at least one Tag and one Release on the Project. (Note that the latest Release is equivalent to the "latest version" of the Catalog Resource.)
  3. 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
      versions(first: 1) {
        nodes {
          tagName
          releasedAt
          author {
            id
            name
            webUrl
          }
        }
      }
    }
  }
}
  1. Observe that the output shows the correct Catalog Resource information along with the latest version data.
Screenshot Screenshot_2023-05-15_at_6.29.26_PM

Query Plan

SELECT "releases".* FROM "releases" WHERE "releases"."project_id" IN (7764, 250833, 13083) AND "releases"."tag" IS NOT NULL ORDER BY "releases"."released_at" DESC

Plan link: https://console.postgres.ai/shared/eb47c8f7-4a0d-45f2-b990-72c51a3de460

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