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

todo_type.rb « types « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6e5ce35033b8f28c240937884d69f9d739259bb6 (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 TodoType < BaseObject
    graphql_name 'Todo'
    description 'Representing a to-do entry'

    present_using TodoPresenter

    authorize :read_todo

    field :id, GraphQL::Types::ID,
          description: 'ID of the to-do item.',
          null: false

    field :project, Types::ProjectType,
          description: 'Project this to-do item is associated with.',
          null: true

    field :group, 'Types::GroupType',
          description: 'Group this to-do item is associated with.',
          null: true

    field :author, Types::UserType,
          description: 'Author of this to-do item.',
          null: false

    field :action, Types::TodoActionEnum,
          description: 'Action of the to-do item.',
          null: false

    field :target, Types::TodoableInterface,
          description: 'Target of the to-do item.',
          calls_gitaly: true,
          null: false

    field :target_type, Types::TodoTargetEnum,
          description: 'Target type of the to-do item.',
          null: false

    field :body, GraphQL::Types::String,
          description: 'Body of the to-do item.',
          null: false,
          calls_gitaly: true # TODO This is only true when `target_type` is `Commit`. See https://gitlab.com/gitlab-org/gitlab/issues/34757#note_234752665

    field :state, Types::TodoStateEnum,
          description: 'State of the to-do item.',
          null: false

    field :created_at, Types::TimeType,
          description: 'Timestamp this to-do item was created.',
          null: false

    field :note, Types::Notes::NoteType,
          description: 'Note which created this to-do item.',
          null: true

    def project
      Gitlab::Graphql::Loaders::BatchModelLoader.new(Project, object.project_id).find
    end

    def group
      Gitlab::Graphql::Loaders::BatchModelLoader.new(Group, object.group_id).find
    end

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

    def target
      if object.for_commit?
        Gitlab::Graphql::Loaders::BatchCommitLoader.new(
          container_class: Project,
          container_id: object.project_id,
          oid: object.commit_id
        ).find
      else
        Gitlab::Graphql::Loaders::BatchModelLoader.new(target_type_class, object.target_id).find
      end
    end

    private

    def target_type_class
      klass = object.target_type.safe_constantize
      raise "Invalid target type \"#{object.target_type}\"" unless klass < Todoable

      klass
    end
  end
end

Types::TodoType.prepend_mod