Skip to content

Add GraphQL field `root_namespace` to CiCatalogResource

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

What does this MR do and why?

Added the root_namespace field to ciCatalogResource in GraphQL.

The field resolver makes use of batch loading and ProjectRootAncestorPreloader. The latter utilizes traversal_ids to avoid recursive queries when fetching the root namespaces.

Please note that currently all resource objects returned from the ciCatalogResource endpoint are expected to have the same root_namespace. However, this field was implemented with the expectation that this endpoint will be able to return resources from multiple root namespaces in the future.

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. 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
      rootNamespace {
        id
        name
        path
      }
    }
  }
}
  1. Observe that the output shows the correct Catalog Resource data.
Screenshot Screenshot_2023-05-30_at_9.29.02_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