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

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

module Resolvers
  class BoardListsResolver < BaseResolver
    include Gitlab::Graphql::Authorize::AuthorizeResource

    type Types::BoardListType, null: true

    alias_method :board, :object

    def resolve(lookahead: nil)
      authorize!(board)

      lists = board_lists

      if load_preferences?(lookahead)
        List.preload_preferences_for_user(lists, context[:current_user])
      end

      Gitlab::Graphql::Pagination::OffsetActiveRecordRelationConnection.new(lists)
    end

    private

    def board_lists
      service = Boards::Lists::ListService.new(board.resource_parent, context[:current_user])
      service.execute(board, create_default_lists: false)
    end

    def authorized_resource?(board)
      Ability.allowed?(context[:current_user], :read_list, board)
    end

    def load_preferences?(lookahead)
      lookahead&.selection(:edges)&.selection(:node)&.selects?(:collapsed)
    end
  end
end