Commit 7234bb6b authored by Eugenia Grieff's avatar Eugenia Grieff

Add option to query a single board list on GraphQL

parent 6336341b
......@@ -6,12 +6,16 @@ module Resolvers
type Types::BoardListType, null: true
argument :id, GraphQL::ID_TYPE,
required: false,
description: 'Find a list by its ID'
alias_method :board, :object
def resolve(lookahead: nil)
def resolve(lookahead: nil, id: nil)
authorize!(board)
lists = board_lists
lists = board_lists(id)
if load_preferences?(lookahead)
List.preload_preferences_for_user(lists, context[:current_user])
......@@ -22,8 +26,8 @@ module Resolvers
private
def board_lists
service = Boards::Lists::ListService.new(board.resource_parent, context[:current_user])
def board_lists(id)
service = Boards::Lists::ListService.new(board.resource_parent, context[:current_user], list_id: extract_list_id(id))
service.execute(board, create_default_lists: false)
end
......@@ -34,5 +38,11 @@ module Resolvers
def load_preferences?(lookahead)
lookahead&.selection(:edges)&.selection(:node)&.selects?(:collapsed)
end
def extract_list_id(gid)
return unless gid.present?
GitlabSchema.parse_gid(gid, expected_type: ::List).model_id
end
end
end
......@@ -8,7 +8,8 @@ module Boards
board.lists.create(list_type: :backlog)
end
board.lists.preload_associated_models
lists = board.lists.preload_associated_models
params[:list_id].present? ? lists.where(id: params[:list_id]) : lists # rubocop: disable CodeReuse/ActiveRecord
end
end
end
......
......@@ -57,6 +57,25 @@ RSpec.describe Resolvers::BoardListsResolver do
expect(lists.count).to eq 3
end
end
context 'when querying for a single list' do
it 'returns specified list' do
list = resolve_board_lists(args: { id: global_id_of(label_list) }).items
expect(list).to eq [label_list]
end
it 'returns empty result if list is not accessible found' do
external_group = create(:group, :private)
external_board = create(:board, resource_parent: external_group )
external_label = create(:group_label, group: group)
external_list = create(:list, board: external_board, label: external_label)
list = resolve_board_lists(args: { id: global_id_of(external_list) }).items
expect(list).to eq List.none
end
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment