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
2b6184fd
Commit
2b6184fd
authored
Oct 03, 2019
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sort graphql issues by due_date
and add new IssueSortEnum values
parent
ddf7a00d
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
171 additions
and
5 deletions
+171
-5
app/graphql/types/issue_sort_enum.rb
app/graphql/types/issue_sort_enum.rb
+3
-0
app/models/issue.rb
app/models/issue.rb
+2
-2
changelogs/unreleased/63778-graphql-add-issue-due-date-sortring.yml
.../unreleased/63778-graphql-add-issue-due-date-sortring.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
spec/graphql/resolvers/issues_resolver_spec.rb
spec/graphql/resolvers/issues_resolver_spec.rb
+27
-2
spec/graphql/types/issue_sort_enum_spec.rb
spec/graphql/types/issue_sort_enum_spec.rb
+13
-0
spec/requests/api/graphql/project/issues_spec.rb
spec/requests/api/graphql/project/issues_spec.rb
+92
-1
spec/support/shared_examples/graphql/sort_enum_shared_examples.rb
...port/shared_examples/graphql/sort_enum_shared_examples.rb
+7
-0
No files found.
app/graphql/types/issue_sort_enum.rb
View file @
2b6184fd
...
...
@@ -5,6 +5,9 @@ module Types
class
IssueSortEnum
<
IssuableSortEnum
graphql_name
'IssueSort'
description
'Values for sorting issues'
value
'DUE_DATE_ASC'
,
'Due date by ascending order'
,
value:
'due_date_asc'
value
'DUE_DATE_DESC'
,
'Due date by descending order'
,
value:
'due_date_desc'
end
# rubocop: enable Graphql/AuthorizeTypes
end
app/models/issue.rb
View file @
2b6184fd
...
...
@@ -138,8 +138,8 @@ class Issue < ApplicationRecord
def
self
.
sort_by_attribute
(
method
,
excluded_labels:
[])
case
method
.
to_s
when
'closest_future_date'
,
'closest_future_date_asc'
then
order_closest_future_date
when
'due_date'
,
'due_date_asc'
then
order_due_date_asc
when
'due_date_desc'
then
order_due_date_desc
when
'due_date'
,
'due_date_asc'
then
order_due_date_asc
.
with_order_id_desc
when
'due_date_desc'
then
order_due_date_desc
.
with_order_id_desc
when
'relative_position'
,
'relative_position_asc'
then
order_relative_position_asc
.
with_order_id_desc
else
super
...
...
changelogs/unreleased/63778-graphql-add-issue-due-date-sortring.yml
0 → 100644
View file @
2b6184fd
---
title
:
'
Issues
queried
in
GraphQL
now
sortable
by
due
date'
merge_request
:
18094
author
:
type
:
added
doc/api/graphql/reference/gitlab_schema.graphql
View file @
2b6184fd
...
...
@@ -2641,6 +2641,16 @@ type IssuePermissions {
Values for sorting issues
"""
enum
IssueSort
{
"""
Due
date
by
ascending
order
"""
DUE_DATE_ASC
"""
Due
date
by
descending
order
"""
DUE_DATE_DESC
"""
Created
at
ascending
order
"""
...
...
doc/api/graphql/reference/gitlab_schema.json
View file @
2b6184fd
...
...
@@ -13353,6 +13353,18 @@
"description"
:
"Created at ascending order"
,
"isDeprecated"
:
false
,
"deprecationReason"
:
null
},
{
"name"
:
"DUE_DATE_ASC"
,
"description"
:
"Due date by ascending order"
,
"isDeprecated"
:
false
,
"deprecationReason"
:
null
},
{
"name"
:
"DUE_DATE_DESC"
,
"description"
:
"Due date by descending order"
,
"isDeprecated"
:
false
,
"deprecationReason"
:
null
}
],
"possibleTypes"
:
null
...
...
spec/graphql/resolvers/issues_resolver_spec.rb
View file @
2b6184fd
...
...
@@ -72,8 +72,33 @@ describe Resolvers::IssuesResolver do
expect
(
resolve_issues
(
search:
'foo'
)).
to
contain_exactly
(
issue2
)
end
it
'sort issues'
do
expect
(
resolve_issues
(
sort:
'created_desc'
)).
to
eq
[
issue2
,
issue1
]
describe
'sorting'
do
context
'when sorting by created'
do
it
'sorts issues ascending'
do
expect
(
resolve_issues
(
sort:
'created_asc'
)).
to
eq
[
issue1
,
issue2
]
end
it
'sorts issues descending'
do
expect
(
resolve_issues
(
sort:
'created_desc'
)).
to
eq
[
issue2
,
issue1
]
end
end
context
'when sorting by due date'
do
let
(
:project
)
{
create
(
:project
)
}
let!
(
:due_issue1
)
{
create
(
:issue
,
project:
project
,
due_date:
3
.
days
.
from_now
)
}
let!
(
:due_issue2
)
{
create
(
:issue
,
project:
project
,
due_date:
nil
)
}
let!
(
:due_issue3
)
{
create
(
:issue
,
project:
project
,
due_date:
2
.
days
.
ago
)
}
let!
(
:due_issue4
)
{
create
(
:issue
,
project:
project
,
due_date:
nil
)
}
it
'sorts issues ascending'
do
expect
(
resolve_issues
(
sort: :due_date_asc
)).
to
eq
[
due_issue3
,
due_issue1
,
due_issue4
,
due_issue2
]
end
it
'sorts issues descending'
do
expect
(
resolve_issues
(
sort: :due_date_desc
)).
to
eq
[
due_issue1
,
due_issue3
,
due_issue4
,
due_issue2
]
end
end
end
it
'returns issues user can see'
do
...
...
spec/graphql/types/issue_sort_enum_spec.rb
0 → 100644
View file @
2b6184fd
# 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 issue sort values'
do
expect
(
described_class
.
values
.
keys
).
to
include
(
*
%w[DUE_DATE_ASC DUE_DATE_DESC]
)
end
end
spec/requests/api/graphql/project/issues_spec.rb
View file @
2b6184fd
...
...
@@ -64,7 +64,7 @@ describe 'getting an issue list for a project' do
end
end
it
"is expected to check permissions on the first issue only"
do
it
'is expected to check permissions on the first issue only'
do
allow
(
Ability
).
to
receive
(
:allowed?
).
and_call_original
# Newest first, we only want to see the newest checked
expect
(
Ability
).
not_to
receive
(
:allowed?
).
with
(
current_user
,
:read_issue
,
issues
.
first
)
...
...
@@ -116,4 +116,95 @@ describe 'getting an issue list for a project' do
end
end
end
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 due date'
do
let
(
:sort_project
)
{
create
(
:project
,
:public
)
}
let!
(
:due_issue1
)
{
create
(
:issue
,
project:
sort_project
,
due_date:
3
.
days
.
from_now
)
}
let!
(
:due_issue2
)
{
create
(
:issue
,
project:
sort_project
,
due_date:
nil
)
}
let!
(
:due_issue3
)
{
create
(
:issue
,
project:
sort_project
,
due_date:
2
.
days
.
ago
)
}
let!
(
:due_issue4
)
{
create
(
:issue
,
project:
sort_project
,
due_date:
nil
)
}
let!
(
:due_issue5
)
{
create
(
:issue
,
project:
sort_project
,
due_date:
1
.
day
.
ago
)
}
let
(
:params
)
{
'sort: DUE_DATE_ASC'
}
def
query
(
issue_params
=
params
)
graphql_query_for
(
'project'
,
{
'fullPath'
=>
sort_project
.
full_path
},
<<~
ISSUES
issues(
#{
issue_params
}
) {
pageInfo {
endCursor
}
edges {
node {
iid
dueDate
}
}
}
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
[
due_issue3
.
iid
,
due_issue5
.
iid
,
due_issue1
.
iid
,
due_issue4
.
iid
,
due_issue2
.
iid
]
end
context
'when paginating'
do
let
(
:params
)
{
'sort: DUE_DATE_ASC, first: 2'
}
it
'sorts issues'
do
expect
(
grab_iids
).
to
eq
[
due_issue3
.
iid
,
due_issue5
.
iid
]
cursored_query
=
query
(
"sort: DUE_DATE_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
[
due_issue1
.
iid
,
due_issue4
.
iid
,
due_issue2
.
iid
]
end
end
end
context
'when descending'
do
let
(
:params
)
{
'sort: DUE_DATE_DESC'
}
it
'sorts issues'
do
expect
(
grab_iids
).
to
eq
[
due_issue1
.
iid
,
due_issue5
.
iid
,
due_issue3
.
iid
,
due_issue4
.
iid
,
due_issue2
.
iid
]
end
context
'when paginating'
do
let
(
:params
)
{
'sort: DUE_DATE_DESC, first: 2'
}
it
'sorts issues'
do
expect
(
grab_iids
).
to
eq
[
due_issue1
.
iid
,
due_issue5
.
iid
]
cursored_query
=
query
(
"sort: DUE_DATE_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
[
due_issue3
.
iid
,
due_issue4
.
iid
,
due_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
spec/support/shared_examples/graphql/sort_enum_shared_examples.rb
0 → 100644
View file @
2b6184fd
# frozen_string_literal: true
RSpec
.
shared_examples
'common sort values'
do
it
'exposes all the existing common sort values'
do
expect
(
described_class
.
values
.
keys
).
to
include
(
*
%w[updated_desc updated_asc created_desc created_asc]
)
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