Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
d28e7206
Commit
d28e7206
authored
Feb 09, 2022
by
Mario Celi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add issuableUpdate subscription to GraphQL
New subscription is only triggered when a work item is updated for now
parent
f039e8cf
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
58 additions
and
2 deletions
+58
-2
app/graphql/graphql_triggers.rb
app/graphql/graphql_triggers.rb
+4
-0
app/graphql/types/issuable_type.rb
app/graphql/types/issuable_type.rb
+3
-1
app/graphql/types/subscription_type.rb
app/graphql/types/subscription_type.rb
+3
-0
app/services/work_items/update_service.rb
app/services/work_items/update_service.rb
+7
-0
doc/api/graphql/reference/index.md
doc/api/graphql/reference/index.md
+1
-0
spec/graphql/graphql_triggers_spec.rb
spec/graphql/graphql_triggers_spec.rb
+14
-0
spec/graphql/types/issuable_type_spec.rb
spec/graphql/types/issuable_type_spec.rb
+5
-1
spec/graphql/types/subscription_type_spec.rb
spec/graphql/types/subscription_type_spec.rb
+1
-0
spec/services/work_items/update_service_spec.rb
spec/services/work_items/update_service_spec.rb
+20
-0
No files found.
app/graphql/graphql_triggers.rb
View file @
d28e7206
...
@@ -8,4 +8,8 @@ module GraphqlTriggers
...
@@ -8,4 +8,8 @@ module GraphqlTriggers
def
self
.
issue_crm_contacts_updated
(
issue
)
def
self
.
issue_crm_contacts_updated
(
issue
)
GitlabSchema
.
subscriptions
.
trigger
(
'issueCrmContactsUpdated'
,
{
issuable_id:
issue
.
to_gid
},
issue
)
GitlabSchema
.
subscriptions
.
trigger
(
'issueCrmContactsUpdated'
,
{
issuable_id:
issue
.
to_gid
},
issue
)
end
end
def
self
.
issuable_title_updated
(
issuable
)
GitlabSchema
.
subscriptions
.
trigger
(
'issuableTitleUpdated'
,
{
issuable_id:
issuable
.
to_gid
},
issuable
)
end
end
end
app/graphql/types/issuable_type.rb
View file @
d28e7206
...
@@ -5,10 +5,12 @@ module Types
...
@@ -5,10 +5,12 @@ module Types
graphql_name
'Issuable'
graphql_name
'Issuable'
description
'Represents an 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
)
def
self
.
resolve_type
(
object
,
context
)
case
object
case
object
when
WorkItem
Types
::
WorkItemType
when
Issue
when
Issue
Types
::
IssueType
Types
::
IssueType
when
MergeRequest
when
MergeRequest
...
...
app/graphql/types/subscription_type.rb
View file @
d28e7206
...
@@ -9,5 +9,8 @@ module Types
...
@@ -9,5 +9,8 @@ module Types
field
:issue_crm_contacts_updated
,
subscription:
Subscriptions
::
IssuableUpdated
,
null:
true
,
field
:issue_crm_contacts_updated
,
subscription:
Subscriptions
::
IssuableUpdated
,
null:
true
,
description:
'Triggered when the crm contacts of an issuable are updated.'
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
end
end
app/services/work_items/update_service.rb
View file @
d28e7206
...
@@ -2,5 +2,12 @@
...
@@ -2,5 +2,12 @@
module
WorkItems
module
WorkItems
class
UpdateService
<
::
Issues
::
UpdateService
class
UpdateService
<
::
Issues
::
UpdateService
private
def
after_update
(
issuable
)
super
GraphqlTriggers
.
issuable_title_updated
(
issuable
)
if
issuable
.
previous_changes
.
key?
(
:title
)
end
end
end
end
end
doc/api/graphql/reference/index.md
View file @
d28e7206
...
@@ -18761,6 +18761,7 @@ One of:
...
@@ -18761,6 +18761,7 @@ One of:
- [`Epic`](#epic)
- [`Epic`](#epic)
- [`Issue`](#issue)
- [`Issue`](#issue)
- [`MergeRequest`](#mergerequest)
- [`MergeRequest`](#mergerequest)
- [`WorkItem`](#workitem)
#### `JobNeedUnion`
#### `JobNeedUnion`
spec/graphql/graphql_triggers_spec.rb
View file @
d28e7206
...
@@ -17,4 +17,18 @@ RSpec.describe GraphqlTriggers do
...
@@ -17,4 +17,18 @@ RSpec.describe GraphqlTriggers do
GraphqlTriggers
.
issuable_assignees_updated
(
issue
)
GraphqlTriggers
.
issuable_assignees_updated
(
issue
)
end
end
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
end
spec/graphql/types/issuable_type_spec.rb
View file @
d28e7206
...
@@ -4,7 +4,7 @@ require 'spec_helper'
...
@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec
.
describe
GitlabSchema
.
types
[
'Issuable'
]
do
RSpec
.
describe
GitlabSchema
.
types
[
'Issuable'
]
do
it
'returns possible types'
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
end
describe
'.resolve_type'
do
describe
'.resolve_type'
do
...
@@ -16,6 +16,10 @@ RSpec.describe GitlabSchema.types['Issuable'] do
...
@@ -16,6 +16,10 @@ RSpec.describe GitlabSchema.types['Issuable'] do
expect
(
described_class
.
resolve_type
(
build
(
:merge_request
),
{})).
to
eq
(
Types
::
MergeRequestType
)
expect
(
described_class
.
resolve_type
(
build
(
:merge_request
),
{})).
to
eq
(
Types
::
MergeRequestType
)
end
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
it
'raises an error for invalid types'
do
expect
{
described_class
.
resolve_type
(
build
(
:user
),
{})
}.
to
raise_error
'Unsupported issuable type'
expect
{
described_class
.
resolve_type
(
build
(
:user
),
{})
}.
to
raise_error
'Unsupported issuable type'
end
end
...
...
spec/graphql/types/subscription_type_spec.rb
View file @
d28e7206
...
@@ -7,6 +7,7 @@ RSpec.describe GitlabSchema.types['Subscription'] do
...
@@ -7,6 +7,7 @@ RSpec.describe GitlabSchema.types['Subscription'] do
expected_fields
=
%i[
expected_fields
=
%i[
issuable_assignees_updated
issuable_assignees_updated
issue_crm_contacts_updated
issue_crm_contacts_updated
issuable_title_updated
]
]
expect
(
described_class
).
to
have_graphql_fields
(
*
expected_fields
).
only
expect
(
described_class
).
to
have_graphql_fields
(
*
expected_fields
).
only
...
...
spec/services/work_items/update_service_spec.rb
View file @
d28e7206
...
@@ -18,6 +18,26 @@ RSpec.describe WorkItems::UpdateService do
...
@@ -18,6 +18,26 @@ RSpec.describe WorkItems::UpdateService do
stub_spam_services
stub_spam_services
end
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 updating state_event'
do
context
'when state_event is close'
do
context
'when state_event is close'
do
let
(
:opts
)
{
{
state_event:
'close'
}
}
let
(
:opts
)
{
{
state_event:
'close'
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment