Commit 78824581 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch...

Merge branch '293843-expand-filtering-functionality-of-vulnerabilities-graphql-endpoint-scanner-gid' into 'master'

Take scanner ID as Global ID type

See merge request gitlab-org/gitlab!59305
parents 1d034644 f733e9f1
......@@ -397,7 +397,7 @@ Returns [`VulnerabilityConnection`](#vulnerabilityconnection).
| `projectId` | [`[ID!]`](#id) | Filter vulnerabilities by project. |
| `reportType` | [`[VulnerabilityReportType!]`](#vulnerabilityreporttype) | Filter vulnerabilities by report type. |
| `scanner` | [`[String!]`](#string) | Filter vulnerabilities by VulnerabilityScanner.externalId. |
| `scannerId` | [`[Int!]`](#int) | Filter vulnerabilities by scanner ID. |
| `scannerId` | [`[VulnerabilitiesScannerID!]`](#vulnerabilitiesscannerid) | Filter vulnerabilities by scanner ID. |
| `severity` | [`[VulnerabilitySeverity!]`](#vulnerabilityseverity) | Filter vulnerabilities by severity. |
| `sort` | [`VulnerabilitySort`](#vulnerabilitysort) | List vulnerabilities by sort order. |
| `state` | [`[VulnerabilityState!]`](#vulnerabilitystate) | Filter vulnerabilities by state. |
......@@ -9156,6 +9156,12 @@ A `VulnerabilitiesExternalIssueLinkID` is a global ID. It is encoded as a string
An example `VulnerabilitiesExternalIssueLinkID` is: `"gid://gitlab/Vulnerabilities::ExternalIssueLink/1"`.
### `VulnerabilitiesScannerID`
A `VulnerabilitiesScannerID` is a global ID. It is encoded as a string.
An example `VulnerabilitiesScannerID` is: `"gid://gitlab/Vulnerabilities::Scanner/1"`.
### `VulnerabilityID`
A `VulnerabilityID` is a global ID. It is encoded as a string.
......
......@@ -8,7 +8,7 @@ query instance(
$severity: [VulnerabilitySeverity!]
$reportType: [VulnerabilityReportType!]
$scanner: [String!]
$scannerId: [Int!]
$scannerId: [ID!]
$state: [VulnerabilityState!]
$sort: VulnerabilitySort
$hasIssues: Boolean
......
......@@ -26,7 +26,7 @@ module Resolvers
required: false,
description: 'Filter vulnerabilities by VulnerabilityScanner.externalId.'
argument :scanner_id, [GraphQL::INT_TYPE],
argument :scanner_id, [::Types::GlobalIDType[::Vulnerabilities::Scanner]],
required: false,
description: 'Filter vulnerabilities by scanner ID.'
......@@ -46,6 +46,8 @@ module Resolvers
def resolve(**args)
return Vulnerability.none unless vulnerable
args[:scanner_id] = resolve_gids(args[:scanner_id], ::Vulnerabilities::Scanner) if args[:scanner_id]
vulnerabilities(args)
.with_findings_scanner_and_identifiers
.with_created_issue_links_and_issues
......@@ -53,6 +55,12 @@ module Resolvers
private
def resolve_gids(gids, gid_class)
gids.map do |gid|
Types::GlobalIDType[gid_class].coerce_isolated_input(gid).model_id
end
end
def vulnerabilities(params)
Security::VulnerabilitiesFinder.new(vulnerable, params).execute
end
......
---
title: Change vulnerabilities GraphQL query to use GlobalID for scanner IDs
merge_request: 59305
author:
type: changed
......@@ -78,7 +78,7 @@ RSpec.describe Resolvers::VulnerabilitiesResolver do
end
context 'when given scanner ID' do
let(:params) { { scanner_id: [high_vulnerability.finding_scanner_id] } }
let(:params) { { scanner_id: [GitlabSchema.id_from_object(high_vulnerability.finding.scanner)] } }
it 'only returns vulnerabilities of the given scanner IDs' do
is_expected.to contain_exactly(high_vulnerability)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment