Commit e23705a7 authored by Eugenia Grieff's avatar Eugenia Grieff

Add ResolvesIssuable to EE scope

- This concern is now used to resolve Epics too

Rename EpicResolver

- For consistency with other issuable resolvers
use plural in resolver name

Fix MergeRequestsResolver
parent e84ca201
......@@ -6,19 +6,25 @@ module Mutations
include Mutations::ResolvesProject
def resolve_issuable(type:, parent_path:, iid:)
parent = resolve_issuable_parent(parent_path)
parent = resolve_issuable_parent(type, parent_path)
issuable_resolver(type, parent, context).resolve(iid: iid.to_s)
end
private
def issuable_resolver(type, parent, context)
resolver_class = "Resolvers::#{type.to_s.classify.pluralize}Resolver".constantize
resolver_class.single.new(object: parent, context: context, field: nil)
end
def resolve_issuable_parent(parent_path)
def resolve_issuable_parent(type, parent_path)
return unless type == :issue || type == :merge_request
resolve_project(full_path: parent_path)
end
end
end
Mutations::ResolvesIssuable.prepend_if_ee('::EE::Mutations::ResolvesIssuable')
# frozen_string_literal: true
module EE
module Mutations
module ResolvesIssuable
include ::Mutations::ResolvesGroup
extend ::Gitlab::Utils::Override
private
override :resolve_issuable_parent
def resolve_issuable_parent(type, parent_path)
return super unless type == :epic
resolve_group(full_path: parent_path)
end
end
end
end
......@@ -14,12 +14,12 @@ module EE
field :epic, ::Types::EpicType, null: true,
description: 'Find a single epic',
resolver: ::Resolvers::EpicResolver.single
resolver: ::Resolvers::EpicsResolver.single
field :epics, ::Types::EpicType.connection_type, null: true,
description: 'Find epics',
max_page_size: 2000,
resolver: ::Resolvers::EpicResolver
resolver: ::Resolvers::EpicsResolver
field :timelogs, ::Types::TimelogType.connection_type, null: false,
description: 'Time logged in issues by group members',
......
......@@ -3,7 +3,7 @@
module Mutations
module Epics
class Base < ::Mutations::BaseMutation
include Mutations::ResolvesGroup
include Mutations::ResolvesIssuable
argument :iid, GraphQL::ID_TYPE,
required: true,
......@@ -21,11 +21,7 @@ module Mutations
private
def find_object(group_path:, iid:)
group = resolve_group(full_path: group_path)
resolver = Resolvers::EpicResolver
.single.new(object: group, context: context, field: nil)
resolver.resolve(iid: iid)
resolve_issuable(type: :epic, parent_path: group_path, iid: iid)
end
end
end
......
# frozen_string_literal: true
module Resolvers
class EpicResolver < BaseResolver
class EpicsResolver < BaseResolver
include TimeFrameArguments
argument :iid, GraphQL::ID_TYPE,
......
......@@ -74,7 +74,7 @@ module Types
field :children, ::Types::EpicType.connection_type, null: true,
description: 'Children (sub-epics) of the epic',
resolver: ::Resolvers::EpicResolver
resolver: ::Resolvers::EpicsResolver
field :labels, Types::LabelType.connection_type, null: true,
description: 'Labels assigned to the epic'
......
# frozen_string_literal: true
require 'spec_helper'
describe Mutations::ResolvesIssuable do
let_it_be(:mutation_class) do
Class.new(Mutations::BaseMutation) do
include Mutations::ResolvesIssuable
end
end
let_it_be(:group) { create(:group) }
let_it_be(:user) { create(:user) }
let_it_be(:context) { { current_user: user } }
let_it_be(:mutation) { mutation_class.new(object: nil, context: context, field: nil) }
context 'with epics' do
let_it_be(:issuable) { create(:epic, group: group) }
let_it_be(:parent) { issuable.group }
before do
stub_licensed_features(epics: true)
end
it_behaves_like 'resolving an issuable in GraphQL', :epic
end
end
......@@ -2,7 +2,7 @@
require 'spec_helper'
describe Resolvers::EpicResolver do
describe Resolvers::EpicsResolver do
include GraphqlHelpers
let_it_be(:current_user) { create(:user) }
......
......@@ -3,76 +3,27 @@
require 'spec_helper'
describe Mutations::ResolvesIssuable do
let(:mutation_class) do
let_it_be(:mutation_class) do
Class.new(Mutations::BaseMutation) do
include Mutations::ResolvesIssuable
end
end
let(:project) { create(:project) }
let(:user) { create(:user) }
let(:context) { { current_user: user } }
let(:mutation) { mutation_class.new(object: nil, context: context, field: nil) }
shared_examples 'resolving an issuable' do |type|
context 'when user has access' do
let(:source) { type == :merge_request ? 'source_project' : 'project' }
let(:issuable) { create(type, author: user, "#{source}" => project) }
subject { mutation.resolve_issuable(type: type, parent_path: project.full_path, iid: issuable.iid) }
before do
project.add_developer(user)
end
it 'resolves issuable by iid' do
result = type == :merge_request ? subject.sync : subject
expect(result).to eq(issuable)
end
it 'uses the correct Resolver to resolve issuable' do
resolver_class = "Resolvers::#{type.to_s.classify.pluralize}Resolver".constantize
resolved_project = mutation.resolve_project(full_path: project.full_path)
allow(mutation).to receive(:resolve_project)
.with(full_path: project.full_path)
.and_return(resolved_project)
expect(resolver_class).to receive(:new)
.with(object: resolved_project, context: context, field: nil)
.and_call_original
subject
end
it 'uses the ResolvesProject to resolve project' do
expect(Resolvers::ProjectResolver).to receive(:new)
.with(object: nil, context: context, field: nil)
.and_call_original
subject
end
it 'returns nil if issuable is not found' do
result = mutation.resolve_issuable(type: type, parent_path: project.full_path, iid: "100")
result = type == :merge_request ? result.sync : result
expect(result).to be_nil
end
it 'returns nil if parent path is empty' do
result = mutation.resolve_issuable(type: type, parent_path: "", iid: issuable.iid)
expect(result).to be_nil
end
end
end
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let_it_be(:context) { { current_user: user } }
let_it_be(:mutation) { mutation_class.new(object: nil, context: context, field: nil) }
let(:parent) { issuable.project }
context 'with issues' do
it_behaves_like 'resolving an issuable', :issue
let(:issuable) { create(:issue, project: project) }
it_behaves_like 'resolving an issuable in GraphQL', :issue
end
context 'with merge requests' do
it_behaves_like 'resolving an issuable', :merge_request
let(:issuable) { create(:merge_request, source_project: project) }
it_behaves_like 'resolving an issuable in GraphQL', :merge_request
end
end
# frozen_string_literal: true
RSpec.shared_examples 'resolving an issuable in GraphQL' do |type|
subject { mutation.resolve_issuable(type: type, parent_path: parent.full_path, iid: issuable.iid) }
context 'when user has access' do
before do
parent.add_developer(user)
end
it 'resolves issuable by iid' do
result = type == :merge_request ? subject.sync : subject
expect(result).to eq(issuable)
end
it 'uses the correct Resolver to resolve issuable' do
resolver_class = "Resolvers::#{type.to_s.classify.pluralize}Resolver".constantize
resolve_method = type == :epic ? :resolve_group : :resolve_project
resolved_parent = mutation.send(resolve_method, full_path: parent.full_path)
allow(mutation).to receive(resolve_method)
.with(full_path: parent.full_path)
.and_return(resolved_parent)
expect(resolver_class).to receive(:new)
.with(object: resolved_parent, context: context, field: nil)
.and_call_original
subject
end
it 'uses correct Resolver to resolve issuable parent' do
resolver_class = type == :epic ? 'Resolvers::GroupResolver' : 'Resolvers::ProjectResolver'
expect(resolver_class.constantize).to receive(:new)
.with(object: nil, context: context, field: nil)
.and_call_original
subject
end
it 'returns nil if issuable is not found' do
result = mutation.resolve_issuable(type: type, parent_path: parent.full_path, iid: "100")
result = type == :merge_request ? result.sync : result
expect(result).to be_nil
end
it 'returns nil if parent path is not present' do
result = mutation.resolve_issuable(type: type, parent_path: "", iid: issuable.iid)
expect(result).to be_nil
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