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

types_resolver.rb « work_items « resolvers « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5f9f8ab5572a50451e4fc1ced16c56e86532b7f4 (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
# frozen_string_literal: true

module Resolvers
  module WorkItems
    class TypesResolver < BaseResolver
      type Types::WorkItems::TypeType.connection_type, null: true

      argument :taskable, ::GraphQL::Types::Boolean,
               required: false,
               description: 'If `true`, only taskable work item types will be returned.' \
                            ' Argument is experimental and can be removed in the future without notice.'

      def resolve(taskable: nil)
        return unless feature_flag_enabled_for_parent?(object)

        # This will require a finder in the future when groups/projects get their work item types
        # All groups/projects use the default types for now
        base_scope = ::WorkItems::Type.default
        base_scope = base_scope.by_type(:task) if taskable

        base_scope.order_by_name_asc
      end

      private

      def feature_flag_enabled_for_parent?(parent)
        return false unless parent.is_a?(::Project) || parent.is_a?(::Group)

        parent.work_items_feature_flag_enabled?
      end
    end
  end
end