1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-26 09:49:12 +00:00
mobilizon/lib/mobilizon_web/schema.ex

139 lines
3.9 KiB
Elixir
Raw Normal View History

defmodule MobilizonWeb.Schema do
@moduledoc """
GraphQL schema representation
"""
use Absinthe.Schema
alias Mobilizon.{Actors, Events, Users, Addresses, Media}
alias Mobilizon.Actors.{Actor, Follower, Member}
alias Mobilizon.Events.{Event, Comment, Participant}
import_types(MobilizonWeb.Schema.Custom.UUID)
import_types(MobilizonWeb.Schema.Custom.Point)
import_types(Absinthe.Type.Custom)
import_types(Absinthe.Plug.Types)
import_types(MobilizonWeb.Schema.UserType)
import_types(MobilizonWeb.Schema.PictureType)
import_types(MobilizonWeb.Schema.ActorInterface)
import_types(MobilizonWeb.Schema.Actors.PersonType)
import_types(MobilizonWeb.Schema.Actors.GroupType)
import_types(MobilizonWeb.Schema.CommentType)
import_types(MobilizonWeb.Schema.SearchType)
2019-03-22 09:53:38 +00:00
import_types(MobilizonWeb.Schema.ConfigType)
import_types(MobilizonWeb.Schema.ReportType)
import_types(MobilizonWeb.Schema.AdminType)
2019-01-25 08:23:44 +00:00
@desc "A struct containing the id of the deleted object"
object :deleted_object do
field(:id, :integer)
end
@desc "A JWT and the associated user ID"
object :login do
2019-08-12 14:04:16 +00:00
field(:access_token, non_null(:string), description: "A JWT Token for this session")
field(:refresh_token, non_null(:string),
description: "A JWT Token to refresh the access token"
)
field(:user, non_null(:user), description: "The user associated to this session")
end
@desc """
Represents a notification for an user
"""
object :notification do
field(:id, :integer, description: "The notification ID")
field(:user, :user, description: "The user to transmit the notification to")
field(:actor, :actor, description: "The notification target profile")
field(:activity_type, :integer,
description:
"Whether the notification is about a follow, group join, event change or comment"
)
field(:target_object, :object, description: "The object responsible for the notification")
field(:summary, :string, description: "Text inside the notification")
field(:seen, :boolean, description: "Whether or not the notification was seen by the user")
field(:published, :datetime, description: "Datetime when the notification was published")
end
union :object do
types([:event, :person, :group, :comment, :follower, :member, :participant])
resolve_type(fn
%Actor{type: :Person}, _ ->
:person
%Actor{type: :Group}, _ ->
:group
%Event{}, _ ->
:event
%Comment{}, _ ->
:comment
%Follower{}, _ ->
:follower
%Member{}, _ ->
:member
%Participant{}, _ ->
:participant
end)
end
def context(ctx) do
loader =
Dataloader.new()
|> Dataloader.add_source(Actors, Actors.data())
|> Dataloader.add_source(Users, Users.data())
|> Dataloader.add_source(Events, Events.data())
|> Dataloader.add_source(Addresses, Addresses.data())
|> Dataloader.add_source(Media, Media.data())
Map.put(ctx, :loader, loader)
end
def plugins do
[Absinthe.Middleware.Dataloader] ++ Absinthe.Plugin.defaults()
end
@desc """
Root Query
"""
query do
import_fields(:search_queries)
import_fields(:user_queries)
import_fields(:person_queries)
import_fields(:group_queries)
import_fields(:event_queries)
import_fields(:participant_queries)
import_fields(:tag_queries)
import_fields(:address_queries)
2019-03-22 09:53:38 +00:00
import_fields(:config_queries)
import_fields(:picture_queries)
import_fields(:report_queries)
import_fields(:admin_queries)
end
@desc """
Root Mutation
"""
mutation do
import_fields(:user_mutations)
import_fields(:person_mutations)
import_fields(:group_mutations)
import_fields(:event_mutations)
import_fields(:comment_mutations)
2019-02-01 14:38:35 +00:00
import_fields(:participant_mutations)
2019-03-01 16:11:28 +00:00
import_fields(:member_mutations)
import_fields(:feed_token_mutations)
import_fields(:picture_mutations)
import_fields(:report_mutations)
end
end