Commit 71400cff authored by charlie ablett's avatar charlie ablett

Merge branch '38296-graphql-add-milestone_due_asc-sort-for-issuables' into 'master'

GraphQL: Add 'milestone_due_asc' sort for Issuables

See merge request gitlab-org/gitlab!29992
parents fb9d90f2 d504b0c9
......@@ -52,7 +52,9 @@ module Resolvers
type Types::IssueType, null: true
NON_STABLE_CURSOR_SORTS = %i[priority_asc priority_desc label_priority_asc label_priority_desc].freeze
NON_STABLE_CURSOR_SORTS = %i[priority_asc priority_desc
label_priority_asc label_priority_desc
milestone_due_asc milestone_due_desc].freeze
def resolve(**args)
# The project could have been loaded in batch by `BatchLoader`.
......
......@@ -9,5 +9,7 @@ module Types
value 'PRIORITY_DESC', 'Priority by descending order', value: :priority_desc
value 'LABEL_PRIORITY_ASC', 'Label priority by ascending order', value: :label_priority_asc
value 'LABEL_PRIORITY_DESC', 'Label priority by descending order', value: :label_priority_desc
value 'MILESTONE_DUE_ASC', 'Milestone due date by ascending order', value: :milestone_due_asc
value 'MILESTONE_DUE_DESC', 'Milestone due date by descending order', value: :milestone_due_desc
end
end
---
title: GraphQL issue queries can now be sorted by milestone due date
merge_request: 29992
author:
type: added
......@@ -4677,6 +4677,16 @@ enum IssueSort {
"""
LABEL_PRIORITY_DESC
"""
Milestone due date by ascending order
"""
MILESTONE_DUE_ASC
"""
Milestone due date by descending order
"""
MILESTONE_DUE_DESC
"""
Priority by ascending order
"""
......
......@@ -13272,6 +13272,18 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "MILESTONE_DUE_ASC",
"description": "Milestone due date by ascending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "MILESTONE_DUE_DESC",
"description": "Milestone due date by descending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "DUE_DATE_ASC",
"description": "Due date by ascending order",
......
......@@ -190,6 +190,23 @@ describe Resolvers::IssuesResolver do
expect(resolve_issues(sort: :label_priority_desc).items).to eq([label_issue2, label_issue3, label_issue1, label_issue4])
end
end
context 'when sorting by milestone due date' do
let_it_be(:project) { create(:project) }
let_it_be(:early_milestone) { create(:milestone, project: project, due_date: 10.days.from_now) }
let_it_be(:late_milestone) { create(:milestone, project: project, due_date: 30.days.from_now) }
let_it_be(:milestone_issue1) { create(:issue, project: project) }
let_it_be(:milestone_issue2) { create(:issue, project: project, milestone: early_milestone) }
let_it_be(:milestone_issue3) { create(:issue, project: project, milestone: late_milestone) }
it 'sorts issues ascending' do
expect(resolve_issues(sort: :milestone_due_asc).items).to eq([milestone_issue2, milestone_issue3, milestone_issue1])
end
it 'sorts issues descending' do
expect(resolve_issues(sort: :milestone_due_desc).items).to eq([milestone_issue3, milestone_issue2, milestone_issue1])
end
end
end
it 'returns issues user can see' do
......
......@@ -6,6 +6,10 @@ describe Types::IssuableSortEnum do
it { expect(described_class.graphql_name).to eq('IssuableSort') }
it 'exposes all the existing issuable sort values' do
expect(described_class.values.keys).to include(*%w[PRIORITY_ASC PRIORITY_DESC])
expect(described_class.values.keys).to include(
*%w[PRIORITY_ASC PRIORITY_DESC
LABEL_PRIORITY_ASC LABEL_PRIORITY_DESC
MILESTONE_DUE_ASC MILESTONE_DUE_DESC]
)
end
end
......@@ -9,7 +9,7 @@ describe GitlabSchema.types['IssueSort'] do
it 'exposes all the existing issue sort values' do
expect(described_class.values.keys).to include(
*%w[DUE_DATE_ASC DUE_DATE_DESC RELATIVE_POSITION_ASC LABEL_PRIORITY_ASC LABEL_PRIORITY_DESC]
*%w[DUE_DATE_ASC DUE_DATE_DESC RELATIVE_POSITION_ASC]
)
end
end
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