2019-06-07 17:13:26 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Types
|
|
|
|
module Notes
|
|
|
|
class DiscussionType < BaseObject
|
|
|
|
graphql_name 'Discussion'
|
|
|
|
|
2022-02-15 12:14:49 +00:00
|
|
|
DiscussionID = ::Types::GlobalIDType[::Discussion]
|
|
|
|
|
2019-06-07 17:13:26 +00:00
|
|
|
authorize :read_note
|
|
|
|
|
2020-06-01 00:08:25 +00:00
|
|
|
implements(Types::ResolvableInterface)
|
|
|
|
|
2019-12-16 00:07:33 +00:00
|
|
|
field :created_at, Types::TimeType, null: false,
|
2021-02-05 15:09:28 +00:00
|
|
|
description: "Timestamp of the discussion's creation."
|
2022-03-02 15:16:07 +00:00
|
|
|
field :id, DiscussionID, null: false,
|
|
|
|
description: "ID of this discussion."
|
2021-07-05 15:07:38 +00:00
|
|
|
field :noteable, Types::NoteableType, null: true,
|
|
|
|
description: 'Object which the discussion belongs to.'
|
2022-03-02 15:16:07 +00:00
|
|
|
field :notes, Types::Notes::NoteType.connection_type, null: false,
|
|
|
|
description: 'All notes in the discussion.'
|
|
|
|
field :reply_id, DiscussionID, null: false,
|
|
|
|
description: 'ID used to reply to this discussion.'
|
2019-07-04 03:33:14 +00:00
|
|
|
|
2021-01-20 15:10:29 +00:00
|
|
|
# DiscussionID.coerce_result is suitable here, but will always mark this
|
|
|
|
# as being a 'Discussion'. Using `GlobalId.build` guarantees that we get
|
|
|
|
# the correct class, and that it matches `id`.
|
2019-07-04 03:33:14 +00:00
|
|
|
def reply_id
|
|
|
|
::Gitlab::GlobalId.build(object, id: object.reply_id)
|
|
|
|
end
|
2021-07-05 15:07:38 +00:00
|
|
|
|
|
|
|
def noteable
|
|
|
|
noteable = object.noteable
|
|
|
|
|
|
|
|
return unless Ability.allowed?(context[:current_user], :"read_#{noteable.to_ability_name}", noteable)
|
|
|
|
|
|
|
|
noteable
|
|
|
|
end
|
2019-06-07 17:13:26 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|