Hierarchy widget - preload children when requesting hierarchy widget for multiple work items

When we support fetching of multiple work items (#363299 (closed)), it would be good to make sure that we eliminate any N+1 issues when loading widget data. For hierarchy widget, we should be able to preload both parent and children for any issues being fetched.


Proposal

Preload required associations in WorkItemsResolver and include the children field in work_items_spec.rb.

Example query:

query {
  project(fullPath: "flightjs/flight") {
    workItems(types: ISSUE) {
      nodes {
        widgets {
        ... on WorkItemWidgetHierarchy {
              parent { id }
              children { nodes { id } }
            }
          }
        }
      }
    }
  }
}

N+1 queries:

 SELECT "issues".* FROM "issues"...
       -- (expected: 0, got: 1)
          INNER JOIN "work_item_parent_links" ON "issues"."id" = "work_item_parent_links"."work_item_id" WHERE "work_item_parent_links"."work_item_parent_id" = 91 ORDER BY "issues"."id" DESC LIMIT 101
       -- (expected: 0, got: 1)
          INNER JOIN "work_item_parent_links" ON "issues"."id" = "work_item_parent_links"."work_item_id" WHERE "work_item_parent_links"."work_item_parent_id" = 90 ORDER BY "issues"."id" DESC LIMIT 101
       -- (expected: 0, got: 1)
          INNER JOIN "work_item_parent_links" ON "issues"."id" = "work_item_parent_links"."work_item_id" WHERE "work_item_parent_links"."work_item_parent_id" = 89 ORDER BY "issues"."id" DESC LIMIT 101
Edited by Eugenia Grieff