Commit 87b61455 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch '292477-compliance-framework-graphql-base-input-object' into 'master'

Refactor Compliance Framework graphql parameters

See merge request gitlab-org/gitlab!50154
parents 4d9b9c2d 47c247d3
......@@ -3595,6 +3595,23 @@ type ComplianceFrameworkEdge {
node: ComplianceFramework
}
input ComplianceFrameworkInput {
"""
New color representation of the compliance framework in hex format. e.g. #FCA121.
"""
color: String
"""
New description for the compliance framework.
"""
description: String
"""
New name for the compliance framework.
"""
name: String
}
"""
Identifier of ComplianceManagement::Framework
"""
......@@ -4386,24 +4403,14 @@ input CreateComplianceFrameworkInput {
clientMutationId: String
"""
Color to represent the compliance framework as a hexadecimal value. e.g. #ABC123.
"""
color: String!
"""
Description of the compliance framework.
"""
description: String!
"""
Name of the compliance framework.
Full path of the namespace to add the compliance framework to.
"""
name: String!
namespacePath: ID!
"""
Full path of the namespace to add the compliance framework to.
Parameters to update the compliance framework with.
"""
namespacePath: ID!
params: ComplianceFrameworkInput!
}
"""
......@@ -24295,24 +24302,14 @@ input UpdateComplianceFrameworkInput {
clientMutationId: String
"""
New color representation of the compliance framework in hex format. e.g. #FCA121
"""
color: String
"""
New description for the compliance framework
"""
description: String
"""
The global ID of the compliance framework to update
The global ID of the compliance framework to update.
"""
id: ComplianceManagementFrameworkID!
"""
New name for the compliance framework
Parameters to update the compliance framework with.
"""
name: String
params: ComplianceFrameworkInput!
}
"""
......@@ -24325,7 +24322,7 @@ type UpdateComplianceFrameworkPayload {
clientMutationId: String
"""
The compliance framework after mutation
The compliance framework after mutation.
"""
complianceFramework: ComplianceFramework
......
......@@ -9834,6 +9834,47 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "INPUT_OBJECT",
"name": "ComplianceFrameworkInput",
"description": null,
"fields": null,
"inputFields": [
{
"name": "name",
"description": "New name for the compliance framework.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "description",
"description": "New description for the compliance framework.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "color",
"description": "New color representation of the compliance framework in hex format. e.g. #FCA121.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
}
],
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "SCALAR",
"name": "ComplianceManagementFrameworkID",
......@@ -11975,42 +12016,14 @@
"defaultValue": null
},
{
"name": "name",
"description": "Name of the compliance framework.",
"name": "params",
"description": "Parameters to update the compliance framework with.",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"defaultValue": null
},
{
"name": "description",
"description": "Description of the compliance framework.",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"defaultValue": null
},
{
"name": "color",
"description": "Color to represent the compliance framework as a hexadecimal value. e.g. #ABC123.",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"kind": "INPUT_OBJECT",
"name": "ComplianceFrameworkInput",
"ofType": null
}
},
......@@ -70788,7 +70801,7 @@
"inputFields": [
{
"name": "id",
"description": "The global ID of the compliance framework to update",
"description": "The global ID of the compliance framework to update.",
"type": {
"kind": "NON_NULL",
"name": null,
......@@ -70801,32 +70814,16 @@
"defaultValue": null
},
{
"name": "name",
"description": "New name for the compliance framework",
"name": "params",
"description": "Parameters to update the compliance framework with.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "description",
"description": "New description for the compliance framework",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "color",
"description": "New color representation of the compliance framework in hex format. e.g. #FCA121",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "ComplianceFrameworkInput",
"ofType": null
}
},
"defaultValue": null
},
......@@ -70866,7 +70863,7 @@
},
{
"name": "complianceFramework",
"description": "The compliance framework after mutation",
"description": "The compliance framework after mutation.",
"args": [
],
......@@ -3645,7 +3645,7 @@ Autogenerated return type of UpdateComplianceFramework.
| Field | Type | Description |
| ----- | ---- | ----------- |
| `clientMutationId` | String | A unique identifier for the client performing the mutation. |
| `complianceFramework` | ComplianceFramework | The compliance framework after mutation |
| `complianceFramework` | ComplianceFramework | The compliance framework after mutation. |
| `errors` | String! => Array | Errors encountered during execution of the mutation. |
### UpdateContainerExpirationPolicyPayload
......
......@@ -15,21 +15,13 @@ module Mutations
required: true,
description: 'Full path of the namespace to add the compliance framework to.'
argument :name, GraphQL::STRING_TYPE,
argument :params, Types::ComplianceManagement::ComplianceFrameworkInputType,
required: true,
description: 'Name of the compliance framework.'
argument :description, GraphQL::STRING_TYPE,
required: true,
description: 'Description of the compliance framework.'
argument :color, GraphQL::STRING_TYPE,
required: true,
description: 'Color to represent the compliance framework as a hexadecimal value. e.g. #ABC123.'
description: 'Parameters to update the compliance framework with.'
def resolve(**args)
service = ::ComplianceManagement::Frameworks::CreateService.new(namespace: namespace(args[:namespace_path]),
params: args,
params: args[:params].to_h,
current_user: current_user).execute
service.success? ? success(service) : error(service)
......
......@@ -11,33 +11,22 @@ module Mutations
argument :id,
::Types::GlobalIDType[::ComplianceManagement::Framework],
required: true,
description: 'The global ID of the compliance framework to update'
description: 'The global ID of the compliance framework to update.'
argument :name,
GraphQL::STRING_TYPE,
required: false,
description: 'New name for the compliance framework'
argument :description,
GraphQL::STRING_TYPE,
required: false,
description: 'New description for the compliance framework'
argument :color,
GraphQL::STRING_TYPE,
required: false,
description: 'New color representation of the compliance framework in hex format. e.g. #FCA121'
argument :params, Types::ComplianceManagement::ComplianceFrameworkInputType,
required: true,
description: 'Parameters to update the compliance framework with.'
field :compliance_framework,
Types::ComplianceManagement::ComplianceFrameworkType,
null: true,
description: "The compliance framework after mutation"
description: "The compliance framework after mutation."
def resolve(id:, **args)
framework = authorized_find!(id: id)
::ComplianceManagement::Frameworks::UpdateService.new(framework: framework,
current_user: current_user,
params: args).execute
params: args[:params].to_h).execute
{ compliance_framework: framework, errors: errors_on_object(framework) }
end
......
# frozen_string_literal: true
module Types
module ComplianceManagement
# rubocop: disable Graphql/AuthorizeTypes
class ComplianceFrameworkInputType < BaseInputObject
graphql_name 'ComplianceFrameworkInput'
argument :name,
GraphQL::STRING_TYPE,
required: false,
description: 'New name for the compliance framework.'
argument :description,
GraphQL::STRING_TYPE,
required: false,
description: 'New description for the compliance framework.'
argument :color,
GraphQL::STRING_TYPE,
required: false,
description: 'New color representation of the compliance framework in hex format. e.g. #FCA121.'
end
end
end
......@@ -84,7 +84,7 @@ RSpec.describe Mutations::ComplianceManagement::Frameworks::Create do
end
context 'framework parameters are invalid' do
let(:params) { valid_params.merge(color: 'notacolor') }
subject { mutation.resolve(invalid_color_params) }
it 'does not create a new compliance framework' do
expect { subject }.not_to change { namespace.compliance_management_frameworks.count }
......@@ -103,9 +103,22 @@ RSpec.describe Mutations::ComplianceManagement::Frameworks::Create do
def valid_params
{
namespace_path: namespace.full_path,
name: 'GDPR',
description: 'Example description',
color: '#abc123'
params: {
name: 'GDPR',
description: 'Example description',
color: '#abc123'
}
}
end
def invalid_color_params
{
namespace_path: namespace.full_path,
params: {
name: 'GDPR',
description: 'Example description',
color: '#notacolor'
}
}
end
end
......@@ -16,7 +16,7 @@ RSpec.describe Mutations::ComplianceManagement::Frameworks::Update do
}
end
subject { mutation.resolve(id: global_id_of(framework), **params) }
subject { mutation.resolve(id: global_id_of(framework), params: params) }
context 'feature is enabled and licensed' do
before do
......
......@@ -12,9 +12,11 @@ RSpec.describe 'Create a Compliance Framework' do
graphql_mutation(
:create_compliance_framework,
namespace_path: namespace.full_path,
name: 'GDPR',
description: 'Example Description',
color: '#ABC123'
params: {
name: 'GDPR',
description: 'Example Description',
color: '#ABC123'
}
)
end
......
......@@ -10,9 +10,11 @@ RSpec.describe 'Update a compliance framework' do
let(:current_user) { framework.namespace.owner }
let(:params) do
{
name: 'New Name',
description: 'New Description',
color: '#AAC112'
params: {
name: 'New Name',
description: 'New Description',
color: '#AAC112'
}
}
end
......@@ -72,9 +74,11 @@ RSpec.describe 'Update a compliance framework' do
context 'with invalid params' do
let(:params) do
{
name: '',
description: '',
color: 'NOTACOLOR'
params: {
name: '',
description: '',
color: 'NOTACOLOR'
}
}
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