Skip to content

Add _links object to the Package GraphQL API

Context

A package might have one of the following statuses: default, hidden, processing, error and pending_destruction.

Currently not all the statuses allow the package to be displayed in the details page.
The package details pages should be restricted to only packages with status default.

In order to be fully backward compatible and avoid any degradations on UX we agreed on the multi MRs implementation of necessary changes.

What does this MR do and why?

Add the _links object with underlying web_path property to the Package type (GraphQL API). Later on frontend will use web_path to show the link to package details page.

Screenshots or screen recordings

Query project with a package

Screenshot_2022-10-18_at_19.47.15

Query package

Screenshot_2022-10-18_at_19.48.28

How to set up and validate locally

Preparation

  1. Prepare a package

    def fixture_file_upload(*args, **kwargs)
      Rack::Test::UploadedFile.new(*args, **kwargs)
    end
    
    FactoryBot.create(:npm_package, project: Project.first)
  2. Grab required information

    Packages::Package.last.id

    Write it down somewhere or remember - it will be required at the later step.

    Packages::Package.last.project_id

    Write it down somewhere or remember - it will be required at the later step.

GraphQL API

  1. Browse http://gdk.test:3000/-/graphql-explorer and query a package

    {
      package(id: "gid://gitlab/Packages::Package/:package_id") {
        _links {
          webPath
        }
      }
    }
  2. Verify response

    {
      "data": {
        "package": {
          "_links": {
            "webPath": "/gitlab-org/gitlab-test/-/packages/:package_id"
          }
        }  
      }
    }
  3. Browse http://gdk.test:3000/-/graphql-explorer and query a project with packages

    {
      project(fullPath: "gitlab-org/gitlab-test") {
        id
        packages {
          edges {
            node {
              _links {
                webPath
              }
            }
          }
        }
      }
    }
  4. Verify response

    {
      "data": {
        "project": {
          "id": "gid://gitlab/Project/:project_id",
          "packages": {
            "edges": [
              {
                "node": {
                  "_links": {
                    "webPath": "/gitlab-org/gitlab-test/-/packages/:package_id"
                  }
                }
              }
            ]
          }
        }
      }
    }

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 #344257 (closed)

Edited by Dzmitry (Dima) Meshcharakou

Merge request reports