debian-mirror-gitlab/app/graphql/mutations/release_asset_links/update.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
1.8 KiB
Ruby
Raw Normal View History

2021-04-17 20:07:23 +05:30
# frozen_string_literal: true
module Mutations
module ReleaseAssetLinks
class Update < BaseMutation
graphql_name 'ReleaseAssetLinkUpdate'
authorize :update_release
ReleaseAssetLinkID = ::Types::GlobalIDType[::Releases::Link]
argument :id, ReleaseAssetLinkID,
required: true,
description: 'ID of the release asset link to update.'
2021-10-27 15:23:28 +05:30
argument :name, GraphQL::Types::String,
2021-04-17 20:07:23 +05:30
required: false,
description: 'Name of the asset link.'
2021-10-27 15:23:28 +05:30
argument :url, GraphQL::Types::String,
2021-04-17 20:07:23 +05:30
required: false,
description: 'URL of the asset link.'
2021-10-27 15:23:28 +05:30
argument :direct_asset_path, GraphQL::Types::String,
2021-04-17 20:07:23 +05:30
required: false, as: :filepath,
description: 'Relative path for a direct asset link.'
argument :link_type, Types::ReleaseAssetLinkTypeEnum,
required: false,
2021-10-27 15:23:28 +05:30
description: 'Type of the asset link.'
2021-04-17 20:07:23 +05:30
field :link,
Types::ReleaseAssetLinkType,
null: true,
2021-10-27 15:23:28 +05:30
description: 'Asset link after mutation.'
2021-04-17 20:07:23 +05:30
def ready?(**args)
if args.key?(:link_type) && args[:link_type].nil?
raise Gitlab::Graphql::Errors::ArgumentError,
'if the linkType argument is provided, it cannot be null'
end
super
end
def resolve(id:, **link_attrs)
link = authorized_find!(id)
2023-05-27 22:25:52 +05:30
result = ::Releases::Links::UpdateService
.new(link.release, current_user, link_attrs)
.execute(link)
2021-04-17 20:07:23 +05:30
2023-05-27 22:25:52 +05:30
if result.success?
{ link: result.payload[:link], errors: [] }
else
{ link: nil, errors: result.message }
end
2021-04-17 20:07:23 +05:30
end
def find_object(id)
GitlabSchema.find_by_gid(id)
end
end
end
end