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

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

module Resolvers
  class BoardsResolver < BaseResolver
    type Types::BoardType, null: true

    argument :id, ::Types::GlobalIDType[::Board],
             required: false,
             description: 'Find a board by its ID.'

    def resolve(id: nil)
      # The project or group could have been loaded in batch by `BatchLoader`.
      # At this point we need the `id` of the project/group to query for boards, so
      # make sure it's loaded and not `nil` before continuing.
      parent = object.respond_to?(:sync) ? object.sync : object

      return Board.none unless parent

      ::Boards::BoardsFinder.new(parent, context[:current_user], board_id: extract_board_id(id)).execute
    rescue ActiveRecord::RecordNotFound
      Board.none
    end

    private

    def extract_board_id(id)
      return unless id.present?

      # TODO: remove this line when the compatibility layer is removed
      # See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
      id = Types::GlobalIDType[Board].coerce_isolated_input(id)
      id.model_id
    end
  end
end