Welcome to mirror list, hosted at ThFree Co, Russian Federation.

destroy_file.rb « packages « mutations « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 35a486666d5c49d6c29f12b2cb1256532731cbd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

module Mutations
  module Packages
    class DestroyFile < ::Mutations::BaseMutation
      graphql_name 'DestroyPackageFile'

      authorize :destroy_package

      argument :id,
               ::Types::GlobalIDType[::Packages::PackageFile],
               required: true,
               description: 'ID of the Package file.'

      def resolve(id:)
        package_file = authorized_find!(id: id)

        if package_file.destroy
          return { errors: [] }
        end

        { errors: package_file.errors.full_messages }
      end

      private

      def find_object(id:)
        # TODO: remove this line when the compatibility layer is removed
        # See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
        id = ::Types::GlobalIDType[::Packages::PackageFile].coerce_isolated_input(id)
        GitlabSchema.find_by_gid(id)
      end
    end
  end
end