Commit 8ddd7787 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'issue_227691-allow_to_query_discussion_noteable' into 'master'

Allow to query discussion design on GraphQL

See merge request gitlab-org/gitlab!64550
parents 52ea95bb 318a49b4
......@@ -8,7 +8,7 @@ module Types
present_using ::AlertManagement::AlertPresenter
implements(Types::Notes::NoteableType)
implements(Types::Notes::NoteableInterface)
authorize :read_alert_management_alert
......
......@@ -10,7 +10,7 @@ module Types
alias_method :design, :object
implements(Types::Notes::NoteableType)
implements(Types::Notes::NoteableInterface)
implements(Types::DesignManagement::DesignFields)
implements(Types::CurrentUserTodos)
......
......@@ -6,7 +6,7 @@ module Types
connection_type_class(Types::IssueConnectionType)
implements(Types::Notes::NoteableType)
implements(Types::Notes::NoteableInterface)
implements(Types::CurrentUserTodos)
authorize :read_issue
......
......@@ -6,7 +6,7 @@ module Types
connection_type_class(Types::MergeRequestConnectionType)
implements(Types::Notes::NoteableType)
implements(Types::Notes::NoteableInterface)
implements(Types::CurrentUserTodos)
authorize :read_merge_request
......
# frozen_string_literal: true
module Types
class NoteableType < BaseUnion
graphql_name 'NoteableType'
description 'Represents an object that supports notes.'
possible_types Types::IssueType, Types::DesignManagement::DesignType, Types::MergeRequestType
def self.resolve_type(object, context)
case object
when Issue
Types::IssueType
when ::DesignManagement::Design
Types::DesignManagement::DesignType
when MergeRequest
Types::MergeRequestType
else
raise 'Unsupported issuable type'
end
end
end
end
......@@ -19,6 +19,8 @@ module Types
description: "Timestamp of the discussion's creation."
field :notes, Types::Notes::NoteType.connection_type, null: false,
description: 'All notes in the discussion.'
field :noteable, Types::NoteableType, null: true,
description: 'Object which the discussion belongs to.'
# DiscussionID.coerce_result is suitable here, but will always mark this
# as being a 'Discussion'. Using `GlobalId.build` guarantees that we get
......@@ -26,6 +28,14 @@ module Types
def reply_id
::Gitlab::GlobalId.build(object, id: object.reply_id)
end
def noteable
noteable = object.noteable
return unless Ability.allowed?(context[:current_user], :"read_#{noteable.to_ability_name}", noteable)
noteable
end
end
end
end
......@@ -2,7 +2,7 @@
module Types
module Notes
module NoteableType
module NoteableInterface
include Types::BaseInterface
field :notes, Types::Notes::NoteType.connection_type, null: false, description: "All notes on this noteable."
......@@ -28,4 +28,4 @@ module Types
end
end
Types::Notes::NoteableType.prepend_mod_with('Types::Notes::NoteableType')
Types::Notes::NoteableInterface.prepend_mod_with('Types::Notes::NoteableInterface')
......@@ -5,7 +5,7 @@ module Types
graphql_name 'Snippet'
description 'Represents a snippet entry'
implements(Types::Notes::NoteableType)
implements(Types::Notes::NoteableInterface)
present_using SnippetPresenter
......
......@@ -8582,6 +8582,7 @@ Aggregated summary of changes.
| ---- | ---- | ----------- |
| <a id="discussioncreatedat"></a>`createdAt` | [`Time!`](#time) | Timestamp of the discussion's creation. |
| <a id="discussionid"></a>`id` | [`DiscussionID!`](#discussionid) | ID of this discussion. |
| <a id="discussionnoteable"></a>`noteable` | [`NoteableType`](#noteabletype) | Object which the discussion belongs to. |
| <a id="discussionnotes"></a>`notes` | [`NoteConnection!`](#noteconnection) | All notes in the discussion. (see [Connections](#connections)) |
| <a id="discussionreplyid"></a>`replyId` | [`DiscussionID!`](#discussionid) | ID used to reply to this discussion. |
| <a id="discussionresolvable"></a>`resolvable` | [`Boolean!`](#boolean) | Indicates if the object can be resolved. |
......@@ -15820,6 +15821,16 @@ One of:
- [`Issue`](#issue)
- [`MergeRequest`](#mergerequest)
#### `NoteableType`
Represents an object that supports notes.
One of:
- [`Design`](#design)
- [`Issue`](#issue)
- [`MergeRequest`](#mergerequest)
#### `PackageMetadata`
Represents metadata associated with a Package.
......@@ -15988,7 +15999,7 @@ Implementations:
| <a id="memberinterfaceupdatedat"></a>`updatedAt` | [`Time`](#time) | Date and time the membership was last updated. |
| <a id="memberinterfaceuser"></a>`user` | [`UserCore`](#usercore) | User that is associated with the member object. |
#### `Noteable`
#### `NoteableInterface`
Implementations:
......@@ -16006,8 +16017,8 @@ Implementations:
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="noteablediscussions"></a>`discussions` | [`DiscussionConnection!`](#discussionconnection) | All discussions on this noteable. (see [Connections](#connections)) |
| <a id="noteablenotes"></a>`notes` | [`NoteConnection!`](#noteconnection) | All notes on this noteable. (see [Connections](#connections)) |
| <a id="noteableinterfacediscussions"></a>`discussions` | [`DiscussionConnection!`](#discussionconnection) | All discussions on this noteable. (see [Connections](#connections)) |
| <a id="noteableinterfacenotes"></a>`notes` | [`NoteConnection!`](#noteconnection) | All notes on this noteable. (see [Connections](#connections)) |
#### `PackageFileMetadata`
......
......@@ -3,7 +3,7 @@
module EE
module Types
module Notes
module NoteableType
module NoteableInterface
module ClassMethods
def resolve_type(object, *)
return ::Types::VulnerabilityType if ::Vulnerability === object
......
......@@ -13,7 +13,7 @@ module Types
present_using EpicPresenter
implements(Types::Notes::NoteableType)
implements(Types::Notes::NoteableInterface)
implements(Types::CurrentUserTodos)
implements(Types::EventableType)
......
......@@ -5,7 +5,7 @@ module Types
graphql_name 'Vulnerability'
description 'Represents a vulnerability'
implements(Types::Notes::NoteableType)
implements(Types::Notes::NoteableInterface)
authorize :read_security_resource
......
......@@ -2,8 +2,8 @@
require 'spec_helper'
RSpec.describe EE::Types::Notes::NoteableType do
let(:extended_class) { Types::Notes::NoteableType }
RSpec.describe EE::Types::Notes::NoteableInterface do
let(:extended_class) { Types::Notes::NoteableInterface }
describe ".resolve_type" do
it 'knows the correct type for objects' do
......
......@@ -9,7 +9,7 @@ RSpec.describe GitlabSchema.types['Issue'] do
specify { expect(described_class).to require_graphql_authorizations(:read_issue) }
specify { expect(described_class.interfaces).to include(Types::Notes::NoteableType) }
specify { expect(described_class.interfaces).to include(Types::Notes::NoteableInterface) }
specify { expect(described_class.interfaces).to include(Types::CurrentUserTodos) }
......
......@@ -9,7 +9,7 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do
specify { expect(described_class).to require_graphql_authorizations(:read_merge_request) }
specify { expect(described_class.interfaces).to include(Types::Notes::NoteableType) }
specify { expect(described_class.interfaces).to include(Types::Notes::NoteableInterface) }
specify { expect(described_class.interfaces).to include(Types::CurrentUserTodos) }
......
......@@ -13,6 +13,7 @@ RSpec.describe GitlabSchema.types['Discussion'] do
resolved
resolved_at
resolved_by
noteable
]
expect(described_class).to have_graphql_fields(*expected_fields)
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe Types::Notes::NoteableType do
RSpec.describe Types::Notes::NoteableInterface do
it 'exposes the expected fields' do
expected_fields = %i[
discussions
......
......@@ -31,6 +31,28 @@ RSpec.shared_examples 'a noteable graphql type we can query' do
expect(graphql_data_at(*path_to_noteable, :discussions, :nodes))
.to match_array(expected)
end
it 'can fetch discussion noteable' do
create(discussion_factory, project: project, noteable: noteable)
fields =
<<-QL.strip_heredoc
discussions {
nodes {
noteable {
__typename
... on #{noteable.class.name.demodulize} {
id
}
}
}
}
QL
post_graphql(query(fields), current_user: current_user)
data = graphql_data_at(*path_to_noteable, :discussions, :nodes, :noteable, :id)
expect(data[0]).to eq(global_id_of(noteable))
end
end
describe '.notes' 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