Split GraphQL as separate context
This commit is contained in:
38
lib/graphql/schema/actors/application.ex
Normal file
38
lib/graphql/schema/actors/application.ex
Normal file
@@ -0,0 +1,38 @@
|
||||
defmodule Mobilizon.GraphQL.Schema.Actors.ApplicationType do
|
||||
@moduledoc """
|
||||
Schema representation for Group.
|
||||
"""
|
||||
|
||||
use Absinthe.Schema.Notation
|
||||
|
||||
@desc """
|
||||
Represents an application
|
||||
"""
|
||||
object :application do
|
||||
interfaces([:actor])
|
||||
|
||||
field(:id, :id, description: "Internal ID for this application")
|
||||
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"
|
||||
)
|
||||
|
||||
field(:suspended, :boolean, description: "If the actor is suspended")
|
||||
|
||||
field(:avatar, :picture, description: "The actor's avatar picture")
|
||||
field(:banner, :picture, description: "The actor's banner picture")
|
||||
|
||||
# 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")
|
||||
end
|
||||
end
|
||||
26
lib/graphql/schema/actors/follower.ex
Normal file
26
lib/graphql/schema/actors/follower.ex
Normal file
@@ -0,0 +1,26 @@
|
||||
defmodule Mobilizon.GraphQL.Schema.Actors.FollowerType do
|
||||
@moduledoc """
|
||||
Schema representation for Follower
|
||||
"""
|
||||
use Absinthe.Schema.Notation
|
||||
|
||||
@desc """
|
||||
Represents an actor's follower
|
||||
"""
|
||||
object :follower do
|
||||
field(:target_actor, :actor, description: "What or who the profile follows")
|
||||
field(:actor, :actor, description: "Which profile follows")
|
||||
|
||||
field(:approved, :boolean,
|
||||
description: "Whether the follow has been approved by the target actor"
|
||||
)
|
||||
|
||||
field(:inserted_at, :datetime, description: "When the follow was created")
|
||||
field(:updated_at, :datetime, description: "When the follow was updated")
|
||||
end
|
||||
|
||||
object :paginated_follower_list do
|
||||
field(:elements, list_of(:follower), description: "A list of followers")
|
||||
field(:total, :integer, description: "The total number of elements in the list")
|
||||
end
|
||||
end
|
||||
129
lib/graphql/schema/actors/group.ex
Normal file
129
lib/graphql/schema/actors/group.ex
Normal file
@@ -0,0 +1,129 @@
|
||||
defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
|
||||
@moduledoc """
|
||||
Schema representation for Group.
|
||||
"""
|
||||
|
||||
use Absinthe.Schema.Notation
|
||||
|
||||
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
||||
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.GraphQL.Resolvers.{Group, Member}
|
||||
alias Mobilizon.GraphQL.Schema
|
||||
|
||||
import_types(Schema.Actors.MemberType)
|
||||
|
||||
@desc """
|
||||
Represents a group of actors
|
||||
"""
|
||||
object :group do
|
||||
interfaces([:actor])
|
||||
|
||||
field(:id, :id, description: "Internal ID for this group")
|
||||
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"
|
||||
)
|
||||
|
||||
field(:suspended, :boolean, description: "If the actor is suspended")
|
||||
|
||||
field(:avatar, :picture, description: "The actor's avatar picture")
|
||||
field(:banner, :picture, description: "The actor's banner picture")
|
||||
|
||||
# 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
|
||||
field(:organized_events, list_of(:event),
|
||||
resolve: dataloader(Events),
|
||||
description: "A list of the events this actor has organized"
|
||||
)
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
field(:members, non_null(list_of(:member)),
|
||||
resolve: &Member.find_members_for_group/3,
|
||||
description: "List of group members"
|
||||
)
|
||||
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
|
||||
|
||||
object :group_queries do
|
||||
@desc "Get all groups"
|
||||
field :groups, list_of(:group) do
|
||||
arg(:page, :integer, default_value: 1)
|
||||
arg(:limit, :integer, default_value: 10)
|
||||
resolve(&Group.list_groups/3)
|
||||
end
|
||||
|
||||
@desc "Get a group by its preferred username"
|
||||
field :group, :group do
|
||||
arg(:preferred_username, non_null(:string))
|
||||
resolve(&Group.find_group/3)
|
||||
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")
|
||||
|
||||
arg(:creator_actor_id, non_null(:id), description: "The identity that creates the group")
|
||||
|
||||
arg(:name, :string, description: "The displayed name for the group")
|
||||
arg(:summary, :string, description: "The summary for the group", default_value: "")
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
resolve(&Group.create_group/3)
|
||||
end
|
||||
|
||||
@desc "Delete a group"
|
||||
field :delete_group, :deleted_object do
|
||||
arg(:group_id, non_null(:id))
|
||||
arg(:actor_id, non_null(:id))
|
||||
|
||||
resolve(&Group.delete_group/3)
|
||||
end
|
||||
end
|
||||
end
|
||||
41
lib/graphql/schema/actors/member.ex
Normal file
41
lib/graphql/schema/actors/member.ex
Normal file
@@ -0,0 +1,41 @@
|
||||
defmodule Mobilizon.GraphQL.Schema.Actors.MemberType do
|
||||
@moduledoc """
|
||||
Schema representation for Member
|
||||
"""
|
||||
use Absinthe.Schema.Notation
|
||||
|
||||
alias Mobilizon.GraphQL.Resolvers.Group
|
||||
|
||||
@desc """
|
||||
Represents a member of a group
|
||||
"""
|
||||
object :member do
|
||||
field(:parent, :group, description: "Of which the profile is member")
|
||||
field(:actor, :person, description: "Which profile is member of")
|
||||
field(:role, :integer, description: "The role of this membership")
|
||||
end
|
||||
|
||||
@desc "Represents a deleted member"
|
||||
object :deleted_member do
|
||||
field(:parent, :deleted_object)
|
||||
field(:actor, :deleted_object)
|
||||
end
|
||||
|
||||
object :member_mutations do
|
||||
@desc "Join a group"
|
||||
field :join_group, :member do
|
||||
arg(:group_id, non_null(:id))
|
||||
arg(:actor_id, non_null(:id))
|
||||
|
||||
resolve(&Group.join_group/3)
|
||||
end
|
||||
|
||||
@desc "Leave an event"
|
||||
field :leave_group, :deleted_member do
|
||||
arg(:group_id, non_null(:id))
|
||||
arg(:actor_id, non_null(:id))
|
||||
|
||||
resolve(&Group.leave_group/3)
|
||||
end
|
||||
end
|
||||
end
|
||||
175
lib/graphql/schema/actors/person.ex
Normal file
175
lib/graphql/schema/actors/person.ex
Normal file
@@ -0,0 +1,175 @@
|
||||
defmodule Mobilizon.GraphQL.Schema.Actors.PersonType do
|
||||
@moduledoc """
|
||||
Schema representation for Person
|
||||
"""
|
||||
use Absinthe.Schema.Notation
|
||||
|
||||
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
||||
import Mobilizon.GraphQL.Helpers.Error
|
||||
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.GraphQL.Resolvers.Person
|
||||
alias Mobilizon.GraphQL.Schema
|
||||
|
||||
import_types(Schema.Events.FeedTokenType)
|
||||
|
||||
@desc """
|
||||
Represents a person identity
|
||||
"""
|
||||
object :person do
|
||||
interfaces([:actor])
|
||||
field(:id, :id, description: "Internal ID for this person")
|
||||
field(:user, :user, description: "The user this actor is associated to")
|
||||
|
||||
field(:member_of, list_of(:member), description: "The list of groups this person is member of")
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
field(:suspended, :boolean, description: "If the actor is suspended")
|
||||
|
||||
field(:avatar, :picture, description: "The actor's avatar picture")
|
||||
field(:banner, :picture, description: "The actor's banner picture")
|
||||
|
||||
# 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")
|
||||
|
||||
field(:feed_tokens, list_of(:feed_token),
|
||||
resolve: dataloader(Events),
|
||||
description: "A list of the feed tokens for this person"
|
||||
)
|
||||
|
||||
# This one should have a privacy setting
|
||||
field(:organized_events, list_of(:event),
|
||||
resolve: dataloader(Events),
|
||||
description: "A list of the events this actor has organized"
|
||||
)
|
||||
|
||||
@desc "The list of events this person goes to"
|
||||
field(:participations, list_of(:participant),
|
||||
description: "The list of events this person goes to"
|
||||
) do
|
||||
arg(:event_id, :id)
|
||||
resolve(&Person.person_participations/3)
|
||||
end
|
||||
end
|
||||
|
||||
object :person_queries do
|
||||
@desc "Get the current actor for the logged-in user"
|
||||
field :logged_person, :person do
|
||||
resolve(&Person.get_current_person/3)
|
||||
end
|
||||
|
||||
@desc "Get a person by its (federated) username"
|
||||
field :fetch_person, :person do
|
||||
arg(:preferred_username, non_null(:string))
|
||||
resolve(&Person.fetch_person/3)
|
||||
end
|
||||
|
||||
@desc "Get a person by its ID"
|
||||
field :person, :person do
|
||||
arg(:id, non_null(:id))
|
||||
resolve(&Person.get_person/3)
|
||||
end
|
||||
|
||||
@desc "Get the persons for an user"
|
||||
field :identities, list_of(:person) do
|
||||
resolve(&Person.identities/3)
|
||||
end
|
||||
end
|
||||
|
||||
object :person_mutations do
|
||||
@desc "Create a new person for user"
|
||||
field :create_person, :person do
|
||||
arg(:preferred_username, non_null(:string))
|
||||
|
||||
arg(:name, :string, description: "The displayed name for the new profile", default_value: "")
|
||||
|
||||
arg(:summary, :string, description: "The summary for the new profile", default_value: "")
|
||||
|
||||
arg(:avatar, :picture_input,
|
||||
description:
|
||||
"The avatar for the profile, either as an object or directly the ID of an existing Picture"
|
||||
)
|
||||
|
||||
arg(:banner, :picture_input,
|
||||
description:
|
||||
"The banner for the profile, either as an object or directly the ID of an existing Picture"
|
||||
)
|
||||
|
||||
resolve(handle_errors(&Person.create_person/3))
|
||||
end
|
||||
|
||||
@desc "Update an identity"
|
||||
field :update_person, :person do
|
||||
arg(:id, non_null(:id))
|
||||
|
||||
arg(:name, :string, description: "The displayed name for this profile")
|
||||
|
||||
arg(:summary, :string, description: "The summary for this profile")
|
||||
|
||||
arg(:avatar, :picture_input,
|
||||
description:
|
||||
"The avatar for the profile, either as an object or directly the ID of an existing Picture"
|
||||
)
|
||||
|
||||
arg(:banner, :picture_input,
|
||||
description:
|
||||
"The banner for the profile, either as an object or directly the ID of an existing Picture"
|
||||
)
|
||||
|
||||
resolve(handle_errors(&Person.update_person/3))
|
||||
end
|
||||
|
||||
@desc "Delete an identity"
|
||||
field :delete_person, :person do
|
||||
arg(:id, non_null(:id))
|
||||
|
||||
resolve(handle_errors(&Person.delete_person/3))
|
||||
end
|
||||
|
||||
@desc "Register a first profile on registration"
|
||||
field :register_person, :person do
|
||||
arg(:preferred_username, non_null(:string))
|
||||
|
||||
arg(:name, :string, description: "The displayed name for the new profile", default_value: "")
|
||||
|
||||
arg(:summary, :string, description: "The summary for the new profile", default_value: "")
|
||||
arg(:email, non_null(:string), description: "The email from the user previously created")
|
||||
|
||||
arg(:avatar, :picture_input,
|
||||
description:
|
||||
"The avatar for the profile, either as an object or directly the ID of an existing Picture"
|
||||
)
|
||||
|
||||
arg(:banner, :picture_input,
|
||||
description:
|
||||
"The banner for the profile, either as an object or directly the ID of an existing Picture"
|
||||
)
|
||||
|
||||
resolve(handle_errors(&Person.register_person/3))
|
||||
end
|
||||
end
|
||||
|
||||
object :person_subscriptions do
|
||||
field :event_person_participation_changed, :person do
|
||||
arg(:person_id, non_null(:id))
|
||||
|
||||
config(fn args, _ ->
|
||||
{:ok, topic: args.person_id}
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user