2020-07-09 15:24:28 +00:00
|
|
|
defmodule Mobilizon.GraphQL.Schema.Discussions.CommentType do
|
2019-01-14 16:48:08 +00:00
|
|
|
@moduledoc """
|
|
|
|
Schema representation for Comment
|
|
|
|
"""
|
2019-01-14 16:13:17 +00:00
|
|
|
use Absinthe.Schema.Notation
|
2020-01-26 19:34:25 +00:00
|
|
|
|
2019-11-15 17:36:47 +00:00
|
|
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
2019-01-14 16:13:17 +00:00
|
|
|
|
2020-07-09 15:24:28 +00:00
|
|
|
alias Mobilizon.{Actors, Discussions}
|
2020-01-26 19:34:25 +00:00
|
|
|
alias Mobilizon.GraphQL.Resolvers.Comment
|
|
|
|
|
2019-01-14 16:13:17 +00:00
|
|
|
@desc "A comment"
|
|
|
|
object :comment do
|
2021-03-10 16:38:13 +00:00
|
|
|
interfaces([:action_log_object, :activity_object])
|
2019-01-21 14:08:22 +00:00
|
|
|
field(:id, :id, description: "Internal ID for this comment")
|
2020-11-19 16:06:28 +00:00
|
|
|
field(:uuid, :uuid, description: "An UUID for this comment")
|
|
|
|
field(:url, :string, description: "Comment URL")
|
|
|
|
field(:local, :boolean, description: "Whether this comment is local or not")
|
|
|
|
field(:visibility, :comment_visibility, description: "The visibility for the comment")
|
|
|
|
field(:text, :string, description: "The comment body")
|
|
|
|
field(:primaryLanguage, :string, description: "The comment's primary language")
|
2019-11-15 17:36:47 +00:00
|
|
|
|
|
|
|
field(:replies, list_of(:comment)) do
|
2020-11-19 16:06:28 +00:00
|
|
|
description("A list of replies to the comment")
|
2020-07-09 15:24:28 +00:00
|
|
|
resolve(dataloader(Discussions))
|
2019-11-15 17:36:47 +00:00
|
|
|
end
|
|
|
|
|
2020-11-19 16:06:28 +00:00
|
|
|
field(:total_replies, :integer,
|
|
|
|
description: "The number of total known replies to this comment"
|
|
|
|
)
|
|
|
|
|
|
|
|
field(:in_reply_to_comment, :comment,
|
|
|
|
resolve: dataloader(Discussions),
|
|
|
|
description: "The comment this comment directly replies to"
|
|
|
|
)
|
|
|
|
|
|
|
|
field(:event, :event,
|
|
|
|
resolve: dataloader(Events),
|
|
|
|
description: "The eventual event this comment is under"
|
|
|
|
)
|
|
|
|
|
|
|
|
field(:origin_comment, :comment,
|
|
|
|
resolve: dataloader(Discussions),
|
|
|
|
description: "The original comment that started the thread this comment is in"
|
|
|
|
)
|
|
|
|
|
|
|
|
field(:threadLanguages, non_null(list_of(:string)), description: "The thread languages")
|
|
|
|
field(:actor, :person, resolve: dataloader(Actors), description: "The comment's author")
|
|
|
|
field(:inserted_at, :datetime, description: "When was the comment inserted in database")
|
|
|
|
field(:updated_at, :datetime, description: "When was the comment updated")
|
|
|
|
field(:deleted_at, :datetime, description: "When was the comment deleted")
|
|
|
|
field(:published_at, :datetime, description: "When was the comment published")
|
2019-01-14 16:13:17 +00:00
|
|
|
end
|
2019-01-14 16:48:08 +00:00
|
|
|
|
|
|
|
@desc "The list of visibility options for a comment"
|
|
|
|
enum :comment_visibility do
|
2019-09-16 13:11:43 +00:00
|
|
|
value(:public, description: "Publicly listed and federated. Can be shared.")
|
2019-01-14 16:48:08 +00:00
|
|
|
value(:unlisted, description: "Visible only to people with the link - or invited")
|
|
|
|
|
|
|
|
value(:private,
|
|
|
|
description: "Visible only to people members of the group or followers of the person"
|
|
|
|
)
|
|
|
|
|
|
|
|
value(:moderated, description: "Visible only after a moderator accepted")
|
|
|
|
value(:invite, description: "visible only to people invited")
|
|
|
|
end
|
2019-01-25 14:41:10 +00:00
|
|
|
|
2020-11-19 16:06:28 +00:00
|
|
|
@desc "A paginated list of comments"
|
2020-02-18 07:57:00 +00:00
|
|
|
object :paginated_comment_list do
|
|
|
|
field(:elements, list_of(:comment), description: "A list of comments")
|
|
|
|
field(:total, :integer, description: "The total number of comments in the list")
|
|
|
|
end
|
|
|
|
|
2019-11-15 17:36:47 +00:00
|
|
|
object :comment_queries do
|
|
|
|
@desc "Get replies for thread"
|
|
|
|
field :thread, type: list_of(:comment) do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:id, non_null(:id), description: "The comment ID")
|
2019-11-15 17:36:47 +00:00
|
|
|
resolve(&Comment.get_thread/3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-25 14:41:10 +00:00
|
|
|
object :comment_mutations do
|
|
|
|
@desc "Create a comment"
|
|
|
|
field :create_comment, type: :comment do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:text, non_null(:string), description: "The comment's body")
|
|
|
|
arg(:event_id, non_null(:id), description: "The event under which this comment is")
|
|
|
|
arg(:in_reply_to_comment_id, :id, description: "The comment ID this one replies to")
|
2019-01-25 14:41:10 +00:00
|
|
|
|
|
|
|
resolve(&Comment.create_comment/3)
|
|
|
|
end
|
2019-11-15 17:36:47 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
@desc "Update a comment"
|
|
|
|
field :update_comment, type: :comment do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:text, non_null(:string), description: "The comment updated body")
|
|
|
|
arg(:comment_id, non_null(:id), description: "The comment ID")
|
2020-02-18 07:57:00 +00:00
|
|
|
|
|
|
|
resolve(&Comment.update_comment/3)
|
|
|
|
end
|
|
|
|
|
2020-08-14 09:32:23 +00:00
|
|
|
@desc "Delete a single comment"
|
2019-11-15 17:36:47 +00:00
|
|
|
field :delete_comment, type: :comment do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:comment_id, non_null(:id), description: "The comment ID")
|
2019-11-15 17:36:47 +00:00
|
|
|
|
|
|
|
resolve(&Comment.delete_comment/3)
|
|
|
|
end
|
2019-01-25 14:41:10 +00:00
|
|
|
end
|
2019-01-14 16:13:17 +00:00
|
|
|
end
|