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
5cc540c7
Commit
5cc540c7
authored
Dec 14, 2020
by
Jonathan Schafer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
User count resolvers for EpicType
Add test specs for EpicType in ee
parent
2d1cc720
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
129 additions
and
23 deletions
+129
-23
ee/app/graphql/types/epic_type.rb
ee/app/graphql/types/epic_type.rb
+4
-22
ee/spec/graphql/resolvers/user_discussions_count_resolver_spec.rb
...graphql/resolvers/user_discussions_count_resolver_spec.rb
+61
-0
ee/spec/graphql/resolvers/user_notes_count_resolver_spec.rb
ee/spec/graphql/resolvers/user_notes_count_resolver_spec.rb
+63
-0
ee/spec/requests/api/graphql/group/epics_spec.rb
ee/spec/requests/api/graphql/group/epics_spec.rb
+1
-1
No files found.
ee/app/graphql/types/epic_type.rb
View file @
5cc540c7
...
...
@@ -66,9 +66,11 @@ module Types
description:
'Number of downvotes the epic has received'
field
:user_notes_count
,
GraphQL
::
INT_TYPE
,
null:
false
,
description:
'Number of user notes of the epic'
description:
'Number of user notes of the epic'
,
resolver:
Resolvers
::
UserNotesCountResolver
field
:user_discussions_count
,
GraphQL
::
INT_TYPE
,
null:
false
,
description:
'Number of user discussions in the epic'
description:
'Number of user discussions in the epic'
,
resolver:
Resolvers
::
UserDiscussionsCountResolver
field
:closed_at
,
Types
::
TimeType
,
null:
true
,
description:
'Timestamp of when the epic was closed'
...
...
@@ -139,26 +141,6 @@ module Types
field
:health_status
,
Types
::
EpicHealthStatusType
,
null:
true
,
complexity:
10
,
description:
'Current health status of the epic'
def
user_notes_count
BatchLoader
::
GraphQL
.
for
(
object
.
id
).
batch
(
key: :epic_user_notes_count
)
do
|
ids
,
loader
,
args
|
counts
=
Note
.
count_for_collection
(
ids
,
'Epic'
).
index_by
(
&
:noteable_id
)
ids
.
each
do
|
id
|
loader
.
call
(
id
,
counts
[
id
]
&
.
count
||
0
)
end
end
end
def
user_discussions_count
BatchLoader
::
GraphQL
.
for
(
object
.
id
).
batch
(
key: :epic_user_discussions_count
)
do
|
ids
,
loader
,
args
|
counts
=
Note
.
count_for_collection
(
ids
,
'Epic'
,
'COUNT(DISTINCT discussion_id) as count'
).
index_by
(
&
:noteable_id
)
ids
.
each
do
|
id
|
loader
.
call
(
id
,
counts
[
id
]
&
.
count
||
0
)
end
end
end
def
has_children?
Gitlab
::
Graphql
::
Aggregations
::
Epics
::
LazyEpicAggregate
.
new
(
context
,
object
.
id
,
COUNT
)
do
|
node
,
_aggregate_object
|
node
.
children
.
any?
...
...
ee/spec/graphql/resolvers/user_discussions_count_resolver_spec.rb
0 → 100644
View file @
5cc540c7
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Resolvers
::
UserDiscussionsCountResolver
do
include
GraphqlHelpers
describe
'#resolve'
do
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:repository
,
:public
)
}
let_it_be
(
:private_project
)
{
create
(
:project
,
:repository
,
:private
)
}
specify
do
expect
(
described_class
).
to
have_nullable_graphql_type
(
GraphQL
::
INT_TYPE
)
end
context
'when counting discussions from an epic'
do
let_it_be
(
:epic
)
{
create
(
:epic
)
}
let_it_be
(
:private_epic
)
{
create
(
:epic
,
group:
create
(
:group
,
:private
))
}
let_it_be
(
:public_discussions
)
{
create_list
(
:discussion_note
,
2
,
noteable:
epic
)
}
let_it_be
(
:system_note
)
{
create
(
:discussion_note
,
system:
true
,
noteable:
epic
)
}
let_it_be
(
:private_discussions
)
{
create_list
(
:discussion_note
,
3
,
noteable:
private_epic
)
}
before
do
stub_licensed_features
(
epics:
true
)
end
context
'when counting discussions from a public epic'
do
subject
{
batch_sync
{
resolve_user_discussions_count
(
epic
)
}
}
it
'returns the number of non-system discussions for the epic'
do
expect
(
subject
).
to
eq
(
2
)
end
end
context
'when a user has permission to view discussions'
do
before
do
private_epic
.
group
.
add_developer
(
user
)
end
subject
{
batch_sync
{
resolve_user_discussions_count
(
private_epic
)
}
}
it
'returns the number of discussions for the issue'
do
expect
(
subject
).
to
eq
(
3
)
end
end
context
'when a user does not have permission to view discussions'
do
subject
{
batch_sync
{
resolve_user_discussions_count
(
private_epic
)
}
}
it
'raises an error'
do
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
end
end
end
end
def
resolve_user_discussions_count
(
obj
)
resolve
(
described_class
,
obj:
obj
,
ctx:
{
current_user:
user
})
end
end
ee/spec/graphql/resolvers/user_notes_count_resolver_spec.rb
0 → 100644
View file @
5cc540c7
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Resolvers
::
UserNotesCountResolver
do
include
GraphqlHelpers
describe
'#resolve'
do
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:repository
,
:public
)
}
let_it_be
(
:private_project
)
{
create
(
:project
,
:repository
,
:private
)
}
specify
do
expect
(
described_class
).
to
have_nullable_graphql_type
(
GraphQL
::
INT_TYPE
)
end
context
'when counting notes from an epic'
do
let_it_be
(
:epic
)
{
create
(
:epic
)
}
let_it_be
(
:private_epic
)
{
create
(
:epic
,
group:
create
(
:group
,
:private
))
}
let_it_be
(
:public_notes
)
{
create_list
(
:note
,
2
,
noteable:
epic
)
}
let_it_be
(
:system_note
)
{
create
(
:note
,
system:
true
,
noteable:
epic
)
}
let_it_be
(
:private_notes
)
{
create_list
(
:note
,
3
,
noteable:
private_epic
)
}
context
'when epics feature is available'
do
before
do
stub_licensed_features
(
epics:
true
)
end
context
'when counting notes from a public epic'
do
subject
{
batch_sync
{
resolve_user_notes_count
(
epic
)
}
}
it
'returns the number of non-system notes for the epic'
do
expect
(
subject
).
to
eq
(
2
)
end
end
context
'when a user has permission to view notes'
do
before
do
private_epic
.
group
.
add_developer
(
user
)
end
subject
{
batch_sync
{
resolve_user_notes_count
(
private_epic
)
}
}
it
'returns the number of notes for the issue'
do
expect
(
subject
).
to
eq
(
3
)
end
end
context
'when a user does not have permission to view notes'
do
subject
{
batch_sync
{
resolve_user_notes_count
(
private_epic
)
}
}
it
'raises an error'
do
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
end
end
end
end
end
def
resolve_user_notes_count
(
obj
)
resolve
(
described_class
,
obj:
obj
,
ctx:
{
current_user:
user
})
end
end
ee/spec/requests/api/graphql/group/epics_spec.rb
View file @
5cc540c7
...
...
@@ -191,7 +191,7 @@ RSpec.describe 'Epics through GroupQuery' do
before
do
stub_licensed_features
(
epics:
true
)
post_graphql
(
query
)
post_graphql
(
query
,
current_user:
user
)
end
it_behaves_like
'a working graphql query'
...
...
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