Commit 2a300991 authored by Florie Guibert's avatar Florie Guibert

Expose hasParent on epic

Expose hasParent on epic
Refactor epic graphQL queries for roadmap
Backend for multi level epic hierarchy on roadmaps
parent bfe74afe
...@@ -2119,6 +2119,11 @@ type Epic implements Noteable { ...@@ -2119,6 +2119,11 @@ type Epic implements Noteable {
""" """
hasIssues: Boolean! hasIssues: Boolean!
"""
Indicates if the epic has a parent epic
"""
hasParent: Boolean!
""" """
Current health status of the epic Current health status of the epic
""" """
......
...@@ -6224,6 +6224,24 @@ ...@@ -6224,6 +6224,24 @@
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
}, },
{
"name": "hasParent",
"description": "Indicates if the epic has a parent epic",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "healthStatus", "name": "healthStatus",
"description": "Current health status of the epic", "description": "Current health status of the epic",
......
...@@ -349,6 +349,7 @@ Represents an epic. ...@@ -349,6 +349,7 @@ Represents an epic.
| `group` | Group! | Group to which the epic belongs | | `group` | Group! | Group to which the epic belongs |
| `hasChildren` | Boolean! | Indicates if the epic has children | | `hasChildren` | Boolean! | Indicates if the epic has children |
| `hasIssues` | Boolean! | Indicates if the epic has direct issues | | `hasIssues` | Boolean! | Indicates if the epic has direct issues |
| `hasParent` | Boolean! | Indicates if the epic has a parent epic |
| `healthStatus` | EpicHealthStatus | Current health status of the epic | | `healthStatus` | EpicHealthStatus | Current health status of the epic |
| `id` | ID! | ID of the epic | | `id` | ID! | ID of the epic |
| `iid` | ID! | Internal ID of the epic | | `iid` | ID! | Internal ID of the epic |
......
fragment BaseEpic on Epic {
id
iid
title
description
state
webUrl
startDate
dueDate
hasChildren
descendantCounts {
openedEpics
closedEpics
openedIssues
closedIssues
}
group {
name
fullName
}
}
fragment EpicNode on Epic {
...BaseEpic
state
reference(full: true)
createdAt
closedAt
relationPath
createdAt
hasChildren
hasIssues
group {
fullPath
}
}
#import "./epic.fragment.graphql"
query epicChildEpics( query epicChildEpics(
$fullPath: ID! $fullPath: ID!
$iid: ID! $iid: ID!
...@@ -12,6 +14,7 @@ query epicChildEpics( ...@@ -12,6 +14,7 @@ query epicChildEpics(
epic(iid: $iid) { epic(iid: $iid) {
id id
title title
hasChildren
children(state: $state, sort: $sort, startDate: $startDate, endDate: $dueDate) { children(state: $state, sort: $sort, startDate: $startDate, endDate: $dueDate) {
edges { edges {
node { node {
...@@ -22,6 +25,7 @@ query epicChildEpics( ...@@ -22,6 +25,7 @@ query epicChildEpics(
webUrl webUrl
startDate startDate
dueDate dueDate
hasChildren
descendantWeightSum { descendantWeightSum {
closedIssues closedIssues
openedIssues openedIssues
...@@ -33,21 +37,7 @@ query epicChildEpics( ...@@ -33,21 +37,7 @@ query epicChildEpics(
children { children {
edges { edges {
node { node {
id ...EpicNode
title
description
state
webUrl
startDate
dueDate
descendantWeightSum {
closedIssues
openedIssues
}
group {
name
fullName
}
} }
} }
} }
......
#import "./epic.fragment.graphql"
query groupEpics( query groupEpics(
$fullPath: ID! $fullPath: ID!
$state: EpicState $state: EpicState
...@@ -22,39 +24,11 @@ query groupEpics( ...@@ -22,39 +24,11 @@ query groupEpics(
) { ) {
edges { edges {
node { node {
id ...BaseEpic
title
description
state
webUrl
startDate
dueDate
descendantWeightSum {
closedIssues
openedIssues
}
group {
name
fullName
}
children { children {
edges { edges {
node { node {
id ...EpicNode
title
description
state
webUrl
startDate
dueDate
descendantWeightSum {
closedIssues
openedIssues
}
group {
name
fullName
}
} }
} }
} }
......
...@@ -84,6 +84,9 @@ module Types ...@@ -84,6 +84,9 @@ module Types
description: 'Indicates if the epic has children' description: 'Indicates if the epic has children'
field :has_issues, GraphQL::BOOLEAN_TYPE, null: false, field :has_issues, GraphQL::BOOLEAN_TYPE, null: false,
description: 'Indicates if the epic has direct issues' description: 'Indicates if the epic has direct issues'
field :has_parent, GraphQL::BOOLEAN_TYPE, null: false,
method: :has_parent?,
description: 'Indicates if the epic has a parent epic'
field :web_path, GraphQL::STRING_TYPE, null: false, field :web_path, GraphQL::STRING_TYPE, null: false,
description: 'Web path of the epic', description: 'Web path of the epic',
......
...@@ -322,6 +322,10 @@ module EE ...@@ -322,6 +322,10 @@ module EE
issues.any? issues.any?
end end
def has_parent?
!!parent_id
end
def child?(id) def child?(id)
children.where(id: id).exists? children.where(id: id).exists?
end end
......
---
title: Expose hasParent GraphQL field on epic
merge_request: 29214
author:
type: added
...@@ -8,7 +8,7 @@ describe GitlabSchema.types['Epic'] do ...@@ -8,7 +8,7 @@ describe GitlabSchema.types['Epic'] do
id iid title description confidential state group parent author labels id iid title description confidential state group parent author labels
start_date start_date_is_fixed start_date_fixed start_date_from_milestones start_date start_date_is_fixed start_date_fixed start_date_from_milestones
due_date due_date_is_fixed due_date_fixed due_date_from_milestones due_date due_date_is_fixed due_date_fixed due_date_from_milestones
closed_at created_at updated_at children has_children has_issues closed_at created_at updated_at children has_children has_issues has_parent
web_path web_url relation_path reference issues user_permissions web_path web_url relation_path reference issues user_permissions
notes discussions relative_position subscribed participants notes discussions relative_position subscribed participants
descendant_counts descendant_weight_sum upvotes downvotes health_status descendant_counts descendant_weight_sum upvotes downvotes health_status
......
...@@ -551,6 +551,20 @@ describe Epic do ...@@ -551,6 +551,20 @@ describe Epic do
end end
end end
describe '#has_parent?' do
let_it_be(:epic, reload: true) { create(:epic, group: group) }
it 'has no parent' do
expect(epic.has_parent?).to be_falsey
end
it 'has parent' do
create(:epic, group: group, children: [epic])
expect(epic.has_parent?).to be_truthy
end
end
context 'mentioning other objects' do context 'mentioning other objects' do
let(:epic) { create(:epic, group: group) } let(:epic) { create(:epic, group: group) }
......
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