GraphQL: Implement not arg in BulkLabelsResolver Label Filtering
What does this MR do and why?
This mr introduces the :not
argument in the BulkLabelsResolver. It now supports both exact string matches and wildcard-end-of-string patterns ('*') for label exclusion. Labels matching the specified patterns in the :not
array are effectively filtered out from the results. Changelog: added
This enhancement is particularly useful in scenarios where labels are dynamically generated or follow a certain naming convention (like group:*). By allowing exclusions, we can reduce clutter in the query results and present only the labels that are of interest to the user, thereby improving the overall api experience.
Performance Considerations
The negated argument should not affect performance as the labels are filtered based on exclusion criteria before being loaded by BatchLoader.
Testing
I couldn't find a specific spec for BulkLabelResolver, so I've created bulk_labels_resolver_spec.rb, let me know if there's a better place to put those tests.
How to set up and validate locally
- Set up MR
4
inflightjs/Flight
with labels for testing, those can beHighlander
and a fewgroup:*
labels. - Use the fallowing query to call the API:
query MyQuery {
project(fullPath: "flightjs/Flight") {
id
name
mergeRequest(iid: "4") {
id
labels(first: 10, not: ["group*", "Highlander"]) {
nodes {
title
description
lockOnMerge
}
}
}
}
}
The response should exclude the negated labels:
Query Response
{
"data": {
"project": {
"id": "gid://gitlab/Project/7",
"name": "Flight",
"mergeRequest": {
"id": "gid://gitlab/MergeRequest/33",
"labels": {
"nodes": [
{
"title": "4Runner",
"description": null,
"lockOnMerge": false
},
{
"title": "Aquanix",
"description": null,
"lockOnMerge": false
},
{
"title": "Aquasche",
"description": null,
"lockOnMerge": false
},
{
"title": "Technix",
"description": null,
"lockOnMerge": false
},
{
"title": "Villager",
"description": null,
"lockOnMerge": false
}
]
}
}
}
}
}
Signed-off-by: Lucas Zampieri lzampier@redhat.com