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
9a21b605
Commit
9a21b605
authored
Nov 19, 2019
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support sort WEIGHT_ASC / WEIGHT_DESC for issues
in GraphQL
parent
10ffefb9
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
197 additions
and
0 deletions
+197
-0
app/graphql/types/issue_sort_enum.rb
app/graphql/types/issue_sort_enum.rb
+2
-0
changelogs/unreleased/29713-graphql-add-issue-weight-sorting.yml
...ogs/unreleased/29713-graphql-add-issue-weight-sorting.yml
+5
-0
doc/api/graphql/reference/gitlab_schema.graphql
doc/api/graphql/reference/gitlab_schema.graphql
+10
-0
doc/api/graphql/reference/gitlab_schema.json
doc/api/graphql/reference/gitlab_schema.json
+12
-0
ee/app/graphql/ee/types/issue_sort_enum.rb
ee/app/graphql/ee/types/issue_sort_enum.rb
+14
-0
ee/spec/graphql/ee/resolvers/issues_resolver_spec.rb
ee/spec/graphql/ee/resolvers/issues_resolver_spec.rb
+39
-0
ee/spec/graphql/ee/types/issue_sort_enum_spec.rb
ee/spec/graphql/ee/types/issue_sort_enum_spec.rb
+13
-0
ee/spec/requests/api/graphql/project/issues_spec.rb
ee/spec/requests/api/graphql/project/issues_spec.rb
+102
-0
No files found.
app/graphql/types/issue_sort_enum.rb
View file @
9a21b605
...
...
@@ -12,3 +12,5 @@ module Types
end
# rubocop: enable Graphql/AuthorizeTypes
end
Types
::
IssueSortEnum
.
prepend_if_ee
(
'::EE::Types::IssueSortEnum'
)
changelogs/unreleased/29713-graphql-add-issue-weight-sorting.yml
0 → 100644
View file @
9a21b605
---
title
:
Graphql query for issues can now be sorted by weight
merge_request
:
19721
author
:
type
:
added
doc/api/graphql/reference/gitlab_schema.graphql
View file @
9a21b605
...
...
@@ -2537,6 +2537,16 @@ enum IssueSort {
"""
RELATIVE_POSITION_ASC
"""
Weight
by
ascending
order
"""
WEIGHT_ASC
"""
Weight
by
descending
order
"""
WEIGHT_DESC
"""
Created
at
ascending
order
"""
...
...
doc/api/graphql/reference/gitlab_schema.json
View file @
9a21b605
...
...
@@ -13772,6 +13772,18 @@
"description"
:
"Relative position by ascending order"
,
"isDeprecated"
:
false
,
"deprecationReason"
:
null
},
{
"name"
:
"WEIGHT_ASC"
,
"description"
:
"Weight by ascending order"
,
"isDeprecated"
:
false
,
"deprecationReason"
:
null
},
{
"name"
:
"WEIGHT_DESC"
,
"description"
:
"Weight by descending order"
,
"isDeprecated"
:
false
,
"deprecationReason"
:
null
}
],
"possibleTypes"
:
null
...
...
ee/app/graphql/ee/types/issue_sort_enum.rb
0 → 100644
View file @
9a21b605
# frozen_string_literal: true
module
EE
module
Types
module
IssueSortEnum
extend
ActiveSupport
::
Concern
prepended
do
value
'WEIGHT_ASC'
,
'Weight by ascending order'
,
value:
'weight_asc'
value
'WEIGHT_DESC'
,
'Weight by descending order'
,
value:
'weight_desc'
end
end
end
end
ee/spec/graphql/ee/resolvers/issues_resolver_spec.rb
0 → 100644
View file @
9a21b605
# frozen_string_literal: true
require
'spec_helper'
describe
Resolvers
::
IssuesResolver
do
include
GraphqlHelpers
let_it_be
(
:current_user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
context
"with a project"
do
describe
'#resolve'
do
describe
'sorting'
do
context
'when sorting by weight'
do
let!
(
:weight_issue1
)
{
create
(
:issue
,
project:
project
,
weight:
5
)
}
let!
(
:weight_issue2
)
{
create
(
:issue
,
project:
project
,
weight:
nil
)
}
let!
(
:weight_issue3
)
{
create
(
:issue
,
project:
project
,
weight:
1
)
}
let!
(
:weight_issue4
)
{
create
(
:issue
,
project:
project
,
weight:
nil
)
}
before
do
project
.
add_developer
(
current_user
)
end
it
'sorts issues ascending'
do
expect
(
resolve_issues
(
sort: :weight_asc
)).
to
eq
[
weight_issue3
,
weight_issue1
,
weight_issue4
,
weight_issue2
]
end
it
'sorts issues descending'
do
expect
(
resolve_issues
(
sort: :weight_desc
)).
to
eq
[
weight_issue1
,
weight_issue3
,
weight_issue4
,
weight_issue2
]
end
end
end
end
end
def
resolve_issues
(
args
=
{},
context
=
{
current_user:
current_user
})
resolve
(
described_class
,
obj:
project
,
args:
args
,
ctx:
context
)
end
end
ee/spec/graphql/ee/types/issue_sort_enum_spec.rb
0 → 100644
View file @
9a21b605
# frozen_string_literal: true
require
'spec_helper'
describe
GitlabSchema
.
types
[
'IssueSort'
]
do
it
{
expect
(
described_class
.
graphql_name
).
to
eq
(
'IssueSort'
)
}
it_behaves_like
'common sort values'
it
'exposes all the existing EE issue sort values'
do
expect
(
described_class
.
values
.
keys
).
to
include
(
*
%w[WEIGHT_ASC WEIGHT_DESC]
)
end
end
ee/spec/requests/api/graphql/project/issues_spec.rb
0 → 100644
View file @
9a21b605
# frozen_string_literal: true
require
'spec_helper'
describe
'getting an issue list for a project'
do
include
GraphqlHelpers
let
(
:project
)
{
create
(
:project
,
:repository
,
:public
)
}
let
(
:current_user
)
{
create
(
:user
)
}
let
(
:issues_data
)
{
graphql_data
[
'project'
][
'issues'
][
'edges'
]
}
describe
'sorting and pagination'
do
let
(
:start_cursor
)
{
graphql_data
[
'project'
][
'issues'
][
'pageInfo'
][
'startCursor'
]
}
let
(
:end_cursor
)
{
graphql_data
[
'project'
][
'issues'
][
'pageInfo'
][
'endCursor'
]
}
context
'when sorting by weight'
do
let
(
:sort_project
)
{
create
(
:project
,
:public
)
}
let!
(
:weight_issue1
)
{
create
(
:issue
,
project:
sort_project
,
weight:
5
)
}
let!
(
:weight_issue2
)
{
create
(
:issue
,
project:
sort_project
,
weight:
nil
)
}
let!
(
:weight_issue3
)
{
create
(
:issue
,
project:
sort_project
,
weight:
1
)
}
let!
(
:weight_issue4
)
{
create
(
:issue
,
project:
sort_project
,
weight:
nil
)
}
let!
(
:weight_issue5
)
{
create
(
:issue
,
project:
sort_project
,
weight:
3
)
}
let
(
:params
)
{
'sort: WEIGHT_ASC'
}
def
query
(
issue_params
=
params
)
graphql_query_for
(
'project'
,
{
'fullPath'
=>
sort_project
.
full_path
},
<<~
ISSUES
issues(
#{
issue_params
}
) {
pageInfo {
endCursor
}
edges {
node {
iid
weight
}
}
}
ISSUES
)
end
before
do
post_graphql
(
query
,
current_user:
current_user
)
end
it_behaves_like
'a working graphql query'
context
'when ascending'
do
it
'sorts issues'
do
expect
(
grab_iids
).
to
eq
[
weight_issue3
.
iid
,
weight_issue5
.
iid
,
weight_issue1
.
iid
,
weight_issue4
.
iid
,
weight_issue2
.
iid
]
end
context
'when paginating'
do
let
(
:params
)
{
'sort: WEIGHT_ASC, first: 2'
}
it
'sorts issues'
do
expect
(
grab_iids
).
to
eq
[
weight_issue3
.
iid
,
weight_issue5
.
iid
]
cursored_query
=
query
(
"sort: WEIGHT_ASC, after:
\"
#{
end_cursor
}
\"
"
)
post_graphql
(
cursored_query
,
current_user:
current_user
)
response_data
=
JSON
.
parse
(
response
.
body
)[
'data'
][
'project'
][
'issues'
][
'edges'
]
expect
(
grab_iids
(
response_data
)).
to
eq
[
weight_issue1
.
iid
,
weight_issue4
.
iid
,
weight_issue2
.
iid
]
end
end
end
context
'when descending'
do
let
(
:params
)
{
'sort: WEIGHT_DESC'
}
it
'sorts issues'
do
expect
(
grab_iids
).
to
eq
[
weight_issue1
.
iid
,
weight_issue5
.
iid
,
weight_issue3
.
iid
,
weight_issue4
.
iid
,
weight_issue2
.
iid
]
end
context
'when paginating'
do
let
(
:params
)
{
'sort: WEIGHT_DESC, first: 2'
}
it
'sorts issues'
do
expect
(
grab_iids
).
to
eq
[
weight_issue1
.
iid
,
weight_issue5
.
iid
]
cursored_query
=
query
(
"sort: WEIGHT_DESC, after:
\"
#{
end_cursor
}
\"
"
)
post_graphql
(
cursored_query
,
current_user:
current_user
)
response_data
=
JSON
.
parse
(
response
.
body
)[
'data'
][
'project'
][
'issues'
][
'edges'
]
expect
(
grab_iids
(
response_data
)).
to
eq
[
weight_issue3
.
iid
,
weight_issue4
.
iid
,
weight_issue2
.
iid
]
end
end
end
end
end
def
grab_iids
(
data
=
issues_data
)
data
.
map
do
|
issue
|
issue
.
dig
(
'node'
,
'iid'
).
to_i
end
end
end
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