2020-01-26 19:34:25 +00:00
|
|
|
defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
|
2019-01-14 16:48:08 +00:00
|
|
|
@moduledoc """
|
2019-09-22 14:26:23 +00:00
|
|
|
Schema representation for Group.
|
2019-01-14 16:48:08 +00:00
|
|
|
"""
|
2019-09-22 14:26:23 +00:00
|
|
|
|
2019-01-14 16:13:17 +00:00
|
|
|
use Absinthe.Schema.Notation
|
2019-09-22 14:26:23 +00:00
|
|
|
|
2020-08-05 14:44:08 +00:00
|
|
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
|
|
|
|
|
|
|
alias Mobilizon.Addresses
|
2020-07-09 15:24:28 +00:00
|
|
|
alias Mobilizon.GraphQL.Resolvers.{Discussion, Group, Member, Post, Resource, Todos}
|
2020-01-26 19:34:25 +00:00
|
|
|
alias Mobilizon.GraphQL.Schema
|
2019-01-14 16:13:17 +00:00
|
|
|
|
2020-01-26 19:34:25 +00:00
|
|
|
import_types(Schema.Actors.MemberType)
|
2019-09-22 14:26:23 +00:00
|
|
|
|
2019-01-14 16:13:17 +00:00
|
|
|
@desc """
|
|
|
|
Represents a group of actors
|
|
|
|
"""
|
|
|
|
object :group do
|
|
|
|
interfaces([:actor])
|
|
|
|
|
2019-09-09 07:31:08 +00:00
|
|
|
field(:id, :id, description: "Internal ID for this group")
|
2019-01-14 16:13:17 +00:00
|
|
|
field(:url, :string, description: "The ActivityPub actor's URL")
|
|
|
|
field(:type, :actor_type, description: "The type of Actor (Person, Group,…)")
|
|
|
|
field(:name, :string, description: "The actor's displayed name")
|
|
|
|
field(:domain, :string, description: "The actor's domain if (null if it's this instance)")
|
|
|
|
field(:local, :boolean, description: "If the actor is from this instance")
|
|
|
|
field(:summary, :string, description: "The actor's summary")
|
|
|
|
field(:preferred_username, :string, description: "The actor's preferred username")
|
|
|
|
|
|
|
|
field(:manually_approves_followers, :boolean,
|
|
|
|
description: "Whether the actors manually approves followers"
|
|
|
|
)
|
|
|
|
|
2020-08-05 14:44:08 +00:00
|
|
|
field(:visibility, :group_visibility,
|
|
|
|
description: "Whether the group can be found and/or promoted"
|
|
|
|
)
|
|
|
|
|
2019-01-14 16:13:17 +00:00
|
|
|
field(:suspended, :boolean, description: "If the actor is suspended")
|
2019-05-22 12:12:11 +00:00
|
|
|
|
|
|
|
field(:avatar, :picture, description: "The actor's avatar picture")
|
|
|
|
field(:banner, :picture, description: "The actor's banner picture")
|
2019-01-14 16:13:17 +00:00
|
|
|
|
2020-08-05 14:44:08 +00:00
|
|
|
field(:physical_address, :address,
|
|
|
|
resolve: dataloader(Addresses),
|
|
|
|
description: "The type of the event's address"
|
|
|
|
)
|
|
|
|
|
2019-01-14 16:13:17 +00:00
|
|
|
# These one should have a privacy setting
|
|
|
|
field(:following, list_of(:follower), description: "List of followings")
|
|
|
|
field(:followers, list_of(:follower), description: "List of followers")
|
|
|
|
field(:followersCount, :integer, description: "Number of followers for this actor")
|
|
|
|
field(:followingCount, :integer, description: "Number of actors following this actor")
|
|
|
|
|
|
|
|
# This one should have a privacy setting
|
2020-02-18 07:57:00 +00:00
|
|
|
field :organized_events, :paginated_event_list do
|
2020-09-02 15:42:17 +00:00
|
|
|
arg(:after_datetime, :datetime, default_value: nil)
|
|
|
|
arg(:before_datetime, :datetime, default_value: nil)
|
|
|
|
arg(:page, :integer, default_value: 1)
|
|
|
|
arg(:limit, :integer, default_value: 10)
|
2020-02-18 07:57:00 +00:00
|
|
|
resolve(&Group.find_events_for_group/3)
|
|
|
|
description("A list of the events this actor has organized")
|
|
|
|
end
|
|
|
|
|
2020-07-09 15:24:28 +00:00
|
|
|
field :discussions, :paginated_discussion_list do
|
|
|
|
resolve(&Discussion.find_discussions_for_actor/3)
|
|
|
|
description("A list of the discussions for this group")
|
2020-02-18 07:57:00 +00:00
|
|
|
end
|
2019-01-14 16:13:17 +00:00
|
|
|
|
|
|
|
field(:types, :group_type, description: "The type of group : Group, Community,…")
|
|
|
|
|
|
|
|
field(:openness, :openness,
|
|
|
|
description: "Whether the group is opened to all or has restricted access"
|
|
|
|
)
|
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
field :members, :paginated_member_list do
|
2020-07-09 15:24:28 +00:00
|
|
|
arg(:page, :integer, default_value: 1)
|
|
|
|
arg(:limit, :integer, default_value: 10)
|
|
|
|
arg(:roles, :string, default_value: "")
|
2020-02-18 07:57:00 +00:00
|
|
|
resolve(&Member.find_members_for_group/3)
|
2020-07-09 15:24:28 +00:00
|
|
|
description("A paginated list of group members")
|
2020-02-18 07:57:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
field :resources, :paginated_resource_list do
|
|
|
|
arg(:page, :integer, default_value: 1)
|
|
|
|
arg(:limit, :integer, default_value: 10)
|
|
|
|
resolve(&Resource.find_resources_for_group/3)
|
|
|
|
description("A paginated list of the resources this group has")
|
|
|
|
end
|
|
|
|
|
2020-07-09 15:24:28 +00:00
|
|
|
field :posts, :paginated_post_list do
|
|
|
|
arg(:page, :integer, default_value: 1)
|
|
|
|
arg(:limit, :integer, default_value: 10)
|
|
|
|
resolve(&Post.find_posts_for_group/3)
|
|
|
|
description("A paginated list of the posts this group has")
|
|
|
|
end
|
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
field :todo_lists, :paginated_todo_list_list do
|
|
|
|
resolve(&Todos.find_todo_lists_for_group/3)
|
|
|
|
description("A paginated list of the todo lists this group has")
|
|
|
|
end
|
2019-01-14 16:13:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
@desc """
|
|
|
|
The types of Group that exist
|
|
|
|
"""
|
|
|
|
enum :group_type do
|
|
|
|
value(:group, description: "A private group of persons")
|
|
|
|
value(:community, description: "A public group of many actors")
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc """
|
|
|
|
Describes how an actor is opened to follows
|
|
|
|
"""
|
|
|
|
enum :openness do
|
|
|
|
value(:invite_only, description: "The actor can only be followed by invitation")
|
|
|
|
|
|
|
|
value(:moderated, description: "The actor needs to accept the following before it's effective")
|
|
|
|
|
|
|
|
value(:open, description: "The actor is open to followings")
|
|
|
|
end
|
2019-01-25 12:59:58 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
object :paginated_group_list do
|
|
|
|
field(:elements, list_of(:group), description: "A list of groups")
|
|
|
|
field(:total, :integer, description: "The total number of elements in the list")
|
|
|
|
end
|
|
|
|
|
2020-07-09 15:24:28 +00:00
|
|
|
@desc "The list of visibility options for a group"
|
|
|
|
enum :group_visibility do
|
|
|
|
value(:public, description: "Publicly listed and federated")
|
|
|
|
value(:unlisted, description: "Visible only to people with the link - or invited")
|
|
|
|
end
|
|
|
|
|
2019-01-25 12:59:58 +00:00
|
|
|
object :group_queries do
|
|
|
|
@desc "Get all groups"
|
2020-02-18 07:57:00 +00:00
|
|
|
field :groups, :paginated_group_list do
|
2020-08-27 09:53:24 +00:00
|
|
|
arg(:preferred_username, :string, default_value: "")
|
|
|
|
arg(:name, :string, default_value: "")
|
|
|
|
arg(:domain, :string, default_value: "")
|
|
|
|
arg(:local, :boolean, default_value: true)
|
|
|
|
arg(:suspended, :boolean, default_value: false)
|
2019-01-25 12:59:58 +00:00
|
|
|
arg(:page, :integer, default_value: 1)
|
|
|
|
arg(:limit, :integer, default_value: 10)
|
2019-05-22 12:12:11 +00:00
|
|
|
resolve(&Group.list_groups/3)
|
2019-01-25 12:59:58 +00:00
|
|
|
end
|
|
|
|
|
2020-08-27 09:53:24 +00:00
|
|
|
@desc "Get a group by its ID"
|
|
|
|
field :get_group, :group do
|
|
|
|
arg(:id, non_null(:id))
|
|
|
|
resolve(&Group.get_group/3)
|
|
|
|
end
|
|
|
|
|
2019-10-15 19:18:03 +00:00
|
|
|
@desc "Get a group by its preferred username"
|
2019-01-25 12:59:58 +00:00
|
|
|
field :group, :group do
|
|
|
|
arg(:preferred_username, non_null(:string))
|
2019-05-22 12:12:11 +00:00
|
|
|
resolve(&Group.find_group/3)
|
2019-01-25 12:59:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
object :group_mutations do
|
|
|
|
@desc "Create a group"
|
|
|
|
field :create_group, :group do
|
|
|
|
arg(:preferred_username, non_null(:string), description: "The name for the group")
|
|
|
|
|
2019-09-09 07:31:08 +00:00
|
|
|
arg(:creator_actor_id, non_null(:id), description: "The identity that creates the group")
|
2019-01-25 12:59:58 +00:00
|
|
|
|
2019-09-02 08:50:00 +00:00
|
|
|
arg(:name, :string, description: "The displayed name for the group")
|
|
|
|
arg(:summary, :string, description: "The summary for the group", default_value: "")
|
|
|
|
|
2020-07-09 15:24:28 +00:00
|
|
|
arg(:visibility, :group_visibility,
|
|
|
|
description: "The visibility for the group",
|
|
|
|
default_value: :public
|
|
|
|
)
|
|
|
|
|
2019-05-22 12:12:11 +00:00
|
|
|
arg(:avatar, :picture_input,
|
|
|
|
description:
|
|
|
|
"The avatar for the group, either as an object or directly the ID of an existing Picture"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:banner, :picture_input,
|
|
|
|
description:
|
|
|
|
"The banner for the group, either as an object or directly the ID of an existing Picture"
|
|
|
|
)
|
|
|
|
|
2020-08-05 14:44:08 +00:00
|
|
|
arg(:physical_address, :address_input)
|
|
|
|
|
2019-05-22 12:12:11 +00:00
|
|
|
resolve(&Group.create_group/3)
|
2019-01-25 12:59:58 +00:00
|
|
|
end
|
|
|
|
|
2020-07-09 15:24:28 +00:00
|
|
|
@desc "Update a group"
|
|
|
|
field :update_group, :group do
|
|
|
|
arg(:id, non_null(:id), description: "The group ID")
|
|
|
|
|
|
|
|
arg(:name, :string, description: "The displayed name for the group")
|
|
|
|
arg(:summary, :string, description: "The summary for the group", default_value: "")
|
|
|
|
|
2020-08-05 14:44:08 +00:00
|
|
|
arg(:visibility, :group_visibility, description: "The visibility for the group")
|
|
|
|
|
2020-07-09 15:24:28 +00:00
|
|
|
arg(:avatar, :picture_input,
|
|
|
|
description:
|
|
|
|
"The avatar for the group, either as an object or directly the ID of an existing Picture"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:banner, :picture_input,
|
|
|
|
description:
|
|
|
|
"The banner for the group, either as an object or directly the ID of an existing Picture"
|
|
|
|
)
|
|
|
|
|
2020-08-05 14:44:08 +00:00
|
|
|
arg(:physical_address, :address_input)
|
|
|
|
|
2020-07-09 15:24:28 +00:00
|
|
|
resolve(&Group.update_group/3)
|
|
|
|
end
|
|
|
|
|
2019-01-25 12:59:58 +00:00
|
|
|
@desc "Delete a group"
|
|
|
|
field :delete_group, :deleted_object do
|
2019-09-09 07:31:08 +00:00
|
|
|
arg(:group_id, non_null(:id))
|
2019-01-25 12:59:58 +00:00
|
|
|
|
2019-05-22 12:12:11 +00:00
|
|
|
resolve(&Group.delete_group/3)
|
2019-01-25 12:59:58 +00:00
|
|
|
end
|
|
|
|
end
|
2019-01-14 16:13:17 +00:00
|
|
|
end
|