2020-07-09 17:24:28 +02:00
|
|
|
defmodule Mobilizon.GraphQL.Schema.Discussions.DiscussionType do
|
|
|
|
@moduledoc """
|
|
|
|
Schema representation for discussion
|
|
|
|
"""
|
|
|
|
use Absinthe.Schema.Notation
|
|
|
|
|
|
|
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
|
|
|
|
|
|
|
alias Mobilizon.Actors
|
|
|
|
alias Mobilizon.GraphQL.Resolvers.Discussion
|
|
|
|
|
|
|
|
@desc "A discussion"
|
|
|
|
object :discussion do
|
2021-02-24 19:06:48 +01:00
|
|
|
interfaces([:activity_object])
|
2020-07-09 17:24:28 +02:00
|
|
|
field(:id, :id, description: "Internal ID for this discussion")
|
2020-11-19 17:06:28 +01:00
|
|
|
field(:title, :string, description: "The title for this discussion")
|
|
|
|
field(:slug, :string, description: "The slug for the discussion")
|
|
|
|
field(:last_comment, :comment, description: "The last comment of the discussion")
|
2020-07-09 17:24:28 +02:00
|
|
|
|
|
|
|
field :comments, :paginated_comment_list do
|
|
|
|
arg(:page, :integer, default_value: 1)
|
|
|
|
arg(:limit, :integer, default_value: 10)
|
|
|
|
resolve(&Discussion.get_comments_for_discussion/3)
|
|
|
|
description("The comments for the discussion")
|
|
|
|
end
|
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
field(:creator, :person,
|
|
|
|
resolve: dataloader(Actors),
|
|
|
|
description: "This discussions's creator"
|
|
|
|
)
|
|
|
|
|
|
|
|
field(:actor, :actor, resolve: dataloader(Actors), description: "This discussion's group")
|
|
|
|
field(:inserted_at, :datetime, description: "When was this discussion's created")
|
|
|
|
field(:updated_at, :datetime, description: "When was this discussion's updated")
|
2020-07-09 17:24:28 +02:00
|
|
|
end
|
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
@desc "A paginated list of discussions"
|
2020-07-09 17:24:28 +02:00
|
|
|
object :paginated_discussion_list do
|
|
|
|
field(:elements, list_of(:discussion), description: "A list of discussion")
|
2020-11-19 17:06:28 +01:00
|
|
|
field(:total, :integer, description: "The total number of discussions in the list")
|
2020-07-09 17:24:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
object :discussion_queries do
|
|
|
|
@desc "Get a discussion"
|
|
|
|
field :discussion, type: :discussion do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:id, :id, description: "The discussion's ID")
|
|
|
|
arg(:slug, :string, description: "The discussion's slug")
|
2020-07-09 17:24:28 +02:00
|
|
|
resolve(&Discussion.get_discussion/3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
object :discussion_mutations do
|
|
|
|
@desc "Create a discussion"
|
|
|
|
field :create_discussion, type: :discussion do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:title, non_null(:string), description: "The discussion's title")
|
|
|
|
arg(:text, non_null(:string), description: "The discussion's first comment body")
|
|
|
|
arg(:actor_id, non_null(:id), description: "The discussion's group ID")
|
2020-07-09 17:24:28 +02:00
|
|
|
|
|
|
|
resolve(&Discussion.create_discussion/3)
|
|
|
|
end
|
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
@desc "Reply to a discussion"
|
2020-07-09 17:24:28 +02:00
|
|
|
field :reply_to_discussion, type: :discussion do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:discussion_id, non_null(:id), description: "The discussion's ID")
|
|
|
|
arg(:text, non_null(:string), description: "The discussion's reply body")
|
2020-07-09 17:24:28 +02:00
|
|
|
resolve(&Discussion.reply_to_discussion/3)
|
|
|
|
end
|
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
@desc "Update a discussion"
|
2020-07-09 17:24:28 +02:00
|
|
|
field :update_discussion, type: :discussion do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:title, non_null(:string), description: "The updated discussion's title")
|
|
|
|
arg(:discussion_id, non_null(:id), description: "The discussion's ID")
|
2020-07-09 17:24:28 +02:00
|
|
|
resolve(&Discussion.update_discussion/3)
|
|
|
|
end
|
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
@desc "Delete a discussion"
|
2020-07-09 17:24:28 +02:00
|
|
|
field :delete_discussion, type: :discussion do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:discussion_id, non_null(:id), description: "The discussion's ID")
|
2020-07-09 17:24:28 +02:00
|
|
|
|
|
|
|
resolve(&Discussion.delete_discussion/3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
object :discussion_subscriptions do
|
2020-11-19 17:06:28 +01:00
|
|
|
@desc "Notify when a discussion changed"
|
2020-07-09 17:24:28 +02:00
|
|
|
field :discussion_comment_changed, :discussion do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:slug, non_null(:string), description: "The discussion's slug")
|
2020-07-09 17:24:28 +02:00
|
|
|
|
|
|
|
config(fn args, _ ->
|
|
|
|
{:ok, topic: args.slug}
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|