GraphQL: Allow filtering epics by top level only
What does this MR do and why?
Adds a new argument topLevelHierarchyOnly
to the epics query that allows us to fetch top-level epics only (IOW, epics with no parent).
We are also modifying EpicsFinder
to accept the new param top_level_hierarchy_only
. This new param will be ignored if the parent_id
param is present because we shouldn't be able to request top_level_hierarchy_only
when we are trying to find children of parent_id
(the result would be empty).
These are the backend changes needed to fix #337435 (closed).
Example query
query topLevelEpics {
group(fullPath: $group_id) {
epics(topLevelHierarchyOnly: true) {
edges {
node {
title
hasParent
}
}
}
}
}
All results from this query should return "hasParent": false
.
Database impact
The finder query will include an additional condition when top_level_hierarchy_only
param is set as true
: AND "epics"."parent_id" IS NULL
.
top_level_hierarchy_only: true
With EpicsFinder.new(user, { group_id: 9970, top_level_hierarchy_only: true}).execute
SQL
SELECT
"epics".*
FROM
"epics"
WHERE
"epics"."group_id" IN (
SELECT
"namespaces"."id"
FROM
"namespaces"
WHERE
"namespaces"."type" = 'Group'
AND (traversal_ids @> ('{9970}'))
)
AND "epics"."parent_id" IS NULL
ORDER BY
"epics"."id" DESC
LIMIT
100
top_level_hierarchy_only: false
With EpicsFinder.new(user, { group_id: 9970, top_level_hierarchy_only: false}).execute
SQL
SELECT
"epics".*
FROM
"epics"
WHERE
"epics"."group_id" IN (
SELECT
"namespaces"."id"
FROM
"namespaces"
WHERE
"namespaces"."type" = 'Group'
AND (traversal_ids @> ('{9970}'))
)
ORDER BY
"epics"."id" DESC
LIMIT
100
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.