Linked Items BE: Add support for linking and unlinking items using GraphQL
In order to add and remove linked items using GraphQL we need to add the following functionality:
- Linking work items
- New service to create the links
WorkItems::RelatedWorkItemLinks::CreateServicethat inherits fromIssuableLinks::CreateServiceand accepts multiple work item records as a param. The service must authenticate items with:admin_work_item_link(equivalent toadmin_issue_link). - New fine-grained mutation
WorkItemAddLinkedItemsthat accepts the following input:-
id- global ID of the work item -
workItemsIds- array containing global IDs of the work items to be added -
linkType- the type of link, can be 'RELATED', 'BLOCKED_BY' or 'BLOCKS'
-
- This mutation must validate that the FF
linked_work_itemsis enabled before linking any items. Also, it should check that a licensed featureblocked_work_itemsis available (defined as STARTER) if the link type is 'BLOCKED_BY' or 'BLOCKS'.
Example mutation
mutation {
workItemUpdateLinkedItems(
input: {
id: "gid://gitlab/WorkItem/1830",
workItemsIds: ["gid://gitlab/WorkItem/1834", "gid://gitlab/WorkItem/1835"],
linkType: RELATED
}
) {
workItem { id }
errors
}
}
- Unlinking work items
- Similar to adding a link, we need a new
WorkItems::RelatedWorkItemLinks::DestroyServiceto support removing items. This can inherit fromIssuableLinks::DestroyServiceif we support removing one link at a time. In order to support removing multiple links at the time I opted for a different approach, see !124328 (comment 1453225643) - New fine-grained mutation
WorkItemRemoveLinkedItemsthat accepts the following input:-
id- global ID of the work item -
workItemsIds- array containing global IDs of the work items to be removed
-
Example mutation
mutation {
workItemRemoveLinkedItems(
input: {
id: "gid://gitlab/WorkItem/1830",
workItemsIds: ["gid://gitlab/WorkItem/1834", "gid://gitlab/WorkItem/1835"]
}
) {
workItem { id }
errors
}
}
Edited by Eugenia Grieff