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

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

module Types
  # rubocop: disable Graphql/AuthorizeTypes
  class BoardListType < BaseObject
    graphql_name 'BoardList'
    description 'Represents a list for an issue board'

    include Gitlab::Utils::StrongMemoize

    alias_method :list, :object

    field :id, GraphQL::Types::ID,
          null: false,
          description: 'ID (global ID) of the list.'

    field :title, GraphQL::Types::String, null: false,
          description: 'Title of the list.'
    field :list_type, GraphQL::Types::String, null: false,
          description: 'Type of the list.'
    field :position, GraphQL::Types::Int, null: true,
          description: 'Position of list within the board.'
    field :label, Types::LabelType, null: true,
          description: 'Label of the list.'
    field :collapsed, GraphQL::Types::Boolean, null: true,
          description: 'Indicates if the list is collapsed for this user.'
    field :issues_count, GraphQL::Types::Int, null: true,
          description: 'Count of issues in the list.'

    field :issues, ::Types::IssueType.connection_type, null: true,
          description: 'Board issues.',
          late_extensions: [Gitlab::Graphql::Board::IssuesConnectionExtension],
          resolver: ::Resolvers::BoardListIssuesResolver

    def issues_count
      metadata[:size]
    end

    def collapsed
      object.collapsed?(context[:current_user])
    end

    def metadata
      strong_memoize(:metadata) do
        params = (context[:issue_filters] || {}).merge(board_id: list.board_id, id: list.id)

        ::Boards::Issues::ListService
          .new(list.board.resource_parent, current_user, params)
          .metadata
      end
    end

    # board lists have a data dependency on label - so we batch load them here
    def title
      BatchLoader::GraphQL.for(object).batch do |lists, callback|
        ActiveRecord::Associations::Preloader.new.preload(lists, :label) # rubocop: disable CodeReuse/ActiveRecord

        # all list titles are preloaded at this point
        lists.each { |list| callback.call(list, list.title) }
      end
    end
  end
  # rubocop: enable Graphql/AuthorizeTypes
end

Types::BoardListType.prepend_mod_with('Types::BoardListType')