Add GraphQL field `latest_version` to CiCatalogResource
What does this MR do and why?
Added the latest_version
field to ciCatalogResource
in GraphQL. The latest version of a catalog resource is a Release
object.
A new type Ci::Catalog::Resource::VersionType
was created which inherits from ReleaseType
; the only difference is that VersionType
overrides the :read_release
authorization. The Release authorization is not required since the user is already authorized through the CiCatalogResource
type. If we leave it in, it would cause an N+1
query issue as each resource's latest version (i.e Release) would have to be authorized.
This MR partially resolves #407382 (closed).
Also note that there is a follow-up issue to move the latest_versions_by_project_id
query into the Release finder: #409712 (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
- In the Rails console, run
Feature.enable(:ci_private_catalog_beta)
and thenFeature.enable(:ci_namespace_catalog_experimental)
. - Create a Catalog Resource with an existing or new Project:
::Ci::Catalog::Resource.create(project: Project.find(<project_id>))
- 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.)
- 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.)
- Go to
http://gdk.test:3000/-/graphql-explorer
and run the following query (adjust theprojectPath
as necessary):
query getCiCatalogResources {
ciCatalogResources(projectPath: "group-a/project-catalog-resource-1") {
nodes {
id
name
latestVersion {
tagName
releasedAt
author {
id
name
webUrl
}
}
}
}
}
- Observe that the output shows the correct Catalog Resource information along with the latest version data.
Query Plan
SELECT DISTINCT ON (project_id) * FROM "releases" WHERE "releases"."project_id" IN (7764, 250833, 13083) ORDER BY "releases"."project_id" ASC, "releases"."released_at" DESC
Query Plan Link: https://console.postgres.ai/shared/12860bae-0c37-4bfa-98fe-433b9ac0e0dc
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #407382 (closed)