2020-01-26 20:34:25 +01:00
|
|
|
defmodule Mobilizon.GraphQL.Schema.CommentType do
|
2019-01-14 17:48:08 +01:00
|
|
|
@moduledoc """
|
|
|
|
Schema representation for Comment
|
|
|
|
"""
|
2019-01-14 17:13:17 +01:00
|
|
|
use Absinthe.Schema.Notation
|
2020-01-26 20:34:25 +01:00
|
|
|
|
2019-11-15 18:36:47 +01:00
|
|
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
2019-01-14 17:13:17 +01:00
|
|
|
|
2020-01-26 20:34:25 +01:00
|
|
|
alias Mobilizon.{Actors, Events}
|
|
|
|
alias Mobilizon.GraphQL.Resolvers.Comment
|
|
|
|
|
2019-01-14 17:13:17 +01:00
|
|
|
@desc "A comment"
|
|
|
|
object :comment do
|
2019-11-15 18:36:47 +01:00
|
|
|
interfaces([:action_log_object])
|
2019-01-21 15:08:22 +01:00
|
|
|
field(:id, :id, description: "Internal ID for this comment")
|
2019-01-14 17:13:17 +01:00
|
|
|
field(:uuid, :uuid)
|
|
|
|
field(:url, :string)
|
|
|
|
field(:local, :boolean)
|
2019-01-14 17:48:08 +01:00
|
|
|
field(:visibility, :comment_visibility)
|
2019-01-14 17:13:17 +01:00
|
|
|
field(:text, :string)
|
|
|
|
field(:primaryLanguage, :string)
|
2019-11-15 18:36:47 +01:00
|
|
|
|
|
|
|
field(:replies, list_of(:comment)) do
|
|
|
|
resolve(dataloader(Events))
|
|
|
|
end
|
|
|
|
|
|
|
|
field(:total_replies, :integer)
|
|
|
|
field(:in_reply_to_comment, :comment, resolve: dataloader(Events))
|
|
|
|
field(:event, :event, resolve: dataloader(Events))
|
|
|
|
field(:origin_comment, :comment, resolve: dataloader(Events))
|
2019-01-14 17:13:17 +01:00
|
|
|
field(:threadLanguages, non_null(list_of(:string)))
|
2019-11-15 18:36:47 +01:00
|
|
|
field(:actor, :person, resolve: dataloader(Actors))
|
|
|
|
field(:inserted_at, :datetime)
|
|
|
|
field(:updated_at, :datetime)
|
|
|
|
field(:deleted_at, :datetime)
|
2019-01-14 17:13:17 +01:00
|
|
|
end
|
2019-01-14 17:48:08 +01:00
|
|
|
|
|
|
|
@desc "The list of visibility options for a comment"
|
|
|
|
enum :comment_visibility do
|
2019-09-16 15:11:43 +02:00
|
|
|
value(:public, description: "Publicly listed and federated. Can be shared.")
|
2019-01-14 17:48:08 +01: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 15:41:10 +01:00
|
|
|
|
2019-11-15 18:36:47 +01:00
|
|
|
object :comment_queries do
|
|
|
|
@desc "Get replies for thread"
|
|
|
|
field :thread, type: list_of(:comment) do
|
|
|
|
arg(:id, :id)
|
|
|
|
resolve(&Comment.get_thread/3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-25 15:41:10 +01:00
|
|
|
object :comment_mutations do
|
|
|
|
@desc "Create a comment"
|
|
|
|
field :create_comment, type: :comment do
|
|
|
|
arg(:text, non_null(:string))
|
2019-11-15 18:36:47 +01:00
|
|
|
arg(:event_id, :id)
|
|
|
|
arg(:in_reply_to_comment_id, :id)
|
2019-10-25 17:43:37 +02:00
|
|
|
arg(:actor_id, non_null(:id))
|
2019-01-25 15:41:10 +01:00
|
|
|
|
|
|
|
resolve(&Comment.create_comment/3)
|
|
|
|
end
|
2019-11-15 18:36:47 +01:00
|
|
|
|
|
|
|
field :delete_comment, type: :comment do
|
|
|
|
arg(:comment_id, non_null(:id))
|
|
|
|
arg(:actor_id, non_null(:id))
|
|
|
|
|
|
|
|
resolve(&Comment.delete_comment/3)
|
|
|
|
end
|
2019-01-25 15:41:10 +01:00
|
|
|
end
|
2019-01-14 17:13:17 +01:00
|
|
|
end
|