Commit 246802f7 authored by Robert Speicher's avatar Robert Speicher

Merge branch '36317-graphql-mutation-for-changing-weight-of-an-issue13254-issue-2' into 'master'

Add GraphQL mutation for changing weight of an issue

Closes #36317

See merge request gitlab-org/gitlab!21331
parents d23d545b 4c696325
...@@ -2898,6 +2898,51 @@ type IssueSetDueDatePayload { ...@@ -2898,6 +2898,51 @@ type IssueSetDueDatePayload {
issue: Issue issue: Issue
} }
"""
Autogenerated input type of IssueSetWeight
"""
input IssueSetWeightInput {
"""
A unique identifier for the client performing the mutation.
"""
clientMutationId: String
"""
The iid of the issue to mutate
"""
iid: String!
"""
The project the issue to mutate is in
"""
projectPath: ID!
"""
The desired weight for the issue
"""
weight: Int!
}
"""
Autogenerated return type of IssueSetWeight
"""
type IssueSetWeightPayload {
"""
A unique identifier for the client performing the mutation.
"""
clientMutationId: String
"""
Reasons why the mutation failed.
"""
errors: [String!]!
"""
The issue after mutation
"""
issue: Issue
}
""" """
Values for sorting issues Values for sorting issues
""" """
...@@ -3895,6 +3940,7 @@ type Mutation { ...@@ -3895,6 +3940,7 @@ type Mutation {
epicTreeReorder(input: EpicTreeReorderInput!): EpicTreeReorderPayload epicTreeReorder(input: EpicTreeReorderInput!): EpicTreeReorderPayload
issueSetConfidential(input: IssueSetConfidentialInput!): IssueSetConfidentialPayload issueSetConfidential(input: IssueSetConfidentialInput!): IssueSetConfidentialPayload
issueSetDueDate(input: IssueSetDueDateInput!): IssueSetDueDatePayload issueSetDueDate(input: IssueSetDueDateInput!): IssueSetDueDatePayload
issueSetWeight(input: IssueSetWeightInput!): IssueSetWeightPayload
mergeRequestSetAssignees(input: MergeRequestSetAssigneesInput!): MergeRequestSetAssigneesPayload mergeRequestSetAssignees(input: MergeRequestSetAssigneesInput!): MergeRequestSetAssigneesPayload
mergeRequestSetLabels(input: MergeRequestSetLabelsInput!): MergeRequestSetLabelsPayload mergeRequestSetLabels(input: MergeRequestSetLabelsInput!): MergeRequestSetLabelsPayload
mergeRequestSetLocked(input: MergeRequestSetLockedInput!): MergeRequestSetLockedPayload mergeRequestSetLocked(input: MergeRequestSetLockedInput!): MergeRequestSetLockedPayload
......
...@@ -16076,6 +16076,33 @@ ...@@ -16076,6 +16076,33 @@
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
}, },
{
"name": "issueSetWeight",
"description": null,
"args": [
{
"name": "input",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "IssueSetWeightInput",
"ofType": null
}
},
"defaultValue": null
}
],
"type": {
"kind": "OBJECT",
"name": "IssueSetWeightPayload",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "mergeRequestSetAssignees", "name": "mergeRequestSetAssignees",
"description": null, "description": null,
...@@ -19941,6 +19968,136 @@ ...@@ -19941,6 +19968,136 @@
"enumValues": null, "enumValues": null,
"possibleTypes": null "possibleTypes": null
}, },
{
"kind": "OBJECT",
"name": "IssueSetWeightPayload",
"description": "Autogenerated return type of IssueSetWeight",
"fields": [
{
"name": "clientMutationId",
"description": "A unique identifier for the client performing the mutation.",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "errors",
"description": "Reasons why the mutation failed.",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
}
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "issue",
"description": "The issue after mutation",
"args": [
],
"type": {
"kind": "OBJECT",
"name": "Issue",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [
],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "INPUT_OBJECT",
"name": "IssueSetWeightInput",
"description": "Autogenerated input type of IssueSetWeight",
"fields": null,
"inputFields": [
{
"name": "projectPath",
"description": "The project the issue to mutate is in",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
},
"defaultValue": null
},
{
"name": "iid",
"description": "The iid of the issue to mutate",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"defaultValue": null
},
{
"name": "weight",
"description": "The desired weight for the issue",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
}
},
"defaultValue": null
},
{
"name": "clientMutationId",
"description": "A unique identifier for the client performing the mutation.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
}
],
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{ {
"kind": "OBJECT", "kind": "OBJECT",
"name": "EpicTreeReorderPayload", "name": "EpicTreeReorderPayload",
......
...@@ -410,6 +410,14 @@ The API can be explored interactively using the [GraphiQL IDE](../index.md#graph ...@@ -410,6 +410,14 @@ The API can be explored interactively using the [GraphiQL IDE](../index.md#graph
| `errors` | String! => Array | Reasons why the mutation failed. | | `errors` | String! => Array | Reasons why the mutation failed. |
| `issue` | Issue | The issue after mutation | | `issue` | Issue | The issue after mutation |
### IssueSetWeightPayload
| Name | Type | Description |
| --- | ---- | ---------- |
| `clientMutationId` | String | A unique identifier for the client performing the mutation. |
| `errors` | String! => Array | Reasons why the mutation failed. |
| `issue` | Issue | The issue after mutation |
### Label ### Label
| Name | Type | Description | | Name | Type | Description |
......
...@@ -8,6 +8,7 @@ module EE ...@@ -8,6 +8,7 @@ module EE
prepended do prepended do
mount_mutation ::Mutations::DesignManagement::Upload, calls_gitaly: true mount_mutation ::Mutations::DesignManagement::Upload, calls_gitaly: true
mount_mutation ::Mutations::DesignManagement::Delete, calls_gitaly: true mount_mutation ::Mutations::DesignManagement::Delete, calls_gitaly: true
mount_mutation ::Mutations::Issues::SetWeight
mount_mutation ::Mutations::EpicTree::Reorder mount_mutation ::Mutations::EpicTree::Reorder
mount_mutation ::Mutations::Epics::Update mount_mutation ::Mutations::Epics::Update
mount_mutation ::Mutations::Epics::Create mount_mutation ::Mutations::Epics::Create
......
# frozen_string_literal: true
module Mutations
module Issues
class SetWeight < ::Mutations::Issues::Base
graphql_name 'IssueSetWeight'
argument :weight,
GraphQL::INT_TYPE,
required: true,
description: 'The desired weight for the issue'
def resolve(project_path:, iid:, weight:)
issue = authorized_find!(project_path: project_path, iid: iid)
project = issue.project
::Issues::UpdateService.new(project, current_user, weight: weight)
.execute(issue)
{
issue: issue,
errors: issue.errors.full_messages
}
end
end
end
end
---
title: Add GraphQL mutation for changing weight of an issue
merge_request: 21331
author:
type: added
# frozen_string_literal: true
require 'spec_helper'
describe Mutations::Issues::SetWeight do
let(:issue) { create(:issue) }
let(:user) { create(:user) }
subject(:mutation) { described_class.new(object: nil, context: { current_user: user }) }
describe '#resolve' do
let(:weight) { 2 }
let(:mutated_issue) { subject[:issue] }
subject { mutation.resolve(project_path: issue.project.full_path, iid: issue.iid, weight: weight) }
it 'raises an error if the resource is not accessible to the user' do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
context 'when the user can update the issue' do
before do
issue.project.add_developer(user)
end
it 'returns the issue with correct weight' do
expect(mutated_issue).to eq(issue)
expect(mutated_issue.weight).to eq(2)
expect(subject[:errors]).to be_empty
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe 'Setting weight of an issue' do
include GraphqlHelpers
let(:current_user) { create(:user) }
let(:issue) { create(:issue) }
let(:project) { issue.project }
let(:input) { { weight: 2 } }
let(:mutation) do
variables = {
project_path: project.full_path,
iid: issue.iid.to_s
}
graphql_mutation(:issue_set_weight, variables.merge(input),
<<-QL.strip_heredoc
clientMutationId
errors
issue {
iid
weight
}
QL
)
end
def mutation_response
graphql_mutation_response(:issue_set_weight)
end
before do
project.add_developer(current_user)
end
it 'returns an error if the user is not allowed to update the issue' do
error = "The resource that you are attempting to access does not exist or you "\
"don't have permission to perform this action"
post_graphql_mutation(mutation, current_user: create(:user))
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)
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['issue']['weight']).to eq(2)
end
context 'when weight is not an integer' do
let(:input) { { weight: "2" } }
it 'raises invalid value error' do
error = "Variable issueSetWeightInput of type IssueSetWeightInput! was provided "\
"invalid value for weight (Could not coerce value \"#{input[:weight]}\" to Int)"
post_graphql_mutation(mutation, current_user: current_user)
expect(graphql_errors).to include(a_hash_including('message' => error))
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