2020-07-09 17:24:28 +02:00
|
|
|
defmodule Mobilizon.GraphQL.Schema.PostType do
|
|
|
|
@moduledoc """
|
|
|
|
Schema representation for Posts
|
|
|
|
"""
|
|
|
|
use Absinthe.Schema.Notation
|
2020-11-26 11:41:13 +01:00
|
|
|
alias Mobilizon.GraphQL.Resolvers.{Media, Post, Tag}
|
2020-07-09 17:24:28 +02:00
|
|
|
|
|
|
|
@desc "A post"
|
|
|
|
object :post do
|
2021-02-24 19:06:48 +01:00
|
|
|
interfaces([:activity_object])
|
2020-07-09 17:24:28 +02:00
|
|
|
field(:id, :id, description: "The post's ID")
|
|
|
|
field(:title, :string, description: "The post's title")
|
|
|
|
field(:slug, :string, description: "The post's slug")
|
|
|
|
field(:body, :string, description: "The post's body, as HTML")
|
|
|
|
field(:url, :string, description: "The post's URL")
|
|
|
|
field(:draft, :boolean, description: "Whether the post is a draft")
|
|
|
|
field(:author, :actor, description: "The post's author")
|
|
|
|
field(:attributed_to, :actor, description: "The post's group")
|
|
|
|
field(:visibility, :post_visibility, description: "The post's visibility")
|
|
|
|
field(:publish_at, :datetime, description: "When the post was published")
|
2020-10-13 20:42:15 +02:00
|
|
|
field(:inserted_at, :datetime, description: "The post's creation date")
|
|
|
|
field(:updated_at, :datetime, description: "The post's last update date")
|
2021-11-23 09:36:19 +01:00
|
|
|
field(:language, :string, description: "The post language")
|
2020-07-09 17:24:28 +02:00
|
|
|
|
|
|
|
field(:tags, list_of(:tag),
|
|
|
|
resolve: &Tag.list_tags_for_post/3,
|
|
|
|
description: "The post's tags"
|
|
|
|
)
|
2020-10-01 15:07:15 +02:00
|
|
|
|
2020-11-26 11:41:13 +01:00
|
|
|
field(:picture, :media,
|
|
|
|
description: "The posts's media",
|
|
|
|
resolve: &Media.media/3
|
2020-10-01 15:07:15 +02:00
|
|
|
)
|
2020-07-09 17:24:28 +02:00
|
|
|
end
|
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
@desc """
|
|
|
|
A paginated list of posts
|
|
|
|
"""
|
2020-07-09 17:24:28 +02:00
|
|
|
object :paginated_post_list do
|
|
|
|
field(:elements, list_of(:post), description: "A list of posts")
|
|
|
|
field(:total, :integer, description: "The total number of posts in the list")
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "The list of visibility options for a post"
|
|
|
|
enum :post_visibility do
|
|
|
|
value(:public, description: "Publicly listed and federated. Can be shared.")
|
|
|
|
value(:unlisted, description: "Visible only to people with the link")
|
|
|
|
# value(:restricted, description: "Visible only after a moderator accepted")
|
|
|
|
|
|
|
|
value(:private,
|
|
|
|
description: "Visible only to people members of the group or followers of the person"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
object :post_queries do
|
|
|
|
@desc "Get a post"
|
|
|
|
field :post, :post do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:slug, non_null(:string), description: "The post's slug")
|
2020-07-09 17:24:28 +02:00
|
|
|
resolve(&Post.get_post/3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
object :post_mutations do
|
|
|
|
@desc "Create a post"
|
|
|
|
field :create_post, :post do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:attributed_to_id, non_null(:id),
|
|
|
|
description: "The ID from the group whose post is attributed to"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:title, non_null(:string), description: "The post's title")
|
|
|
|
arg(:body, non_null(:string), description: "The post's body")
|
|
|
|
arg(:draft, :boolean, default_value: false, description: "Whether the post is a draft")
|
|
|
|
arg(:visibility, :post_visibility, description: "The post's visibility")
|
|
|
|
arg(:publish_at, :datetime, description: "The post's publish date")
|
2021-08-19 20:43:35 +02:00
|
|
|
arg(:language, :string, description: "The post language", default_value: "und")
|
2020-07-09 17:24:28 +02:00
|
|
|
|
|
|
|
arg(:tags, list_of(:string),
|
|
|
|
default_value: [],
|
|
|
|
description: "The list of tags associated to the post"
|
|
|
|
)
|
|
|
|
|
2020-11-26 11:41:13 +01:00
|
|
|
arg(:picture, :media_input,
|
2020-10-01 15:07:15 +02:00
|
|
|
description:
|
2020-11-26 11:41:13 +01:00
|
|
|
"The banner for the post, either as an object or directly the ID of an existing media"
|
2020-10-01 15:07:15 +02:00
|
|
|
)
|
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
resolve(&Post.create_post/3)
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Update a post"
|
|
|
|
field :update_post, :post do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:id, non_null(:id), description: "The post's ID")
|
|
|
|
arg(:title, :string, description: "The post's new title")
|
|
|
|
arg(:body, :string, description: "The post's new body")
|
|
|
|
arg(:attributed_to_id, :id, description: "The group the post is attributed to")
|
|
|
|
arg(:draft, :boolean, description: "Whether the post is a draft")
|
|
|
|
arg(:visibility, :post_visibility, description: "The post's visibility")
|
2021-08-19 20:43:35 +02:00
|
|
|
arg(:language, :string, description: "The post language", default_value: "und")
|
2020-11-19 17:06:28 +01:00
|
|
|
|
|
|
|
arg(:publish_at, :datetime,
|
|
|
|
description: "The time when the posts is going to be or has been published"
|
|
|
|
)
|
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
arg(:tags, list_of(:string), description: "The list of tags associated to the post")
|
|
|
|
|
2020-11-26 11:41:13 +01:00
|
|
|
arg(:picture, :media_input,
|
2020-10-01 15:07:15 +02:00
|
|
|
description:
|
2020-11-26 11:41:13 +01:00
|
|
|
"The banner for the post, either as an object or directly the ID of an existing media"
|
2020-10-01 15:07:15 +02:00
|
|
|
)
|
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
resolve(&Post.update_post/3)
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Delete a post"
|
|
|
|
field :delete_post, :deleted_object do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:id, non_null(:id), description: "The post's ID")
|
2020-07-09 17:24:28 +02:00
|
|
|
resolve(&Post.delete_post/3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|