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

resource_resolver.rb « catalog « ci « resolvers « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4b722bd3ec78741f118a3ae105439f1ea75556b3 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
# frozen_string_literal: true

module Resolvers
  module Ci
    module Catalog
      class ResourceResolver < BaseResolver
        include Gitlab::Graphql::Authorize::AuthorizeResource

        authorize :read_code

        type ::Types::Ci::Catalog::ResourceType, null: true

        argument :id, ::Types::GlobalIDType[::Ci::Catalog::Resource],
          required: false,
          description: 'CI/CD Catalog resource global ID.'

        argument :full_path, GraphQL::Types::ID,
          required: false,
          description: 'CI/CD Catalog resource full path.'

        def ready?(**args)
          unless args[:id].present? ^ args[:full_path].present?
            raise Gitlab::Graphql::Errors::ArgumentError,
              "Exactly one of 'id' or 'full_path' arguments is required."
          end

          super
        end

        def resolve(id: nil, full_path: nil)
          if full_path.present?
            project = Project.find_by_full_path(full_path)
            authorize!(project)

            raise_resource_not_available_error! unless project.catalog_resource

            project.catalog_resource
          else
            catalog_resource = ::Gitlab::Graphql::Lazy.force(GitlabSchema.find_by_gid(id))
            authorize!(catalog_resource&.project)

            catalog_resource
          end
        end
      end
    end
  end
end