Commit 3e2ef953 authored by GitLab Bot's avatar GitLab Bot

Add latest changes from gitlab-org/gitlab@master

parent 35487a1e
# frozen_string_literal: true
module Resolvers
class BoardsResolver < BaseResolver
type Types::BoardType, null: true
def resolve(**args)
# 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::ListService.new(parent, context[:current_user]).execute(create_default_board: false)
end
end
end
# frozen_string_literal: true
module Types
class BoardType < BaseObject
graphql_name 'Board'
description 'Represents a project or group board'
authorize :read_board
field :id, type: GraphQL::ID_TYPE, null: false,
description: 'ID (global ID) of the board'
field :name, type: GraphQL::STRING_TYPE, null: true,
description: 'Name of the board'
end
end
Types::BoardType.prepend_if_ee('::EE::Types::BoardType')
......@@ -2,8 +2,8 @@
module Boards
class ListService < Boards::BaseService
def execute
create_board! if parent.boards.empty?
def execute(create_default_board: true)
create_board! if create_default_board && parent.boards.empty?
if parent.multiple_issue_boards_available?
boards
......
# frozen_string_literal: true
require 'spec_helper'
describe Resolvers::BoardsResolver do
include GraphqlHelpers
let_it_be(:user) { create(:user) }
shared_examples_for 'group and project boards resolver' do
it 'does not create a default board' do
expect(resolve_boards).to eq []
end
it 'calls Boards::ListService' do
expect_next_instance_of(Boards::ListService) do |service|
expect(service).to receive(:execute)
end
resolve_boards
end
it 'avoids N+1 queries' do
control = ActiveRecord::QueryRecorder.new { resolve_boards(args: {}) }
create(:milestone, "#{board_parent.class.name.underscore}": board_parent)
create(:board, resource_parent: board_parent)
expect { resolve_boards(args: {}) }.not_to exceed_query_limit(control)
end
describe 'multiple_issue_boards_available?' do
let!(:board2) { create(:board, name: 'Two', resource_parent: board_parent) }
let!(:board1) { create(:board, name: 'One', resource_parent: board_parent) }
it 'returns multiple boards' do
allow(board_parent).to receive(:multiple_issue_boards_available?).and_return(true)
expect(resolve_boards).to eq [board1, board2]
end
it 'returns only the first boards' do
allow(board_parent).to receive(:multiple_issue_boards_available?).and_return(false)
expect(resolve_boards).to eq [board1]
end
end
end
describe '#resolve' do
context 'when there is no parent' do
let(:board_parent) { nil }
it 'returns none if parent is nil' do
expect(resolve_boards).to eq(Board.none)
end
end
context 'when project boards' do
let(:board_parent) { create(:project, :public, creator_id: user.id, namespace: user.namespace ) }
it_behaves_like 'group and project boards resolver'
end
context 'when group boards' do
let(:board_parent) { create(:group) }
it_behaves_like 'group and project boards resolver'
end
end
def resolve_boards(args: {})
resolve(described_class, obj: board_parent, args: args, ctx: { current_user: user })
end
end
......@@ -11,6 +11,12 @@ RSpec.shared_examples 'boards list service' do
service.execute
end
context 'when create_default_board is false' do
it 'does not create a new parent board' do
expect { service.execute(create_default_board: false) }.not_to change(parent.boards, :count)
end
end
end
context 'when parent has a board' do
......
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