Commit 1c54647d authored by Mehmet Emin INAC's avatar Mehmet Emin INAC Committed by Dmytro Zaporozhets (DZ)

Add `discussions` and `notes` fields for `VulnerabilityType`

Implement `Notes::Noteable` interface in `VulnerabilityType` to add
`discussions` and `notes` fields.

To do so, we had to remove `definiton_methods` DSL method call which is
defined in the private API.
parent 54c2f0b6
......@@ -8,8 +8,7 @@ module Types
field :notes, Types::Notes::NoteType.connection_type, null: false, description: "All notes on this noteable"
field :discussions, Types::Notes::DiscussionType.connection_type, null: false, description: "All discussions on this noteable"
definition_methods do
def resolve_type(object, context)
def self.resolve_type(object, context)
case object
when Issue
Types::IssueType
......@@ -27,5 +26,6 @@ module Types
end
end
end
end
end
Types::Notes::NoteableType.prepend_if_ee('::EE::Types::Notes::NoteableType')
......@@ -18688,7 +18688,7 @@ type VulnerabilitiesCountByDayEdge {
"""
Represents a vulnerability
"""
type Vulnerability {
type Vulnerability implements Noteable {
"""
Description of the vulnerability
"""
......@@ -18699,6 +18699,31 @@ type Vulnerability {
"""
detectedAt: Time!
"""
All discussions on this noteable
"""
discussions(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String
"""
Returns the elements in the list that come before the specified cursor.
"""
before: String
"""
Returns the first _n_ elements from the list.
"""
first: Int
"""
Returns the last _n_ elements from the list.
"""
last: Int
): DiscussionConnection!
"""
GraphQL ID of the vulnerability
"""
......@@ -18744,6 +18769,31 @@ type Vulnerability {
"""
location: VulnerabilityLocation
"""
All notes on this noteable
"""
notes(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String
"""
Returns the elements in the list that come before the specified cursor.
"""
before: String
"""
Returns the first _n_ elements from the list.
"""
first: Int
"""
Returns the last _n_ elements from the list.
"""
last: Int
): NoteConnection!
"""
Primary identifier of the vulnerability.
"""
......
......@@ -33867,6 +33867,11 @@
"kind": "OBJECT",
"name": "Snippet",
"ofType": null
},
{
"kind": "OBJECT",
"name": "Vulnerability",
"ofType": null
}
]
},
......@@ -54731,6 +54736,63 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "discussions",
"description": "All discussions on this noteable",
"args": [
{
"name": "after",
"description": "Returns the elements in the list that come after the specified cursor.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "before",
"description": "Returns the elements in the list that come before the specified cursor.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "first",
"description": "Returns the first _n_ elements from the list.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
},
{
"name": "last",
"description": "Returns the last _n_ elements from the list.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
}
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "DiscussionConnection",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "id",
"description": "GraphQL ID of the vulnerability",
......@@ -54856,6 +54918,63 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "notes",
"description": "All notes on this noteable",
"args": [
{
"name": "after",
"description": "Returns the elements in the list that come after the specified cursor.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "before",
"description": "Returns the elements in the list that come before the specified cursor.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "first",
"description": "Returns the first _n_ elements from the list.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
},
{
"name": "last",
"description": "Returns the last _n_ elements from the list.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
}
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "NoteConnection",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "primaryIdentifier",
"description": "Primary identifier of the vulnerability.",
......@@ -55025,7 +55144,11 @@
],
"inputFields": null,
"interfaces": [
{
"kind": "INTERFACE",
"name": "Noteable",
"ofType": null
}
],
"enumValues": null,
"possibleTypes": null
# frozen_string_literal: true
module EE
module Types
module Notes
module NoteableType
module ClassMethods
def resolve_type(object, *)
return ::Types::VulnerabilityType if ::Vulnerability === object
super
end
end
def self.prepended(base)
base.singleton_class.prepend(ClassMethods)
end
end
end
end
end
......@@ -5,6 +5,8 @@ module Types
graphql_name 'Vulnerability'
description 'Represents a vulnerability'
implements(Types::Notes::NoteableType)
authorize :read_vulnerability
expose_permissions Types::PermissionTypes::Vulnerability
......
---
title: Add `discussions` and `notes` fields for VulnerabilityType on GraphQL API
merge_request: 42892
author:
type: added
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe EE::Types::Notes::NoteableType do
let(:extended_class) { Types::Notes::NoteableType }
describe ".resolve_type" do
it 'knows the correct type for objects' do
expect(extended_class.resolve_type(build(:issue), {})).to eq(Types::IssueType)
expect(extended_class.resolve_type(build(:merge_request), {})).to eq(Types::MergeRequestType)
expect(extended_class.resolve_type(build(:design), {})).to eq(Types::DesignManagement::DesignType)
expect(extended_class.resolve_type(build(:alert_management_alert), {})).to eq(Types::AlertManagement::AlertType)
expect(extended_class.resolve_type(build(:vulnerability), {})).to eq(Types::VulnerabilityType)
end
end
end
......@@ -23,7 +23,9 @@ RSpec.describe GitlabSchema.types['Vulnerability'] do
identifiers
project
issueLinks
detected_at]
detected_at
notes
discussions]
end
before do
......
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