Commit d28e7206 authored by Mario Celi's avatar Mario Celi

Add issuableUpdate subscription to GraphQL

New subscription is only triggered when a
work item is updated for now
parent f039e8cf
......@@ -8,4 +8,8 @@ module GraphqlTriggers
def self.issue_crm_contacts_updated(issue)
GitlabSchema.subscriptions.trigger('issueCrmContactsUpdated', { issuable_id: issue.to_gid }, issue)
end
def self.issuable_title_updated(issuable)
GitlabSchema.subscriptions.trigger('issuableTitleUpdated', { issuable_id: issuable.to_gid }, issuable)
end
end
......@@ -5,10 +5,12 @@ module Types
graphql_name 'Issuable'
description 'Represents an issuable.'
possible_types Types::IssueType, Types::MergeRequestType
possible_types Types::IssueType, Types::MergeRequestType, Types::WorkItemType
def self.resolve_type(object, context)
case object
when WorkItem
Types::WorkItemType
when Issue
Types::IssueType
when MergeRequest
......
......@@ -9,5 +9,8 @@ module Types
field :issue_crm_contacts_updated, subscription: Subscriptions::IssuableUpdated, null: true,
description: 'Triggered when the crm contacts of an issuable are updated.'
field :issuable_title_updated, subscription: Subscriptions::IssuableUpdated, null: true,
description: 'Triggered when the title of an issuable is updated.'
end
end
......@@ -2,5 +2,12 @@
module WorkItems
class UpdateService < ::Issues::UpdateService
private
def after_update(issuable)
super
GraphqlTriggers.issuable_title_updated(issuable) if issuable.previous_changes.key?(:title)
end
end
end
......@@ -18761,6 +18761,7 @@ One of:
- [`Epic`](#epic)
- [`Issue`](#issue)
- [`MergeRequest`](#mergerequest)
- [`WorkItem`](#workitem)
#### `JobNeedUnion`
......@@ -17,4 +17,18 @@ RSpec.describe GraphqlTriggers do
GraphqlTriggers.issuable_assignees_updated(issue)
end
end
describe '.issuable_title_updated' do
it 'triggers the issuableTitleUpdated subscription' do
work_item = create(:work_item)
expect(GitlabSchema.subscriptions).to receive(:trigger).with(
'issuableTitleUpdated',
{ issuable_id: work_item.to_gid },
work_item
).and_call_original
GraphqlTriggers.issuable_title_updated(work_item)
end
end
end
......@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe GitlabSchema.types['Issuable'] do
it 'returns possible types' do
expect(described_class.possible_types).to include(Types::IssueType, Types::MergeRequestType)
expect(described_class.possible_types).to include(Types::IssueType, Types::MergeRequestType, Types::WorkItemType)
end
describe '.resolve_type' do
......@@ -16,6 +16,10 @@ RSpec.describe GitlabSchema.types['Issuable'] do
expect(described_class.resolve_type(build(:merge_request), {})).to eq(Types::MergeRequestType)
end
it 'resolves work items' do
expect(described_class.resolve_type(build(:work_item), {})).to eq(Types::WorkItemType)
end
it 'raises an error for invalid types' do
expect { described_class.resolve_type(build(:user), {}) }.to raise_error 'Unsupported issuable type'
end
......
......@@ -7,6 +7,7 @@ RSpec.describe GitlabSchema.types['Subscription'] do
expected_fields = %i[
issuable_assignees_updated
issue_crm_contacts_updated
issuable_title_updated
]
expect(described_class).to have_graphql_fields(*expected_fields).only
......
......@@ -18,6 +18,26 @@ RSpec.describe WorkItems::UpdateService do
stub_spam_services
end
context 'when title is changed' do
let(:opts) { { title: 'changed' } }
it 'triggers issuable_title_updated graphql subscription' do
expect(GraphqlTriggers).to receive(:issuable_title_updated).with(work_item).and_call_original
update_work_item
end
end
context 'when title is not changed' do
let(:opts) { { description: 'changed' } }
it 'does not trigger issuable_title_updated graphql subscription' do
expect(GraphqlTriggers).not_to receive(:issuable_title_updated)
update_work_item
end
end
context 'when updating state_event' do
context 'when state_event is close' do
let(:opts) { { state_event: 'close' } }
......
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