debian-mirror-gitlab/app/graphql/resolvers/boards_resolver.rb

36 lines
1.1 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
module Resolvers
class BoardsResolver < BaseResolver
type Types::BoardType, null: true
2021-01-29 00:20:46 +05:30
argument :id, ::Types::GlobalIDType[::Board],
2020-04-08 14:13:33 +05:30
required: false,
2021-03-08 18:12:59 +05:30
description: 'Find a board by its ID.'
2020-04-08 14:13:33 +05:30
def resolve(id: nil)
2020-03-13 15:44:24 +05:30
# 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
2021-04-17 20:07:23 +05:30
::Boards::BoardsFinder.new(parent, context[:current_user], board_id: extract_board_id(id)).execute
2020-04-08 14:13:33 +05:30
rescue ActiveRecord::RecordNotFound
Board.none
end
private
2021-01-29 00:20:46 +05:30
def extract_board_id(id)
return unless id.present?
2020-04-08 14:13:33 +05:30
2021-01-29 00:20:46 +05:30
# 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-03-13 15:44:24 +05:30
end
end
end