Skip to content

Allow linking work items to a new work item via GraphQL

What does this MR do and why?

Related to #468222 (closed)

This MR adds the linkedItemsWidget argument to the WorkItemCreate mutation, allowing us to create a work item with other items linked to it. We previously had the option to link items to an existing work item (using the WorkItemAddLinkedItems mutation) but we also need to support this option on creation.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screen_Recording_2024-08-21_at_15.35.10

How to set up and validate locally

  1. Visit http://127.0.0.1:3000/-/graphql-explorer and use the following query to create a new work item. Take note of its ID.

    createWorkItem
    mutation createWorkItem {
      workItemCreate(input: {
        namespacePath: "flightjs/Flight", title: "Work item to link",
        workItemTypeId: "gid://gitlab/WorkItems::Type/1"
      }) {
        workItem {
          id
        }
        errors
      }
    }
  2. Use the following query to create another work item with the previous item linked to it. Verify the response includes "Work item to link" as a linked item.

    createWorkItemWithLinkedWorkItem
    mutation createWorkItemWithLinkedWorkItem {
      workItemCreate(input: {
        namespacePath: "flightjs/Flight", title: "Linked work item",
        workItemTypeId: "gid://gitlab/WorkItems::Type/1",
        linkedItemsWidget: { workItemsIds: ["gid://gitlab/WorkItem/965"] }
      }) {
        workItem {
          title
          widgets {
            ... on WorkItemWidgetLinkedItems {
              linkedItems {
                edges {
                  node {
                    workItem {
                      title
                    }
                  }
                }
              }
            }
          }
        }
        errors
      }
    }
    expected response
    {
      "data": {
        "workItemCreate": {
          "workItem": {
            "title": "Linked work item",
            "webUrl": "http://127.0.0.1:3000/flightjs/Flight/-/issues/84",
            "widgets": [
              {
                "linkedItems": {
                  "edges": [
                    {
                      "node": {
                        "workItem": {
                          "title": "Work item to link"
                        }
                      }
                    }
                  ]
                }
              }
            ]
          },
          "errors": []
        }
      }
    }
  3. Optionally, visit the URL returned by the webUrl field and verify the item is shown in the Linked items widget

Edited by Eugenia Grieff

Merge request reports