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

widget_interface.rb « work_items « types « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 62657f38a4be88a03ea6a2a44d4d170671c7b04c (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 WorkItems
    module WidgetInterface
      include Types::BaseInterface

      graphql_name 'WorkItemWidget'

      field :type, ::Types::WorkItems::WidgetTypeEnum,
        null: true,
        description: 'Widget type.'

      ORPHAN_TYPES = [
        ::Types::WorkItems::Widgets::DescriptionType,
        ::Types::WorkItems::Widgets::HierarchyType,
        ::Types::WorkItems::Widgets::LabelsType,
        ::Types::WorkItems::Widgets::AssigneesType,
        ::Types::WorkItems::Widgets::StartAndDueDateType,
        ::Types::WorkItems::Widgets::MilestoneType,
        ::Types::WorkItems::Widgets::NotesType,
        ::Types::WorkItems::Widgets::NotificationsType,
        ::Types::WorkItems::Widgets::CurrentUserTodosType,
        ::Types::WorkItems::Widgets::AwardEmojiType,
        ::Types::WorkItems::Widgets::LinkedItemsType,
        ::Types::WorkItems::Widgets::ParticipantsType
      ].freeze

      def self.ce_orphan_types
        ORPHAN_TYPES
      end

      # Whenever a new widget is added make sure to update the spec to avoid N + 1 queries in
      # spec/requests/api/graphql/project/work_items_spec.rb and add the necessary preloads
      # in app/graphql/resolvers/work_items_resolver.rb
      def self.resolve_type(object, context)
        case object
        when ::WorkItems::Widgets::Description
          ::Types::WorkItems::Widgets::DescriptionType
        when ::WorkItems::Widgets::Hierarchy
          ::Types::WorkItems::Widgets::HierarchyType
        when ::WorkItems::Widgets::Assignees
          ::Types::WorkItems::Widgets::AssigneesType
        when ::WorkItems::Widgets::Labels
          ::Types::WorkItems::Widgets::LabelsType
        when ::WorkItems::Widgets::StartAndDueDate
          ::Types::WorkItems::Widgets::StartAndDueDateType
        when ::WorkItems::Widgets::Milestone
          ::Types::WorkItems::Widgets::MilestoneType
        when ::WorkItems::Widgets::Notes
          ::Types::WorkItems::Widgets::NotesType
        when ::WorkItems::Widgets::Notifications
          ::Types::WorkItems::Widgets::NotificationsType
        when ::WorkItems::Widgets::CurrentUserTodos
          ::Types::WorkItems::Widgets::CurrentUserTodosType
        when ::WorkItems::Widgets::AwardEmoji
          ::Types::WorkItems::Widgets::AwardEmojiType
        when ::WorkItems::Widgets::LinkedItems
          ::Types::WorkItems::Widgets::LinkedItemsType
        when ::WorkItems::Widgets::Participants
          ::Types::WorkItems::Widgets::ParticipantsType
        else
          raise "Unknown GraphQL type for widget #{object}"
        end
      end

      orphan_types(*ORPHAN_TYPES)
    end
  end
end

Types::WorkItems::WidgetInterface.prepend_mod