2018-11-06 09:30:27 +00:00
|
|
|
defmodule MobilizonWeb.Schema do
|
2019-01-03 13:59:59 +00:00
|
|
|
@moduledoc """
|
|
|
|
GraphQL schema representation
|
|
|
|
"""
|
2018-11-06 09:30:27 +00:00
|
|
|
use Absinthe.Schema
|
|
|
|
|
2019-03-08 17:52:27 +00:00
|
|
|
alias Mobilizon.{Actors, Events, Users}
|
2018-11-23 14:03:53 +00:00
|
|
|
alias Mobilizon.Actors.{Actor, Follower, Member}
|
|
|
|
alias Mobilizon.Events.{Event, Comment, Participant}
|
2018-11-06 09:30:27 +00:00
|
|
|
|
|
|
|
import_types(MobilizonWeb.Schema.Custom.UUID)
|
2019-01-14 16:13:17 +00:00
|
|
|
import_types(MobilizonWeb.Schema.Custom.Point)
|
2018-11-06 09:30:27 +00:00
|
|
|
import_types(Absinthe.Type.Custom)
|
|
|
|
import_types(Absinthe.Plug.Types)
|
|
|
|
|
2019-01-25 14:41:10 +00:00
|
|
|
import_types(MobilizonWeb.Schema.UserType)
|
2019-01-14 16:13:17 +00:00
|
|
|
import_types(MobilizonWeb.Schema.ActorInterface)
|
|
|
|
import_types(MobilizonWeb.Schema.Actors.PersonType)
|
|
|
|
import_types(MobilizonWeb.Schema.Actors.GroupType)
|
|
|
|
import_types(MobilizonWeb.Schema.CommentType)
|
2018-11-23 14:03:53 +00:00
|
|
|
|
2019-01-14 16:13:17 +00:00
|
|
|
alias MobilizonWeb.Resolvers
|
2018-11-06 09:30:27 +00:00
|
|
|
|
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
|
|
|
|
|
2018-11-06 09:30:27 +00:00
|
|
|
@desc "A JWT and the associated user ID"
|
|
|
|
object :login do
|
2018-11-23 14:03:53 +00:00
|
|
|
field(:token, non_null(:string), description: "A JWT Token for this session")
|
|
|
|
field(:user, non_null(:user), description: "The user associated to this session")
|
2018-11-06 09:30:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
@desc "A picture"
|
|
|
|
object :picture do
|
2018-11-23 14:03:53 +00:00
|
|
|
field(:url, :string, description: "The URL for this picture")
|
|
|
|
field(:url_thumbnail, :string, description: "The URL for this picture's thumbnail")
|
|
|
|
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)
|
2018-11-06 09:30:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
@desc "A search result"
|
|
|
|
union :search_result do
|
2018-11-23 14:03:53 +00:00
|
|
|
types([:event, :person, :group])
|
2018-11-06 09:30:27 +00:00
|
|
|
|
|
|
|
resolve_type(fn
|
2018-11-23 14:03:53 +00:00
|
|
|
%Actor{type: :Person}, _ ->
|
|
|
|
:person
|
|
|
|
|
|
|
|
%Actor{type: :Group}, _ ->
|
|
|
|
:group
|
2018-11-06 09:30:27 +00:00
|
|
|
|
|
|
|
%Event{}, _ ->
|
|
|
|
:event
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
def context(ctx) do
|
|
|
|
loader =
|
|
|
|
Dataloader.new()
|
|
|
|
|> Dataloader.add_source(Actors, Actors.data())
|
2019-03-08 17:52:27 +00:00
|
|
|
|> Dataloader.add_source(Users, Users.data())
|
2018-11-06 09:30:27 +00:00
|
|
|
|> Dataloader.add_source(Events, Events.data())
|
|
|
|
|
|
|
|
Map.put(ctx, :loader, loader)
|
|
|
|
end
|
|
|
|
|
|
|
|
def plugins do
|
2019-01-21 14:08:22 +00:00
|
|
|
[Absinthe.Middleware.Dataloader] ++ Absinthe.Plugin.defaults()
|
2018-11-06 09:30:27 +00:00
|
|
|
end
|
|
|
|
|
2018-11-23 14:03:53 +00:00
|
|
|
@desc """
|
|
|
|
Root Query
|
|
|
|
"""
|
2018-11-06 09:30:27 +00:00
|
|
|
query do
|
2018-11-23 14:03:53 +00:00
|
|
|
@desc "Search through events, persons and groups"
|
2018-11-06 09:30:27 +00:00
|
|
|
field :search, list_of(:search_result) do
|
|
|
|
arg(:search, non_null(:string))
|
|
|
|
arg(:page, :integer, default_value: 1)
|
|
|
|
arg(:limit, :integer, default_value: 10)
|
2019-02-21 17:11:49 +00:00
|
|
|
resolve(&Resolvers.Search.search_events_and_actors/3)
|
2018-11-06 09:30:27 +00:00
|
|
|
end
|
|
|
|
|
2019-01-25 14:41:10 +00:00
|
|
|
import_fields(:user_queries)
|
|
|
|
import_fields(:person_queries)
|
|
|
|
import_fields(:group_queries)
|
|
|
|
import_fields(:event_queries)
|
|
|
|
import_fields(:participant_queries)
|
2019-02-22 17:07:20 +00:00
|
|
|
import_fields(:tag_queries)
|
2019-03-14 17:31:14 +00:00
|
|
|
import_fields(:address_queries)
|
2018-11-06 09:30:27 +00:00
|
|
|
end
|
|
|
|
|
2018-11-23 14:03:53 +00:00
|
|
|
@desc """
|
|
|
|
Root Mutation
|
|
|
|
"""
|
2018-11-06 09:30:27 +00:00
|
|
|
mutation do
|
2019-01-25 14:41:10 +00:00
|
|
|
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)
|
2019-03-08 17:52:27 +00:00
|
|
|
import_fields(:feed_token_mutations)
|
2018-12-03 10:58:57 +00:00
|
|
|
|
2018-11-12 17:17:53 +00:00
|
|
|
# @desc "Upload a picture"
|
|
|
|
# field :upload_picture, :picture do
|
|
|
|
# arg(:file, non_null(:upload))
|
|
|
|
# resolve(&Resolvers.Upload.upload_picture/3)
|
|
|
|
# end
|
2018-11-06 09:30:27 +00:00
|
|
|
end
|
|
|
|
end
|