2020-01-26 19:34:25 +00:00
|
|
|
defmodule Mobilizon.GraphQL.Schema do
|
2019-01-03 13:59:59 +00:00
|
|
|
@moduledoc """
|
2019-09-22 14:26:23 +00:00
|
|
|
GraphQL schema representation.
|
2019-01-03 13:59:59 +00:00
|
|
|
"""
|
2019-09-22 14:26:23 +00:00
|
|
|
|
2018-11-06 09:30:27 +00:00
|
|
|
use Absinthe.Schema
|
|
|
|
|
2020-06-25 16:47:17 +00:00
|
|
|
alias Mobilizon.{
|
|
|
|
Actors,
|
|
|
|
Addresses,
|
2020-07-09 15:24:28 +00:00
|
|
|
Discussions,
|
2020-06-25 16:47:17 +00:00
|
|
|
Events,
|
|
|
|
Media,
|
|
|
|
Reports,
|
|
|
|
Resources,
|
|
|
|
Todos,
|
|
|
|
Users
|
|
|
|
}
|
|
|
|
|
2018-11-23 14:03:53 +00:00
|
|
|
alias Mobilizon.Actors.{Actor, Follower, Member}
|
2020-07-09 15:24:28 +00:00
|
|
|
alias Mobilizon.Discussions.Comment
|
2020-02-18 07:57:00 +00:00
|
|
|
alias Mobilizon.Events.{Event, Participant}
|
2023-03-17 17:10:59 +00:00
|
|
|
alias Mobilizon.GraphQL.{Authorization, Schema}
|
2022-11-06 10:57:53 +00:00
|
|
|
alias Mobilizon.GraphQL.Middleware.{CurrentActorProvider, ErrorHandler, OperationNameLogger}
|
2022-03-28 15:42:59 +00:00
|
|
|
alias Mobilizon.GraphQL.Schema.Custom
|
2019-09-17 22:18:45 +00:00
|
|
|
alias Mobilizon.Storage.Repo
|
2018-11-06 09:30:27 +00:00
|
|
|
|
2022-03-28 15:42:59 +00:00
|
|
|
@pipeline_modifier Custom.EnumTypes
|
|
|
|
|
2018-11-06 09:30:27 +00:00
|
|
|
import_types(Absinthe.Type.Custom)
|
|
|
|
import_types(Absinthe.Plug.Types)
|
2022-03-28 15:42:59 +00:00
|
|
|
import_types(Custom.UUID)
|
|
|
|
import_types(Custom.Point)
|
2023-06-05 07:12:02 +00:00
|
|
|
import_types(Custom.Timezone)
|
2018-11-06 09:30:27 +00:00
|
|
|
|
2021-02-24 18:06:48 +00:00
|
|
|
import_types(Schema.ActivityType)
|
2020-01-26 19:34:25 +00:00
|
|
|
import_types(Schema.UserType)
|
2020-11-26 10:41:13 +00:00
|
|
|
import_types(Schema.MediaType)
|
2020-01-26 19:34:25 +00:00
|
|
|
import_types(Schema.ActorInterface)
|
|
|
|
import_types(Schema.Actors.PersonType)
|
|
|
|
import_types(Schema.Actors.GroupType)
|
|
|
|
import_types(Schema.Actors.ApplicationType)
|
2020-07-09 15:24:28 +00:00
|
|
|
import_types(Schema.Discussions.CommentType)
|
|
|
|
import_types(Schema.Discussions.DiscussionType)
|
2020-01-26 19:34:25 +00:00
|
|
|
import_types(Schema.SearchType)
|
2020-02-18 07:57:00 +00:00
|
|
|
import_types(Schema.ResourceType)
|
2020-07-09 15:24:28 +00:00
|
|
|
import_types(Schema.PostType)
|
2020-02-18 07:57:00 +00:00
|
|
|
import_types(Schema.Todos.TodoListType)
|
|
|
|
import_types(Schema.Todos.TodoType)
|
2020-01-26 19:34:25 +00:00
|
|
|
import_types(Schema.ConfigType)
|
|
|
|
import_types(Schema.ReportType)
|
|
|
|
import_types(Schema.AdminType)
|
2020-06-19 17:27:10 +00:00
|
|
|
import_types(Schema.StatisticsType)
|
2021-05-06 16:39:59 +00:00
|
|
|
import_types(Schema.Users.PushSubscription)
|
2021-06-01 16:08:03 +00:00
|
|
|
import_types(Schema.Users.ActivitySetting)
|
2021-10-29 08:42:37 +00:00
|
|
|
import_types(Schema.FollowedGroupActivityType)
|
2023-02-15 18:31:23 +00:00
|
|
|
import_types(Schema.AuthApplicationType)
|
2023-10-17 14:41:31 +00:00
|
|
|
import_types(Schema.ConversationType)
|
2018-11-23 14:03:53 +00:00
|
|
|
|
2019-01-25 08:23:44 +00:00
|
|
|
@desc "A struct containing the id of the deleted object"
|
|
|
|
object :deleted_object do
|
2023-03-17 17:10:59 +00:00
|
|
|
meta(:authorize, :all)
|
2019-09-09 07:31:08 +00:00
|
|
|
field(:id, :id)
|
2019-01-25 08:23:44 +00:00
|
|
|
end
|
|
|
|
|
2018-11-06 09:30:27 +00:00
|
|
|
@desc "A JWT and the associated user ID"
|
|
|
|
object :login do
|
2023-03-17 17:10:59 +00:00
|
|
|
meta(:authorize, :all)
|
2019-08-12 14:04:16 +00:00
|
|
|
field(:access_token, non_null(:string), description: "A JWT Token for this session")
|
2019-08-12 15:41:41 +00:00
|
|
|
|
|
|
|
field(:refresh_token, non_null(:string),
|
|
|
|
description: "A JWT Token to refresh the access token"
|
|
|
|
)
|
|
|
|
|
2018-11-23 14:03:53 +00:00
|
|
|
field(:user, non_null(:user), description: "The user associated to this session")
|
2018-11-06 09:30:27 +00:00
|
|
|
end
|
|
|
|
|
2018-11-23 14:03:53 +00:00
|
|
|
@desc """
|
|
|
|
Represents a notification for an user
|
|
|
|
"""
|
|
|
|
object :notification do
|
2023-03-17 17:10:59 +00:00
|
|
|
meta(:authorize, :user)
|
2019-09-09 07:31:08 +00:00
|
|
|
field(:id, :id, description: "The notification ID")
|
2018-11-23 14:03:53 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
def context(ctx) do
|
2019-09-17 22:18:45 +00:00
|
|
|
default_query = fn queryable, _params -> queryable end
|
|
|
|
default_source = Dataloader.Ecto.new(Repo, query: default_query)
|
|
|
|
|
2018-11-06 09:30:27 +00:00
|
|
|
loader =
|
|
|
|
Dataloader.new()
|
2019-09-17 22:18:45 +00:00
|
|
|
|> Dataloader.add_source(Actors, default_source)
|
|
|
|
|> Dataloader.add_source(Users, default_source)
|
2020-02-18 07:57:00 +00:00
|
|
|
|> Dataloader.add_source(Events, default_source)
|
2020-07-09 15:24:28 +00:00
|
|
|
|> Dataloader.add_source(Discussions, Discussions.data())
|
2019-09-17 22:18:45 +00:00
|
|
|
|> Dataloader.add_source(Addresses, default_source)
|
|
|
|
|> Dataloader.add_source(Media, default_source)
|
2019-09-21 21:59:07 +00:00
|
|
|
|> Dataloader.add_source(Reports, default_source)
|
2020-06-25 16:47:17 +00:00
|
|
|
|> Dataloader.add_source(Resources, default_source)
|
2020-02-18 07:57:00 +00:00
|
|
|
|> Dataloader.add_source(Todos, default_source)
|
2018-11-06 09:30:27 +00:00
|
|
|
|
2023-03-17 17:10:59 +00:00
|
|
|
ctx
|
|
|
|
|> Map.put(:loader, loader)
|
|
|
|
|> Map.put(:authorization, Authorization)
|
2018-11-06 09:30:27 +00:00
|
|
|
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
|
2019-04-12 13:04:32 +00:00
|
|
|
import_fields(:search_queries)
|
2019-01-25 14:41:10 +00:00
|
|
|
import_fields(:user_queries)
|
|
|
|
import_fields(:person_queries)
|
|
|
|
import_fields(:group_queries)
|
|
|
|
import_fields(:event_queries)
|
2019-11-15 17:36:47 +00:00
|
|
|
import_fields(:comment_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)
|
2019-03-22 09:53:38 +00:00
|
|
|
import_fields(:config_queries)
|
2020-11-26 10:41:13 +00:00
|
|
|
import_fields(:media_queries)
|
2019-07-23 11:49:22 +00:00
|
|
|
import_fields(:report_queries)
|
|
|
|
import_fields(:admin_queries)
|
2020-02-18 07:57:00 +00:00
|
|
|
import_fields(:todo_list_queries)
|
|
|
|
import_fields(:todo_queries)
|
2020-07-09 15:24:28 +00:00
|
|
|
import_fields(:discussion_queries)
|
2023-10-17 14:41:31 +00:00
|
|
|
import_fields(:conversation_queries)
|
2020-02-18 07:57:00 +00:00
|
|
|
import_fields(:resource_queries)
|
2020-07-09 15:24:28 +00:00
|
|
|
import_fields(:post_queries)
|
2020-06-19 17:27:10 +00:00
|
|
|
import_fields(:statistics_queries)
|
2023-02-15 18:31:23 +00:00
|
|
|
import_fields(:auth_application_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)
|
2020-11-26 10:41:13 +00:00
|
|
|
import_fields(:media_mutations)
|
2019-07-23 11:49:22 +00:00
|
|
|
import_fields(:report_mutations)
|
2019-12-03 10:29:51 +00:00
|
|
|
import_fields(:admin_mutations)
|
2020-02-18 07:57:00 +00:00
|
|
|
import_fields(:todo_list_mutations)
|
|
|
|
import_fields(:todo_mutations)
|
2020-07-09 15:24:28 +00:00
|
|
|
import_fields(:discussion_mutations)
|
2023-10-17 14:41:31 +00:00
|
|
|
import_fields(:conversation_mutations)
|
2020-02-18 07:57:00 +00:00
|
|
|
import_fields(:resource_mutations)
|
2020-07-09 15:24:28 +00:00
|
|
|
import_fields(:post_mutations)
|
2020-08-27 09:53:24 +00:00
|
|
|
import_fields(:actor_mutations)
|
2021-01-20 17:16:44 +00:00
|
|
|
import_fields(:follower_mutations)
|
2021-05-06 16:39:59 +00:00
|
|
|
import_fields(:push_mutations)
|
2021-06-01 16:08:03 +00:00
|
|
|
import_fields(:activity_setting_mutations)
|
2023-02-15 18:31:23 +00:00
|
|
|
import_fields(:auth_application_mutations)
|
2019-12-03 10:29:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
@desc """
|
|
|
|
Root subscription
|
|
|
|
"""
|
|
|
|
subscription do
|
|
|
|
import_fields(:person_subscriptions)
|
2020-07-09 15:24:28 +00:00
|
|
|
import_fields(:discussion_subscriptions)
|
2023-10-17 14:41:31 +00:00
|
|
|
import_fields(:conversation_subscriptions)
|
2018-11-06 09:30:27 +00:00
|
|
|
end
|
2020-10-01 13:07:15 +00:00
|
|
|
|
2021-09-28 17:40:37 +00:00
|
|
|
@spec middleware(list(module()), any(), map()) :: list(module())
|
2023-03-17 17:10:59 +00:00
|
|
|
def middleware(middleware, field, %{identifier: type}) when type in [:query, :mutation] do
|
|
|
|
[CurrentActorProvider | middleware]
|
|
|
|
|> Enum.map(&fix_middleware_format_for_rajska/1)
|
|
|
|
|> Rajska.add_query_authorization(field, Authorization)
|
|
|
|
|> Rajska.add_object_authorization()
|
|
|
|
|> List.insert_at(-1, ErrorHandler)
|
|
|
|
|> List.insert_at(-1, OperationNameLogger)
|
2020-10-01 13:07:15 +00:00
|
|
|
end
|
|
|
|
|
2023-03-17 17:10:59 +00:00
|
|
|
def middleware(middleware, field, object) do
|
|
|
|
Rajska.add_field_authorization(middleware, field, object)
|
2020-10-01 13:07:15 +00:00
|
|
|
end
|
2023-03-17 17:10:59 +00:00
|
|
|
|
|
|
|
defp fix_middleware_format_for_rajska({mod, config}), do: {mod, config}
|
|
|
|
defp fix_middleware_format_for_rajska(mod), do: {mod, nil}
|
2018-11-06 09:30:27 +00:00
|
|
|
end
|