Commit 495a3027 authored by Thong Kuah's avatar Thong Kuah

Merge branch 'nfriend-add-direct-asset-url-to-graphql' into 'master'

Add release `direct_asset_url` to GraphQL

See merge request gitlab-org/gitlab!41170
parents 5ee5a743 bddb425e
......@@ -17,5 +17,17 @@ module Types
description: 'Type of the link: `other`, `runbook`, `image`, `package`; defaults to `other`'
field :external, GraphQL::BOOLEAN_TYPE, null: true, method: :external?,
description: 'Indicates the link points to an external resource'
field :direct_asset_url, GraphQL::STRING_TYPE, null: true,
description: 'Direct asset URL of the link'
def direct_asset_url
return object.url unless object.filepath
release = object.release
project = release.project
Gitlab::Routing.url_helpers.project_release_url(project, release) << object.filepath
end
end
end
---
title: Add release direct asset link info to GraphQL endpoint
merge_request: 41170
author:
type: added
......@@ -14142,6 +14142,11 @@ type Release {
Represents an asset link associated with a release
"""
type ReleaseAssetLink {
"""
Direct asset URL of the link
"""
directAssetUrl: String
"""
Indicates the link points to an external resource
"""
......
......@@ -41161,6 +41161,20 @@
"name": "ReleaseAssetLink",
"description": "Represents an asset link associated with a release",
"fields": [
{
"name": "directAssetUrl",
"description": "Direct asset URL of the link",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "external",
"description": "Indicates the link points to an external resource",
......@@ -1927,6 +1927,7 @@ Represents an asset link associated with a release
| Name | Type | Description |
| --- | ---- | ---------- |
| `directAssetUrl` | String | Direct asset URL of the link |
| `external` | Boolean | Indicates the link points to an external resource |
| `id` | ID! | ID of the link |
| `linkType` | ReleaseAssetLinkType | Type of the link: `other`, `runbook`, `image`, `package`; defaults to `other` |
......
......@@ -7,7 +7,7 @@ RSpec.describe GitlabSchema.types['ReleaseAssetLink'] do
it 'has the expected fields' do
expected_fields = %w[
id name url external link_type
id name url external link_type direct_asset_url
]
expect(described_class).to include_graphql_fields(*expected_fields)
......
......@@ -10,6 +10,7 @@ RSpec.describe 'Query.project(fullPath).release(tagName)' do
let_it_be(:guest) { create(:user) }
let_it_be(:reporter) { create(:user) }
let_it_be(:stranger) { create(:user) }
let_it_be(:link_filepath) { '/direct/asset/link/path' }
let(:params_for_issues_and_mrs) { { scope: 'all', state: 'opened', release_tag: release.tag } }
let(:post_query) { post_graphql(query, current_user: current_user) }
......@@ -127,7 +128,7 @@ RSpec.describe 'Query.project(fullPath).release(tagName)' do
let(:release_fields) do
query_graphql_field(:assets, nil,
query_graphql_field(:links, nil, 'nodes { id name url external }'))
query_graphql_field(:links, nil, 'nodes { id name url external, directAssetUrl }'))
end
it 'finds all release links' do
......@@ -138,7 +139,8 @@ RSpec.describe 'Query.project(fullPath).release(tagName)' do
'id' => global_id_of(link),
'name' => link.name,
'url' => link.url,
'external' => link.external?
'external' => link.external?,
'directAssetUrl' => link.filepath ? Gitlab::Routing.url_helpers.project_release_url(project, release) << link.filepath : link.url
}
end
......@@ -270,7 +272,7 @@ RSpec.describe 'Query.project(fullPath).release(tagName)' do
let_it_be(:milestone_2) { create(:milestone, project: project) }
let_it_be(:release) { create(:release, :with_evidence, project: project, milestones: [milestone_1, milestone_2]) }
let_it_be(:release_link_1) { create(:release_link, release: release) }
let_it_be(:release_link_2) { create(:release_link, release: release) }
let_it_be(:release_link_2) { create(:release_link, release: release, filepath: link_filepath) }
before_all do
project.add_developer(developer)
......@@ -311,7 +313,7 @@ RSpec.describe 'Query.project(fullPath).release(tagName)' do
let_it_be(:milestone_2) { create(:milestone, project: project) }
let_it_be(:release) { create(:release, :with_evidence, project: project, milestones: [milestone_1, milestone_2]) }
let_it_be(:release_link_1) { create(:release_link, release: release) }
let_it_be(:release_link_2) { create(:release_link, release: release) }
let_it_be(:release_link_2) { create(:release_link, release: release, filepath: link_filepath) }
before_all do
project.add_developer(developer)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment