2020-01-25 21:08:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Resolvers
|
|
|
|
class BoardsResolver < BaseResolver
|
|
|
|
type Types::BoardType, null: true
|
|
|
|
|
2020-10-24 00:08:35 +00:00
|
|
|
argument :id, ::Types::GlobalIDType[::Board],
|
2020-02-24 18:09:05 +00:00
|
|
|
required: false,
|
|
|
|
description: 'Find a board by its ID'
|
|
|
|
|
|
|
|
def resolve(id: nil)
|
2020-01-25 21:08:43 +00:00
|
|
|
# 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
|
|
|
|
|
2020-09-25 15:09:36 +00:00
|
|
|
::Boards::ListService.new(parent, context[:current_user], board_id: extract_board_id(id)).execute(create_default_board: false)
|
2020-02-24 18:09:05 +00:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
Board.none
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-10-24 00:08:35 +00:00
|
|
|
def extract_board_id(id)
|
|
|
|
return unless id.present?
|
2020-02-24 18:09:05 +00:00
|
|
|
|
2020-10-24 00:08:35 +00:00
|
|
|
# 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
|
2020-01-25 21:08:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|