Skip to content

Add links to Release data from GraphQL endpoint

Nathan Friend requested to merge nfriend-add-links-to-release-graphql into master

What does this MR do?

Adds the links provided by the Release API endpoint under the _links property:

{
   ...

   "_links": {
     "self": "http://0.0.0.0:3001/root/private-release-test/-/releases/test",
     "merge_requests_url": "http://0.0.0.0:3001/root/private-release-test/-/merge_requests?release_tag=test&scope=all&state=opened",
     "issues_url": "http://0.0.0.0:3001/root/private-release-test/-/issues?release_tag=test&scope=all&state=opened",
     "edit_url": "http://0.0.0.0:3001/root/private-release-test/-/releases/test/edit"
   }
}

to our GraphQL endpoint.

In addition, this MR expands some of the existing GraphQL tests to cover other permission-related scenarios.

Structure

To make things simple, I've added these links directly to the Release type rather than nest them under a _links property as they are in the REST API. This has the benefit of avoiding confusion with Release asset links, which are also available through the GraphQL endpoint.

Feature flag

All Release-related data was and still is hidden behind the graphql_release_data feature flag, which is currently disabled.

Permissions

Permissions are more restrictive than our REST API. The :download_code policy is required to access selfUrl, mergeRequestsUrl, and issuesUrl, and update_release is required to access edit_url.

Example query and response

Below is an example query and responses against a Release in a private project.

Query:

{
  project(fullPath: "root/private-release-test") {
    releases(first: 1) {
      nodes {
        links {
          selfUrl
          mergeRequestsUrl
          issuesUrl
          editUrl
        }
      }
    }
  }
}

Response when the user has Developer permissions:

{
  "data": {
    "project": {
      "releases": {
        "nodes": [
          {
            "links": {
              "selfUrl": "http://0.0.0.0:3001/root/private-release-test/-/releases/v2.1",
              "mergeRequestsUrl": "http://0.0.0.0:3001/root/private-release-test/-/merge_requests?release_tag=v2.1&scope=all&state=opened",
              "issuesUrl": "http://0.0.0.0:3001/root/private-release-test/-/issues?release_tag=v2.1&scope=all&state=opened",
              "editUrl": "http://0.0.0.0:3001/root/private-release-test/-/releases/v2.1/edit"
            }
          }
        ]
      }
    }
  }
}

Response when the user has Reporter permissions:

{
  "data": {
    "project": {
      "releases": {
        "nodes": [
          {
            "links": {
              "selfUrl": "http://0.0.0.0:3001/root/private-release-test/-/releases/v2.1",
              "mergeRequestsUrl": "http://0.0.0.0:3001/root/private-release-test/-/merge_requests?release_tag=v2.1&scope=all&state=opened",
              "issuesUrl": "http://0.0.0.0:3001/root/private-release-test/-/issues?release_tag=v2.1&scope=all&state=opened",
              "editUrl": null
            }
          }
        ]
      }
    }
  }
}

Response when the user has Guest permissions:

{
  "data": {
    "project": {
      "releases": {
        "nodes": [
          {
            "links": null
          }
        ]
      }
    }
  }
}

Response when the user does not have access to the project:

{
  "data": {
    "project": null
  }
}

Note: selfUrl, mergeRequestsUrl, and issuesUrl are always accessible if the project is public.

MR target

This MR is temporarily targeting the branch nfriend-rename-release-links-classes until !34543 (merged) is merged. Once !34543 (merged) is merged, this MR will be updated to point to master.

This MR now targets master.

Related to #214241 (closed)

Edited by Nathan Friend

Merge request reports

Loading