summaryrefslogtreecommitdiff
path: root/app/graphql/types/namespace_type.rb
blob: fc55ff512b6d5197eb73b81059f7d1f4962fb2c5 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# frozen_string_literal: true

module Types
  class NamespaceType < BaseObject
    graphql_name 'Namespace'

    authorize :read_namespace

    field :id, GraphQL::Types::ID, null: false,
                                   description: 'ID of the namespace.'

    field :full_name, GraphQL::Types::String, null: false,
                                              description: 'Full name of the namespace.'
    field :full_path, GraphQL::Types::ID, null: false,
                                          description: 'Full path of the namespace.'
    field :name, GraphQL::Types::String, null: false,
                                         description: 'Name of the namespace.'
    field :path, GraphQL::Types::String, null: false,
                                         description: 'Path of the namespace.'

    field :cross_project_pipeline_available,
          GraphQL::Types::Boolean,
          null: false,
          resolver_method: :cross_project_pipeline_available?,
          description: 'Indicates if the cross_project_pipeline feature is available for the namespace.'

    field :description, GraphQL::Types::String, null: true,
                                                description: 'Description of the namespace.'

    field :lfs_enabled,
          GraphQL::Types::Boolean,
          null: true,
          method: :lfs_enabled?,
          description: 'Indicates if Large File Storage (LFS) is enabled for namespace.'
    field :request_access_enabled,
          GraphQL::Types::Boolean,
          null: true,
          description: 'Indicates if users can request access to namespace.'
    field :visibility, GraphQL::Types::String, null: true,
                                               description: 'Visibility of the namespace.'

    field :root_storage_statistics, Types::RootStorageStatisticsType,
          null: true,
          description: 'Aggregated storage statistics of the namespace. Only available for root namespaces.'

    field :projects, Types::ProjectType.connection_type, null: false,
                                                         description: 'Projects within this namespace.',
                                                         resolver: ::Resolvers::NamespaceProjectsResolver

    field :package_settings,
          Types::Namespace::PackageSettingsType,
          null: true,
          description: 'Package settings for the namespace.'

    field :shared_runners_setting,
          Types::Namespace::SharedRunnersSettingEnum,
          null: true,
          description: "Shared runners availability for the namespace and its descendants."

    field :timelog_categories,
          Types::TimeTracking::TimelogCategoryType.connection_type,
          null: true,
          description: "Timelog categories for the namespace.",
          alpha: { milestone: '15.3' }

    field :achievements,
          Types::Achievements::AchievementType.connection_type,
          null: true,
          alpha: { milestone: '15.8' },
          description: "Achievements for the namespace. " \
                       "Returns `null` if the `achievements` feature flag is disabled."

    markdown_field :description_html, null: true

    def timelog_categories
      object.timelog_categories if Feature.enabled?(:timelog_categories)
    end

    def cross_project_pipeline_available?
      object.licensed_feature_available?(:cross_project_pipelines)
    end

    def root_storage_statistics
      Gitlab::Graphql::Loaders::BatchRootStorageStatisticsLoader.new(object.id).find
    end

    def achievements
      object.achievements if Feature.enabled?(:achievements, object)
    end
  end
end

Types::NamespaceType.prepend_mod_with('Types::NamespaceType')