Commit 25613d74 authored by Felipe Artur's avatar Felipe Artur

Allow to query discussion design on GraphQL

Expose noteable on GraphQL discussion.

Changelog: added
parent 876ce160
# frozen_string_literal: true
module Types
class NoteableUnion < BaseUnion
graphql_name 'NoteableUnion'
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::NoteableUnion, 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
......@@ -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)
......
......@@ -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