Commit 669eb4d7 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Merge branch 'allow_issue_weight_null_graphql' into 'master'

Allow null as an acceptable value for issue weight in GraphQL API

See merge request gitlab-org/gitlab!64784
parents 30631669 82302cc1
......@@ -2548,7 +2548,7 @@ Input type: `IssueSetWeightInput`
| <a id="mutationissuesetweightclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. |
| <a id="mutationissuesetweightiid"></a>`iid` | [`String!`](#string) | The IID of the issue to mutate. |
| <a id="mutationissuesetweightprojectpath"></a>`projectPath` | [`ID!`](#id) | The project the issue to mutate is in. |
| <a id="mutationissuesetweightweight"></a>`weight` | [`Int!`](#int) | The desired weight for the issue. |
| <a id="mutationissuesetweightweight"></a>`weight` | [`Int`](#int) | The desired weight for the issue. If set to null, weight is removed. |
#### Fields
......
......@@ -7,8 +7,17 @@ module Mutations
argument :weight,
GraphQL::INT_TYPE,
required: true,
description: 'The desired weight for the issue.'
required: false,
description: 'The desired weight for the issue. ' \
'If set to null, weight is removed.'
def ready?(**args)
unless args.key?(:weight)
raise Gitlab::Graphql::Errors::ArgumentError, 'The `weight` argument is required (`null` accepted).'
end
super
end
def resolve(project_path:, iid:, weight:)
issue = authorized_find!(project_path: project_path, iid: iid)
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe Mutations::Issues::SetWeight do
let(:issue) { create(:issue) }
let(:issue) { create(:issue, weight: 1) }
let(:user) { create(:user) }
subject(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) }
......@@ -20,11 +20,19 @@ RSpec.describe Mutations::Issues::SetWeight do
issue.project.add_developer(user)
end
it 'returns the issue with correct weight' do
it 'returns the issue with correct weight', :aggregate_failures do
expect(mutated_issue).to eq(issue)
expect(mutated_issue.weight).to eq(2)
expect(subject[:errors]).to be_empty
end
context 'when the weight is nil' do
let(:weight) { nil }
it 'updates weight to be nil' do
expect(mutated_issue.weight).to be nil
end
end
end
end
end
......@@ -6,7 +6,7 @@ RSpec.describe 'Setting weight of an issue' do
include GraphqlHelpers
let(:current_user) { create(:user) }
let(:issue) { create(:issue) }
let(:issue) { create(:issue, weight: 1) }
let(:project) { issue.project }
let(:input) { { weight: 2 } }
......@@ -44,11 +44,34 @@ RSpec.describe 'Setting weight of an issue' do
expect(graphql_errors).to include(a_hash_including('message' => error))
end
it 'updates the issue weight' do
post_graphql_mutation(mutation, current_user: current_user)
context 'when weight is a number' do
it 'updates the issue weight' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['issue']['weight']).to eq(2)
end
end
context 'when weight is null' do
let(:input) { { weight: nil } }
it 'updates the issue weight' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['issue']['weight']).to eq(2)
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['issue']['weight']).to eq(nil)
end
end
context 'when weight is not given' do
let(:input) { {} }
it 'returns an error' do
post_graphql_mutation(mutation, current_user: current_user)
expect(graphql_errors).to include(a_hash_including('message' => /The `weight` argument is required \(`null` accepted\)/))
end
end
context 'when weight is not an integer' 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