Skip to content

Linked Items BE: Add support for querying linked items using GraphQL

In order to query the items linked to a work item using GraphQL we need to add the following functionality:

  • New feature flag linked_work_items scoped to project and group
  • DB migration for a new widget definition named `linked_items'
  • Add the new widget to WidgetInterface including the following fields:
    • blocked - A boolean, indicates the work item is blocked
    • blockingCount - Count of items the work item is blocking
    • blockedByCount - Count of items blocking the work item
    • linkedItems - a collection of LinkedItemType
  • Each object of linkedItems should represent a linked item with the following fields:
    • linkId - Global id of the RelatedWorkItemLink record
    • linkType - The type of link (can be related_to, blocks or is_blocked_by)
    • linkCreatedAt - Timestamps for RelatedWorkItemLink record
    • linkUpdatedAt
    • workItem- The linked work item (should be a Types::WorkItemType to be able to query its fields)
  • The new query must return authenticated objects and avoid N+1s when fetching multiple items with their fields

See discussions #378059 (comment 1447716729) for more context.

Example query
query getWorkItemLinks {
  workItem(id: "gid://gitlab/WorkItem/1"){
    widgets {
      ... on WorkItemWidgetLinkedItems {
        blocked
        blockedByCount
        blockingCount
        linkedItems {
          edges {
            node {
              linkId
              linkType
	      linkCreatedAt
              linkUpdatedAt
              workItem {
                id
              }
            }
          }
        }
      }
    }
  }
}
Example response
{
  "data": {
    "workItem": {
      "widgets": [
        {
          "blocked": true,
          "blockedByCount": 1,
          "blockingCount": 1,
          "linkedItems": {
            "edges": [
              {
                "node": {
                  "linkId": 45,
                  "linkType": "is_blocked_by",
                  "linkCreatedAt": "2023-06-20T20:42:56Z",
                  "linkUpdatedAt": "2023-06-20T20:42:56Z",
                  "workItem": {
                    "id": "gid://gitlab/WorkItem/1832"
                  }
                }
              },
              {
                "node": {
                  "linkId": 46,
                  "linkType": "relates_to",
                  "linkCreatedAt": "2023-06-20T20:42:57Z",
                  "linkUpdatedAt": "2023-06-20T20:42:57Z",
                  "workItem": {
                    "id": "gid://gitlab/WorkItem/1833"
                  }
                }
              },
              {
                "node": {
                  "linkId": 47,
                  "linkType": "blocks",
                  "linkCreatedAt": "2023-06-21T08:54:40Z",
                  "linkUpdatedAt": "2023-06-21T08:54:40Z",
                  "workItem": {
                    "id": "gid://gitlab/WorkItem/1831"
                  }
                }
              }
            ]
          }
        }
      ]
    }
  }
}

See PoC implementation as an example: !124328 (32e02633)

Edited by Eugenia Grieff