Unioned custom field filters

What does this MR do and why?

This change adds support for "OR" filtering on custom fields in GitLab's GraphQL API. Previously, users could only filter work items (like issues and epics) by custom fields using "AND" logic - meaning items had to match all specified criteria. Now they can also use "OR" logic to find items that match any of the specified custom field values.

The update adds a new custom_field filter option to several GraphQL input types for issues, work items, and epics. This filter is marked as experimental and introduced in GitLab version 18.4. The underlying filtering logic was enhanced to handle three types of operations: include (match all), exclude (match none), and the new or_include (match any).

The changes include comprehensive test coverage to ensure the OR filtering works correctly across different scenarios - from simple single-option filters to complex multi-option combinations. The feature maintains backward compatibility while providing users more flexible ways to search and filter their work items based on custom field values.

Database

Prepare the values
INSERT INTO work_item_select_field_values
  (namespace_id, work_item_id, custom_field_id, custom_field_select_option_id, created_at, updated_at)
SELECT
  9970,
  id,
  1000062,
  (ARRAY[1000139, 1000140, 1000141, 1000142, 1000143])[floor(random() * 5 + 1)::int],
  NOW(),
  NOW()
FROM issues
WHERE project_id = 278964
LIMIT 1000;

Query to fetch the work items: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/42670/commands/130498

References

#515952

#561486

How to set up and validate locally

An example of a graphQL query to filter by or:

query getIssuesEE($fullPath: ID!, $iid: String, $sort: IssueSort, $state: IssuableState, $types: [IssueType!], $or: UnionedIssueFilterInput) {
  project(fullPath: $fullPath) {
    id
    issues(
      iid: $iid
      sort: $sort
      state: $state
      types: $types
      or: $or
    ) {
      pageInfo {
        ...PageInfo
        __typename
      }
      nodes {
      	id
        iid
      }
    }
    __typename
  }
}

Variables

{
  "fullPath": "flightjs/another_flight",
  "sort": "CREATED_DESC",
  "state": "opened",
  "or": {
      "customField":[
  		{
    		"customFieldId": "gid://gitlab/Issuables::CustomField/11",
    		"selectedOptionIds": [
      		"gid://gitlab/Issuables::CustomFieldSelectOption/6",
          "gid://gitlab/Issuables::CustomFieldSelectOption/7"

    		]
  		}
		]
  },
  "types": [
    "ISSUE",
    "INCIDENT",
    "TASK",
    "KEY_RESULT",
    "OBJECTIVE",
    "TEST_CASE"
  ]
}

MR acceptance checklist

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

Edited by Stefanos Xanthopoulos

Merge request reports

Loading