Commit 5c8c8db5 authored by Dmytro Zaporozhets's avatar Dmytro Zaporozhets

Merge branch 'req-rename-graphql' into 'master'

Move requirements under requirement_management - graphql

See merge request gitlab-org/gitlab!30602
parents 9c72c83a 7dad193f
......@@ -14,8 +14,8 @@ module EE
mount_mutation ::Mutations::Epics::Create
mount_mutation ::Mutations::Epics::SetSubscription
mount_mutation ::Mutations::Epics::AddIssue
mount_mutation ::Mutations::Requirements::Create
mount_mutation ::Mutations::Requirements::Update
mount_mutation ::Mutations::RequirementsManagement::CreateRequirement
mount_mutation ::Mutations::RequirementsManagement::UpdateRequirement
mount_mutation ::Mutations::Vulnerabilities::Dismiss
mount_mutation ::Mutations::Boards::Lists::UpdateLimitMetrics
mount_mutation ::Mutations::InstanceSecurityDashboard::AddProject
......
......@@ -26,15 +26,15 @@ module EE
)
end
field :requirement, ::Types::RequirementType, null: true,
field :requirement, ::Types::RequirementsManagement::RequirementType, null: true,
description: 'Find a single requirement. Available only when feature flag `requirements_management` is enabled.',
resolver: ::Resolvers::RequirementsResolver.single
resolver: ::Resolvers::RequirementsManagement::RequirementsResolver.single
field :requirements, ::Types::RequirementType.connection_type, null: true,
field :requirements, ::Types::RequirementsManagement::RequirementType.connection_type, null: true,
description: 'Find requirements. Available only when feature flag `requirements_management` is enabled.',
resolver: ::Resolvers::RequirementsResolver
resolver: ::Resolvers::RequirementsManagement::RequirementsResolver
field :requirement_states_count, ::Types::RequirementStatesCountType, null: true,
field :requirement_states_count, ::Types::RequirementsManagement::RequirementStatesCountType, null: true,
description: 'Number of requirements for the project by their state',
resolve: -> (project, args, ctx) do
return unless requirements_available?(project, ctx[:current_user])
......
# frozen_string_literal: true
module Mutations
module Requirements
class Create < BaseMutation
module RequirementsManagement
class CreateRequirement < BaseMutation
include Mutations::ResolvesProject
graphql_name 'CreateRequirement'
authorize :create_requirement
field :requirement, Types::RequirementType,
field :requirement, Types::RequirementsManagement::RequirementType,
null: true,
description: 'The requirement after mutation'
......
# frozen_string_literal: true
module Mutations
module Requirements
class Update < BaseMutation
module RequirementsManagement
class UpdateRequirement < BaseMutation
include Mutations::ResolvesProject
graphql_name 'UpdateRequirement'
authorize :update_requirement
field :requirement, Types::RequirementType,
field :requirement, Types::RequirementsManagement::RequirementType,
null: true,
description: 'The requirement after mutation'
......@@ -17,7 +17,7 @@ module Mutations
required: false,
description: 'Title of the requirement'
argument :state, Types::RequirementStateEnum,
argument :state, Types::RequirementsManagement::RequirementStateEnum,
required: false,
description: 'State of the requirement'
......@@ -60,7 +60,7 @@ module Mutations
def find_object(project_path:, iid:)
project = resolve_project(full_path: project_path)
resolver = Resolvers::RequirementsResolver
resolver = Resolvers::RequirementsManagement::RequirementsResolver
.single.new(object: project, context: context, field: nil)
resolver.resolve(iid: iid)
......
# frozen_string_literal: true
module Resolvers
module RequirementsManagement
class RequirementsResolver < BaseResolver
argument :iid, GraphQL::ID_TYPE,
required: false,
description: 'IID of the requirement, e.g., "1"'
argument :iids, [GraphQL::ID_TYPE],
required: false,
description: 'List of IIDs of requirements, e.g., [1, 2]'
argument :sort, Types::SortEnum,
required: false,
description: 'List requirements by sort order'
argument :state, Types::RequirementsManagement::RequirementStateEnum,
required: false,
description: 'Filter requirements by state'
type Types::RequirementsManagement::RequirementType, null: true
def resolve(**args)
# The project could have been loaded in batch by `BatchLoader`.
# At this point we need the `id` of the project to query for issues, so
# make sure it's loaded and not `nil` before continuing.
project = object.respond_to?(:sync) ? object.sync : object
return ::RequirementsManagement::Requirement.none if project.nil?
return ::RequirementsManagement::Requirement.none unless Feature.enabled?(:requirements_management, project, default_enabled: true)
args[:project_id] = project.id
args[:iids] ||= [args[:iid]].compact
::RequirementsManagement::RequirementsFinder.new(context[:current_user], args).execute
end
end
end
end
# frozen_string_literal: true
module Resolvers
class RequirementsResolver < BaseResolver
argument :iid, GraphQL::ID_TYPE,
required: false,
description: 'IID of the requirement, e.g., "1"'
argument :iids, [GraphQL::ID_TYPE],
required: false,
description: 'List of IIDs of requirements, e.g., [1, 2]'
argument :sort, Types::SortEnum,
required: false,
description: 'List requirements by sort order'
argument :state, Types::RequirementStateEnum,
required: false,
description: 'Filter requirements by state'
type Types::RequirementType, null: true
def resolve(**args)
# The project could have been loaded in batch by `BatchLoader`.
# At this point we need the `id` of the project to query for issues, so
# make sure it's loaded and not `nil` before continuing.
project = object.respond_to?(:sync) ? object.sync : object
return RequirementsManagement::Requirement.none if project.nil?
return RequirementsManagement::Requirement.none unless Feature.enabled?(:requirements_management, project, default_enabled: true)
args[:project_id] = project.id
args[:iids] ||= [args[:iid]].compact
RequirementsManagement::RequirementsFinder.new(context[:current_user], args).execute
end
end
end
# frozen_string_literal: true
module Types
class RequirementStateEnum < BaseEnum
graphql_name 'RequirementState'
description 'State of a requirement'
value 'OPENED', value: 'opened'
value 'ARCHIVED', value: 'archived'
end
end
# frozen_string_literal: true
module Types
# rubocop: disable Graphql/AuthorizeTypes
class RequirementStatesCountType < BaseObject
graphql_name 'RequirementStatesCount'
description 'Counts of requirements by their state.'
field :opened, GraphQL::INT_TYPE, null: true, description: 'Number of opened requirements'
field :archived, GraphQL::INT_TYPE, null: true, description: 'Number of archived requirements'
end
# rubocop: enable Graphql/AuthorizeTypes
end
# frozen_string_literal: true
module Types
class RequirementType < BaseObject
graphql_name 'Requirement'
description 'Represents a requirement.'
authorize :read_requirement
expose_permissions Types::PermissionTypes::Requirement
field :id, GraphQL::ID_TYPE, null: false,
description: 'ID of the requirement'
field :iid, GraphQL::ID_TYPE, null: false,
description: 'Internal ID of the requirement'
field :title, GraphQL::STRING_TYPE, null: true,
description: 'Title of the requirement'
field :state, RequirementStateEnum, null: false,
description: 'State of the requirement'
field :project, ProjectType, null: false,
description: 'Project to which the requirement belongs',
resolve: -> (obj, _args, _ctx) { Gitlab::Graphql::Loaders::BatchModelLoader.new(Project, obj.project_id).find }
field :author, Types::UserType, null: false,
description: 'Author of the requirement',
resolve: -> (obj, _args, _ctx) { Gitlab::Graphql::Loaders::BatchModelLoader.new(User, obj.author_id).find }
field :created_at, Types::TimeType, null: false,
description: 'Timestamp of when the requirement was created'
field :updated_at, Types::TimeType, null: false,
description: 'Timestamp of when the requirement was last updated'
end
end
# frozen_string_literal: true
module Types
module RequirementsManagement
class RequirementStateEnum < BaseEnum
graphql_name 'RequirementState'
description 'State of a requirement'
value 'OPENED', value: 'opened'
value 'ARCHIVED', value: 'archived'
end
end
end
# frozen_string_literal: true
module Types
module RequirementsManagement
# rubocop: disable Graphql/AuthorizeTypes
class RequirementStatesCountType < BaseObject
graphql_name 'RequirementStatesCount'
description 'Counts of requirements by their state.'
field :opened, GraphQL::INT_TYPE, null: true, description: 'Number of opened requirements'
field :archived, GraphQL::INT_TYPE, null: true, description: 'Number of archived requirements'
end
# rubocop: enable Graphql/AuthorizeTypes
end
end
# frozen_string_literal: true
module Types
module RequirementsManagement
class RequirementType < BaseObject
graphql_name 'Requirement'
description 'Represents a requirement.'
authorize :read_requirement
expose_permissions Types::PermissionTypes::Requirement
field :id, GraphQL::ID_TYPE, null: false,
description: 'ID of the requirement'
field :iid, GraphQL::ID_TYPE, null: false,
description: 'Internal ID of the requirement'
field :title, GraphQL::STRING_TYPE, null: true,
description: 'Title of the requirement'
field :state, RequirementsManagement::RequirementStateEnum, null: false,
description: 'State of the requirement'
field :project, ProjectType, null: false,
description: 'Project to which the requirement belongs',
resolve: -> (obj, _args, _ctx) { Gitlab::Graphql::Loaders::BatchModelLoader.new(Project, obj.project_id).find }
field :author, Types::UserType, null: false,
description: 'Author of the requirement',
resolve: -> (obj, _args, _ctx) { Gitlab::Graphql::Loaders::BatchModelLoader.new(User, obj.author_id).find }
field :created_at, Types::TimeType, null: false,
description: 'Timestamp of when the requirement was created'
field :updated_at, Types::TimeType, null: false,
description: 'Timestamp of when the requirement was last updated'
end
end
end
......@@ -2,7 +2,7 @@
require 'spec_helper'
describe Mutations::Requirements::Create do
describe Mutations::RequirementsManagement::CreateRequirement do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
describe Mutations::Requirements::Update do
describe Mutations::RequirementsManagement::UpdateRequirement do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let_it_be(:requirement) { create(:requirement, project: project) }
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
describe Resolvers::RequirementsResolver do
describe Resolvers::RequirementsManagement::RequirementsResolver do
include GraphqlHelpers
let_it_be(:current_user) { create(:user) }
......
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