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

version_type.rb « resources « catalog « ci « types « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c568403f320ad4288805edfa87f77d1bc9ead9d7 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# frozen_string_literal: true

module Types
  module Ci
    module Catalog
      module Resources
        # rubocop: disable Graphql/AuthorizeTypes -- Authorization is handled by Ci::Catalog::Resources::VersionsFinder in the resolver.
        class VersionType < BaseObject
          graphql_name 'CiCatalogResourceVersion'

          connection_type_class Types::CountableConnectionType

          field :id, ::Types::GlobalIDType[::Ci::Catalog::Resources::Version], null: false,
            description: 'Global ID of the version.',
            alpha: { milestone: '16.7' }

          field :created_at, Types::TimeType, null: true, description: 'Timestamp of when the version was created.',
            alpha: { milestone: '16.7' }

          field :released_at, Types::TimeType, null: true, description: 'Timestamp of when the version was released.',
            alpha: { milestone: '16.7' }

          field :tag_name, GraphQL::Types::String, null: true, method: :name,
            description: 'Deprecated in 16.8. Use name.',
            alpha: { milestone: '16.7' }

          field :name, GraphQL::Types::String, null: true,
            description: 'Name that uniquely identifies the version within the catalog resource.',
            alpha: { milestone: '16.8' }

          field :tag_path, GraphQL::Types::String, null: true, method: :path,
            description: 'Deprecated in 16.8. Use path.',
            alpha: { milestone: '16.7' }

          field :path, GraphQL::Types::String, null: true,
            description: 'Relative web path to the version.',
            alpha: { milestone: '16.8' }

          field :author, Types::UserType, null: true, description: 'User that created the version.',
            alpha: { milestone: '16.7' }

          field :commit, Types::CommitType, null: true, complexity: 10, calls_gitaly: true,
            description: 'Commit associated with the version.',
            alpha: { milestone: '16.7' }

          field :components, Types::Ci::Catalog::Resources::ComponentType.connection_type, null: true,
            description: 'Components belonging to the catalog resource.',
            alpha: { milestone: '16.7' }

          field :readme_html, GraphQL::Types::String, null: true, calls_gitaly: true,
            description: 'GitLab Flavored Markdown rendering of README.md. This field ' \
                         'can only be resolved for one version in any single request.',
            alpha: { milestone: '16.8' } do
              extension ::Gitlab::Graphql::Limit::FieldCallCount, limit: 1 # To avoid N+1 calls to Gitaly
            end

          def author
            Gitlab::Graphql::Loaders::BatchModelLoader.new(User, object.author_id).find
          end

          def readme_html
            return unless Ability.allowed?(current_user, :read_code, object.project)

            markdown_context = context.to_h.dup.merge(project: object.project)
            ::MarkupHelper.markdown(object.readme&.data, markdown_context)
          end
        end
        # rubocop: enable Graphql/AuthorizeTypes
      end
    end
  end
end