Skip to content

Backend: Support fetching versioned README for catalog resource in GraphQl

Summary

We need to fetch the correct README content to populate the catalog resource details page for a given version. A catalog resource Version is identified by its name (which is currently equivalent to the Release git tag; see !136081 (comment 1649709843) for context). Given a version name in a GraphQL query, we should be able to retrieve the README blob from the corresponding commit.

Proposal

Support the following GraphQl query to fetch the versioned README html content:

query getCiCatalogResourceReadme($fullPath: ID!, $version: String!) {
  ciCatalogResource(fullPath: $fullPath) {
    id
    webPath
    versions(name: $version) {
      nodes {
        readmeHtml
      }
    }
  }
}
  • The name argument is optional for versions. When provided, it will return either an empty array or an array containing a single version that matches the given name.
  • If the user isn't authorized with :read_release, returns empty array.
  • If the version name does not exist, returns empty array.

To fetch latestVersion if the version name argument is not available, you can use a query like below or you can write two separate GQL queries and implement the logic with FE code.

query getCiCatalogResourceReadme($fullPath: ID!, $latest_version: Boolean = true, $version: String) {
  ciCatalogResource(fullPath: $fullPath) {
    id
    versions(name: $version) @skip(if: $latest_version) {
      nodes {
        readmeHtml
      }
    }
    latestVersion @include(if: $latest_version) {
      readmeHtml
    }
  }
}

To retrieve the latest version:

{ "fullPath": "group-a/ci_seed_resource_0", "latest_version": true, "version": null }

To retrieve a specific version:

{ "fullPath": "group-a/ci_seed_resource_0", "latest_version": false, "version": "tag1" }

Implementation Table

Group Issue Link
backend Backend: Make ciCatalogResource accept a fullpa... (#429100 - closed)
backend 👈 You are here
frontend Frontend: Support fetching versioned README for... (#436401 - closed)
backend Backend: Remove `readme_html` field from CI Cat... (#436411 - closed)
Edited by Leaminn Ma