Split GraphQL as separate context

This commit is contained in:
rustra 2020-01-26 20:34:25 +01:00
parent a7acf17a4a
commit ba3ad713c0
55 changed files with 292 additions and 269 deletions

View File

@ -1,6 +1,6 @@
defmodule MobilizonWeb.Schema.Utils do
defmodule Mobilizon.GraphQL.Helpers.Error do
@moduledoc """
Helper functions for MobilizonWeb.Schema
Helper functions for Mobilizon.GraphQL
"""
def handle_errors(fun) do

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Resolvers.Address do
defmodule Mobilizon.GraphQL.Resolvers.Address do
@moduledoc """
Handles the comment-related GraphQL calls
"""
@ -11,10 +11,12 @@ defmodule MobilizonWeb.Resolvers.Address do
@doc """
Search an address
"""
@spec search(map(), map(), map()) :: {:ok, list(Address.t())}
def search(_parent, %{query: query, locale: locale, page: _page, limit: _limit}, %{
context: %{ip: ip}
}) do
@spec search(map, map, map) :: {:ok, [Address.t()]}
def search(
_parent,
%{query: query, locale: locale, page: _page, limit: _limit},
%{context: %{ip: ip}}
) do
geolix = Geolix.lookup(ip)
country_code =
@ -31,7 +33,7 @@ defmodule MobilizonWeb.Resolvers.Address do
@doc """
Reverse geocode some coordinates
"""
@spec reverse_geocode(map(), map(), map()) :: {:ok, list(Address.t())}
@spec reverse_geocode(map, map, map) :: {:ok, [Address.t()]}
def reverse_geocode(
_parent,
%{longitude: longitude, latitude: latitude, zoom: zoom, locale: locale},

View File

@ -1,13 +1,13 @@
defmodule MobilizonWeb.Resolvers.Admin do
defmodule Mobilizon.GraphQL.Resolvers.Admin do
@moduledoc """
Handles the report-related GraphQL calls.
"""
import Mobilizon.Users.Guards
alias Mobilizon.Admin.ActionLog
alias Mobilizon.Actors
alias Mobilizon.Actors.Actor
alias Mobilizon.Admin.ActionLog
alias Mobilizon.Events
alias Mobilizon.Events.{Event, Comment}
alias Mobilizon.Reports.{Note, Report}
@ -68,36 +68,28 @@ defmodule MobilizonWeb.Resolvers.Admin do
end
end
defp transform_action_log(Note, :create, %ActionLog{
changes: changes
}) do
defp transform_action_log(Note, :create, %ActionLog{changes: changes}) do
%{
action: :note_creation,
object: convert_changes_to_struct(Note, changes)
}
end
defp transform_action_log(Note, :delete, %ActionLog{
changes: changes
}) do
defp transform_action_log(Note, :delete, %ActionLog{changes: changes}) do
%{
action: :note_deletion,
object: convert_changes_to_struct(Note, changes)
}
end
defp transform_action_log(Event, :delete, %ActionLog{
changes: changes
}) do
defp transform_action_log(Event, :delete, %ActionLog{changes: changes}) do
%{
action: :event_deletion,
object: convert_changes_to_struct(Event, changes)
}
end
defp transform_action_log(Comment, :delete, %ActionLog{
changes: changes
}) do
defp transform_action_log(Comment, :delete, %ActionLog{changes: changes}) do
%{
action: :comment_deletion,
object: convert_changes_to_struct(Comment, changes)
@ -118,9 +110,7 @@ defmodule MobilizonWeb.Resolvers.Admin do
end
end
def get_dashboard(_parent, _args, %{
context: %{current_user: %User{role: role}}
})
def get_dashboard(_parent, _args, %{context: %{current_user: %User{role: role}}})
when is_admin(role) do
last_public_event_published =
case Events.list_events(1, 1, :inserted_at, :desc) do
@ -142,9 +132,11 @@ defmodule MobilizonWeb.Resolvers.Admin do
{:error, "You need to be logged-in and an administrator to access dashboard statistics"}
end
def list_relay_followers(_parent, %{page: page, limit: limit}, %{
context: %{current_user: %User{role: role}}
})
def list_relay_followers(
_parent,
%{page: page, limit: limit},
%{context: %{current_user: %User{role: role}}}
)
when is_admin(role) do
with %Actor{} = relay_actor <- Relay.get_actor() do
%Page{} =
@ -154,9 +146,11 @@ defmodule MobilizonWeb.Resolvers.Admin do
end
end
def list_relay_followings(_parent, %{page: page, limit: limit}, %{
context: %{current_user: %User{role: role}}
})
def list_relay_followings(
_parent,
%{page: page, limit: limit},
%{context: %{current_user: %User{role: role}}}
)
when is_admin(role) do
with %Actor{} = relay_actor <- Relay.get_actor() do
%Page{} =
@ -188,9 +182,11 @@ defmodule MobilizonWeb.Resolvers.Admin do
end
end
def accept_subscription(_parent, %{address: address}, %{
context: %{current_user: %User{role: role}}
})
def accept_subscription(
_parent,
%{address: address},
%{context: %{current_user: %User{role: role}}}
)
when is_admin(role) do
case Relay.accept(address) do
{:ok, _activity, follow} ->
@ -201,9 +197,11 @@ defmodule MobilizonWeb.Resolvers.Admin do
end
end
def reject_subscription(_parent, %{address: address}, %{
context: %{current_user: %User{role: role}}
})
def reject_subscription(
_parent,
%{address: address},
%{context: %{current_user: %User{role: role}}}
)
when is_admin(role) do
case Relay.reject(address) do
{:ok, _activity, follow} ->

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Resolvers.Comment do
defmodule Mobilizon.GraphQL.Resolvers.Comment do
@moduledoc """
Handles the comment-related GraphQL calls.
"""
@ -17,9 +17,11 @@ defmodule MobilizonWeb.Resolvers.Comment do
{:ok, Events.get_thread_replies(thread_id)}
end
def create_comment(_parent, %{actor_id: actor_id} = args, %{
context: %{current_user: %User{} = user}
}) do
def create_comment(
_parent,
%{actor_id: actor_id} = args,
%{context: %{current_user: %User{} = user}}
) do
with {:is_owned, %Actor{} = _organizer_actor} <- User.owns_actor(user, actor_id),
{:ok, _, %CommentModel{} = comment} <-
Comments.create_comment(args) do
@ -34,9 +36,11 @@ defmodule MobilizonWeb.Resolvers.Comment do
{:error, "You are not allowed to create a comment if not connected"}
end
def delete_comment(_parent, %{actor_id: actor_id, comment_id: comment_id}, %{
context: %{current_user: %User{role: role} = user}
}) do
def delete_comment(
_parent,
%{actor_id: actor_id, comment_id: comment_id},
%{context: %{current_user: %User{role: role} = user}}
) do
with {actor_id, ""} <- Integer.parse(actor_id),
{:is_owned, %Actor{} = _organizer_actor} <- User.owns_actor(user, actor_id),
%CommentModel{} = comment <- Events.get_comment_with_preload(comment_id) do

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Resolvers.Config do
defmodule Mobilizon.GraphQL.Resolvers.Config do
@moduledoc """
Handles the config-related GraphQL calls.
"""
@ -10,9 +10,7 @@ defmodule MobilizonWeb.Resolvers.Config do
@doc """
Gets config.
"""
def get_config(_parent, _params, %{
context: %{ip: ip}
}) do
def get_config(_parent, _params, %{context: %{ip: ip}}) do
geolix = Geolix.lookup(ip)
country_code =

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Resolvers.Event do
defmodule Mobilizon.GraphQL.Resolvers.Event do
@moduledoc """
Handles the event-related GraphQL calls.
"""
@ -8,10 +8,11 @@ defmodule MobilizonWeb.Resolvers.Event do
alias Mobilizon.Events.{Event, Participant, EventParticipantStats}
alias Mobilizon.Users.User
alias Mobilizon.GraphQL.Resolvers.Person
alias Mobilizon.Federation.ActivityPub.Activity
alias MobilizonWeb.API
alias MobilizonWeb.Resolvers.Person
# We limit the max number of events that can be retrieved
@event_max_limit 100
@ -40,8 +41,9 @@ defmodule MobilizonWeb.Resolvers.Event do
end
end
defp find_private_event(_parent, %{uuid: uuid}, _resolution),
do: {:error, "Event with UUID #{uuid} not found"}
defp find_private_event(_parent, %{uuid: uuid}, _resolution) do
{:error, "Event with UUID #{uuid} not found"}
end
def find_event(parent, %{uuid: uuid} = args, resolution) do
case {:has_event, Mobilizon.Events.get_public_event_by_uuid_with_preload(uuid)} do
@ -216,11 +218,7 @@ defmodule MobilizonWeb.Resolvers.Event do
def update_participation(
_parent,
%{id: participation_id, moderator_actor_id: moderator_actor_id, role: new_role},
%{
context: %{
current_user: user
}
}
%{context: %{current_user: user}}
) do
# Check that moderator provided is rightly authenticated
with {:is_owned, moderator_actor} <- User.owns_actor(user, moderator_actor_id),

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Resolvers.FeedToken do
defmodule Mobilizon.GraphQL.Resolvers.FeedToken do
@moduledoc """
Handles the feed tokens-related GraphQL calls.
"""
@ -13,10 +13,12 @@ defmodule MobilizonWeb.Resolvers.FeedToken do
@doc """
Create an feed token for an user and a defined actor
"""
@spec create_feed_token(any(), map(), map()) :: {:ok, FeedToken.t()} | {:error, String.t()}
def create_feed_token(_parent, %{actor_id: actor_id}, %{
context: %{current_user: %User{id: id} = user}
}) do
@spec create_feed_token(any, map, map) :: {:ok, FeedToken.t()} | {:error, String.t()}
def create_feed_token(
_parent,
%{actor_id: actor_id},
%{context: %{current_user: %User{id: id} = user}}
) do
with {:is_owned, %Actor{}} <- User.owns_actor(user, actor_id),
{:ok, feed_token} <- Events.create_feed_token(%{"user_id" => id, "actor_id" => actor_id}) do
{:ok, feed_token}
@ -29,16 +31,14 @@ defmodule MobilizonWeb.Resolvers.FeedToken do
@doc """
Create an feed token for an user
"""
@spec create_feed_token(any(), map(), map()) :: {:ok, FeedToken.t()}
def create_feed_token(_parent, %{}, %{
context: %{current_user: %User{id: id}}
}) do
@spec create_feed_token(any, map, map) :: {:ok, FeedToken.t()}
def create_feed_token(_parent, %{}, %{context: %{current_user: %User{id: id}}}) do
with {:ok, feed_token} <- Events.create_feed_token(%{"user_id" => id}) do
{:ok, feed_token}
end
end
@spec create_feed_token(any(), map(), map()) :: {:error, String.t()}
@spec create_feed_token(any, map, map) :: {:error, String.t()}
def create_feed_token(_parent, _args, %{}) do
{:error, "You are not allowed to create a feed token if not connected"}
end
@ -46,10 +46,12 @@ defmodule MobilizonWeb.Resolvers.FeedToken do
@doc """
Delete a feed token
"""
@spec delete_feed_token(any(), map(), map()) :: {:ok, map()} | {:error, String.t()}
def delete_feed_token(_parent, %{token: token}, %{
context: %{current_user: %User{id: id} = _user}
}) do
@spec delete_feed_token(any, map, map) :: {:ok, map} | {:error, String.t()}
def delete_feed_token(
_parent,
%{token: token},
%{context: %{current_user: %User{id: id} = _user}}
) do
with {:ok, token} <- Ecto.UUID.cast(token),
{:no_token, %FeedToken{actor: actor, user: %User{} = user} = feed_token} <-
{:no_token, Events.get_feed_token(token)},
@ -73,7 +75,7 @@ defmodule MobilizonWeb.Resolvers.FeedToken do
end
end
@spec delete_feed_token(any(), map(), map()) :: {:error, String.t()}
@spec delete_feed_token(any, map, map) :: {:error, String.t()}
def delete_feed_token(_parent, _args, %{}) do
{:error, "You are not allowed to delete a feed token if not connected"}
end

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Resolvers.Group do
defmodule Mobilizon.GraphQL.Resolvers.Group do
@moduledoc """
Handles the group-related GraphQL calls.
"""
@ -7,10 +7,11 @@ defmodule MobilizonWeb.Resolvers.Group do
alias Mobilizon.Actors.{Actor, Member}
alias Mobilizon.Users.User
alias Mobilizon.GraphQL.Resolvers.Person
alias Mobilizon.Federation.ActivityPub
alias MobilizonWeb.API
alias MobilizonWeb.Resolvers.Person
require Logger
@ -42,11 +43,7 @@ defmodule MobilizonWeb.Resolvers.Group do
@doc """
Create a new group. The creator is automatically added as admin
"""
def create_group(
_parent,
args,
%{context: %{current_user: user}}
) do
def create_group(_parent, args, %{context: %{current_user: user}}) do
with creator_actor_id <- Map.get(args, :creator_actor_id),
{:is_owned, %Actor{} = creator_actor} <- User.owns_actor(user, creator_actor_id),
args <- Map.put(args, :creator_actor, creator_actor),
@ -180,7 +177,7 @@ defmodule MobilizonWeb.Resolvers.Group do
# We check that the actor asking to leave the group is not it's only administrator
# We start by fetching the list of administrator or creators and if there's only one of them
# and that it's the actor requesting leaving the group we return true
@spec check_that_member_is_not_last_administrator(integer(), integer()) :: boolean()
@spec check_that_member_is_not_last_administrator(integer, integer) :: boolean
defp check_that_member_is_not_last_administrator(group_id, actor_id) do
case Actors.list_administrator_members_for_group(group_id) do
[%Member{actor: %Actor{id: member_actor_id}}] ->

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Resolvers.Member do
defmodule Mobilizon.GraphQL.Resolvers.Member do
@moduledoc """
Handles the member-related GraphQL calls
"""

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Resolvers.Person do
defmodule Mobilizon.GraphQL.Resolvers.Person do
@moduledoc """
Handles the person-related GraphQL calls
"""
@ -191,9 +191,11 @@ defmodule MobilizonWeb.Resolvers.Person do
@doc """
Returns the participation for a specific event
"""
def person_participations(%Actor{id: actor_id}, %{event_id: event_id}, %{
context: %{current_user: user}
}) do
def person_participations(
%Actor{id: actor_id},
%{event_id: event_id},
%{context: %{current_user: user}}
) do
with {:is_owned, %Actor{} = _actor} <- User.owns_actor(user, actor_id),
{:no_participant, {:ok, %Participant{} = participant}} <-
{:no_participant, Events.get_participant(event_id, actor_id)} do

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Resolvers.Picture do
defmodule Mobilizon.GraphQL.Resolvers.Picture do
@moduledoc """
Handles the picture-related GraphQL calls
"""
@ -44,7 +44,7 @@ defmodule MobilizonWeb.Resolvers.Picture do
end
end
@spec upload_picture(map(), map(), map()) :: {:ok, Picture.t()} | {:error, any()}
@spec upload_picture(map, map, map) :: {:ok, Picture.t()} | {:error, any}
def upload_picture(
_parent,
%{file: %Plug.Upload{} = file, actor_id: actor_id} = args,

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Resolvers.Report do
defmodule Mobilizon.GraphQL.Resolvers.Report do
@moduledoc """
Handles the report-related GraphQL calls.
"""

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Resolvers.Search do
defmodule Mobilizon.GraphQL.Resolvers.Search do
@moduledoc """
Handles the event-related GraphQL calls
"""

View File

@ -1,10 +1,9 @@
defmodule MobilizonWeb.Resolvers.Tag do
defmodule Mobilizon.GraphQL.Resolvers.Tag do
@moduledoc """
Handles the tag-related GraphQL calls
"""
alias Mobilizon.Events
alias Mobilizon.Events.Event
alias Mobilizon.Events.Tag
alias Mobilizon.Events.{Event, Tag}
def list_tags(_parent, %{page: page, limit: limit}, _resolution) do
tags = Mobilizon.Events.list_tags(page, limit)

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Resolvers.User do
defmodule Mobilizon.GraphQL.Resolvers.User do
@moduledoc """
Handles the user-related GraphQL calls.
"""
@ -24,15 +24,7 @@ defmodule MobilizonWeb.Resolvers.User do
@doc """
Return current logged-in user
"""
def get_current_user(
_parent,
_args,
%{
context: %{
current_user: user
}
}
) do
def get_current_user(_parent, _args, %{context: %{current_user: user}}) do
{:ok, user}
end
@ -46,13 +38,7 @@ defmodule MobilizonWeb.Resolvers.User do
def list_and_count_users(
_parent,
%{page: page, limit: limit, sort: sort, direction: direction},
%{
context: %{
current_user: %User{
role: role
}
}
}
%{context: %{current_user: %User{role: role}}}
)
when is_moderator(role) do
total = Task.async(&Users.count_users/0)
@ -61,8 +47,9 @@ defmodule MobilizonWeb.Resolvers.User do
{:ok, %{total: Task.await(total), elements: Task.await(elements)}}
end
def list_and_count_users(_parent, _args, _resolution),
do: {:error, "You need to have admin access to list users"}
def list_and_count_users(_parent, _args, _resolution) do
{:error, "You need to have admin access to list users"}
end
@doc """
Login an user. Returns a token and the user
@ -87,13 +74,7 @@ defmodule MobilizonWeb.Resolvers.User do
@doc """
Refresh a token
"""
def refresh_token(
_parent,
%{
refresh_token: refresh_token
},
_context
) do
def refresh_token(_parent, %{refresh_token: refresh_token}, _context) do
with {:ok, user, _claims} <- Auth.Guardian.resource_from_token(refresh_token),
{:ok, _old, {exchanged_token, _claims}} <-
Auth.Guardian.exchange(refresh_token, ["access", "refresh"], "access"),
@ -106,8 +87,9 @@ defmodule MobilizonWeb.Resolvers.User do
end
end
def refresh_token(_parent, _params, _context),
do: {:error, "You need to have an existing token to get a refresh token"}
def refresh_token(_parent, _params, _context) do
{:error, "You need to have an existing token to get a refresh token"}
end
@doc """
Register an user:
@ -115,7 +97,7 @@ defmodule MobilizonWeb.Resolvers.User do
- create the user
- send a validation email to the user
"""
@spec create_user(any(), map(), any()) :: tuple()
@spec create_user(any, map, any) :: tuple
def create_user(_parent, args, _resolution) do
with :registration_ok <- check_registration_config(args),
{:ok, %User{} = user} <- Users.register(args) do
@ -133,7 +115,7 @@ defmodule MobilizonWeb.Resolvers.User do
end
end
@spec check_registration_config(map()) :: atom()
@spec check_registration_config(map) :: atom
defp check_registration_config(%{email: email}) do
cond do
Config.instance_registrations_open?() ->
@ -176,6 +158,7 @@ defmodule MobilizonWeb.Resolvers.User do
error ->
Logger.info("Unable to validate user with token #{token}")
Logger.debug(inspect(error))
{:error, "Unable to validate user"}
end
end
@ -253,9 +236,11 @@ defmodule MobilizonWeb.Resolvers.User do
@doc """
Returns the list of events for all of this user's identities are going to
"""
def user_participations(%User{id: user_id}, args, %{
context: %{current_user: %User{id: logged_user_id}}
}) do
def user_participations(
%User{id: user_id},
args,
%{context: %{current_user: %User{id: logged_user_id}}}
) do
with true <- user_id == logged_user_id,
participations <-
Events.list_participations_for_user(
@ -272,9 +257,11 @@ defmodule MobilizonWeb.Resolvers.User do
@doc """
Returns the list of draft events for the current user
"""
def user_drafted_events(%User{id: user_id}, args, %{
context: %{current_user: %User{id: logged_user_id}}
}) do
def user_drafted_events(
%User{id: user_id},
args,
%{context: %{current_user: %User{id: logged_user_id}}}
) do
with {:same_user, true} <- {:same_user, user_id == logged_user_id},
events <-
Events.list_drafts_for_user(user_id, Map.get(args, :page), Map.get(args, :limit)) do
@ -282,17 +269,17 @@ defmodule MobilizonWeb.Resolvers.User do
end
end
def change_password(_parent, %{old_password: old_password, new_password: new_password}, %{
context: %{current_user: %User{password_hash: old_password_hash} = user}
}) do
def change_password(
_parent,
%{old_password: old_password, new_password: new_password},
%{context: %{current_user: %User{password_hash: old_password_hash} = user}}
) do
with {:current_password, true} <-
{:current_password, Argon2.verify_pass(old_password, old_password_hash)},
{:same_password, false} <- {:same_password, old_password == new_password},
{:ok, %User{} = user} <-
user
|> User.password_change_changeset(%{
"password" => new_password
})
|> User.password_change_changeset(%{"password" => new_password})
|> Repo.update() do
{:ok, user}
else

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Schema do
defmodule Mobilizon.GraphQL.Schema do
@moduledoc """
GraphQL schema representation.
"""
@ -8,24 +8,25 @@ defmodule MobilizonWeb.Schema do
alias Mobilizon.{Actors, Addresses, Events, Media, Reports, Users}
alias Mobilizon.Actors.{Actor, Follower, Member}
alias Mobilizon.Events.{Comment, Event, Participant}
alias Mobilizon.GraphQL.Schema
alias Mobilizon.Storage.Repo
import_types(MobilizonWeb.Schema.Custom.UUID)
import_types(MobilizonWeb.Schema.Custom.Point)
import_types(Absinthe.Type.Custom)
import_types(Absinthe.Plug.Types)
import_types(Schema.Custom.UUID)
import_types(Schema.Custom.Point)
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.Actors.ApplicationType)
import_types(MobilizonWeb.Schema.CommentType)
import_types(MobilizonWeb.Schema.SearchType)
import_types(MobilizonWeb.Schema.ConfigType)
import_types(MobilizonWeb.Schema.ReportType)
import_types(MobilizonWeb.Schema.AdminType)
import_types(Schema.UserType)
import_types(Schema.PictureType)
import_types(Schema.ActorInterface)
import_types(Schema.Actors.PersonType)
import_types(Schema.Actors.GroupType)
import_types(Schema.Actors.ApplicationType)
import_types(Schema.CommentType)
import_types(Schema.SearchType)
import_types(Schema.ConfigType)
import_types(Schema.ReportType)
import_types(Schema.AdminType)
@desc "A struct containing the id of the deleted object"
object :deleted_object do

View File

@ -1,12 +1,14 @@
defmodule MobilizonWeb.Schema.ActorInterface do
defmodule Mobilizon.GraphQL.Schema.ActorInterface do
@moduledoc """
Schema representation for Actor
"""
use Absinthe.Schema.Notation
alias Mobilizon.Actors.Actor
import_types(MobilizonWeb.Schema.Actors.FollowerType)
import_types(MobilizonWeb.Schema.EventType)
alias Mobilizon.Actors.Actor
alias Mobilizon.GraphQL.Schema
import_types(Schema.Actors.FollowerType)
import_types(Schema.EventType)
@desc "An ActivityPub actor"
interface :actor do

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Schema.Actors.ApplicationType do
defmodule Mobilizon.GraphQL.Schema.Actors.ApplicationType do
@moduledoc """
Schema representation for Group.
"""

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Schema.Actors.FollowerType do
defmodule Mobilizon.GraphQL.Schema.Actors.FollowerType do
@moduledoc """
Schema representation for Follower
"""

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Schema.Actors.GroupType do
defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
@moduledoc """
Schema representation for Group.
"""
@ -8,10 +8,10 @@ defmodule MobilizonWeb.Schema.Actors.GroupType do
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias Mobilizon.Events
alias Mobilizon.GraphQL.Resolvers.{Group, Member}
alias Mobilizon.GraphQL.Schema
alias MobilizonWeb.Resolvers.{Group, Member}
import_types(MobilizonWeb.Schema.Actors.MemberType)
import_types(Schema.Actors.MemberType)
@desc """
Represents a group of actors

View File

@ -1,10 +1,10 @@
defmodule MobilizonWeb.Schema.Actors.MemberType do
defmodule Mobilizon.GraphQL.Schema.Actors.MemberType do
@moduledoc """
Schema representation for Member
"""
use Absinthe.Schema.Notation
alias MobilizonWeb.Resolvers
alias Mobilizon.GraphQL.Resolvers.Group
@desc """
Represents a member of a group
@ -27,7 +27,7 @@ defmodule MobilizonWeb.Schema.Actors.MemberType do
arg(:group_id, non_null(:id))
arg(:actor_id, non_null(:id))
resolve(&Resolvers.Group.join_group/3)
resolve(&Group.join_group/3)
end
@desc "Leave an event"
@ -35,7 +35,7 @@ defmodule MobilizonWeb.Schema.Actors.MemberType do
arg(:group_id, non_null(:id))
arg(:actor_id, non_null(:id))
resolve(&Resolvers.Group.leave_group/3)
resolve(&Group.leave_group/3)
end
end
end

View File

@ -1,14 +1,17 @@
defmodule MobilizonWeb.Schema.Actors.PersonType do
defmodule Mobilizon.GraphQL.Schema.Actors.PersonType do
@moduledoc """
Schema representation for Person
"""
use Absinthe.Schema.Notation
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias Mobilizon.Events
alias MobilizonWeb.Resolvers.Person
import MobilizonWeb.Schema.Utils
import_types(MobilizonWeb.Schema.Events.FeedTokenType)
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

View File

@ -1,9 +1,10 @@
defmodule MobilizonWeb.Schema.AddressType do
defmodule Mobilizon.GraphQL.Schema.AddressType do
@moduledoc """
Schema representation for Address
"""
use Absinthe.Schema.Notation
alias MobilizonWeb.Resolvers
alias Mobilizon.GraphQL.Resolvers.Address
object :address do
field(:geom, :point, description: "The geocoordinates for the point where this address is")
@ -52,7 +53,7 @@ defmodule MobilizonWeb.Schema.AddressType do
arg(:page, :integer, default_value: 1)
arg(:limit, :integer, default_value: 10)
resolve(&Resolvers.Address.search/3)
resolve(&Address.search/3)
end
@desc "Reverse geocode coordinates"
@ -62,7 +63,7 @@ defmodule MobilizonWeb.Schema.AddressType do
arg(:zoom, :integer, default_value: 15)
arg(:locale, :string, default_value: "en")
resolve(&Resolvers.Address.reverse_geocode/3)
resolve(&Address.reverse_geocode/3)
end
end
end

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Schema.AdminType do
defmodule Mobilizon.GraphQL.Schema.AdminType do
@moduledoc """
Schema representation for ActionLog.
"""
@ -8,7 +8,7 @@ defmodule MobilizonWeb.Schema.AdminType do
alias Mobilizon.Events.{Event, Comment}
alias Mobilizon.Reports.{Note, Report}
alias MobilizonWeb.Resolvers.Admin
alias Mobilizon.GraphQL.Resolvers.Admin
@desc "An action log"
object :action_log do

View File

@ -1,12 +1,14 @@
defmodule MobilizonWeb.Schema.CommentType do
defmodule Mobilizon.GraphQL.Schema.CommentType do
@moduledoc """
Schema representation for Comment
"""
use Absinthe.Schema.Notation
alias MobilizonWeb.Resolvers.Comment
alias Mobilizon.{Actors, Events}
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias Mobilizon.{Actors, Events}
alias Mobilizon.GraphQL.Resolvers.Comment
@desc "A comment"
object :comment do
interfaces([:action_log_object])

View File

@ -1,10 +1,10 @@
defmodule MobilizonWeb.Schema.ConfigType do
defmodule Mobilizon.GraphQL.Schema.ConfigType do
@moduledoc """
Schema representation for User
"""
use Absinthe.Schema.Notation
alias MobilizonWeb.Resolvers.Config
alias Mobilizon.GraphQL.Resolvers.Config
@desc "A config object"
object :config do

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Schema.Custom.Point do
defmodule Mobilizon.GraphQL.Schema.Custom.Point do
@moduledoc """
The geom scalar type allows Geo.PostGIS.Geometry strings to be passed in and out.
Requires `{:geo, "~> 3.0"},` package: https://github.com/elixir-ecto/ecto
@ -15,7 +15,7 @@ defmodule MobilizonWeb.Schema.Custom.Point do
parse(&decode/1)
end
@spec decode(Absinthe.Blueprint.Input.String.t()) :: {:ok, term()} | :error
@spec decode(Absinthe.Blueprint.Input.String.t()) :: {:ok, term} | :error
@spec decode(Absinthe.Blueprint.Input.Null.t()) :: {:ok, nil}
defp decode(%Absinthe.Blueprint.Input.String{value: value}) do
with [_, _] = lonlat <- String.split(value, ";", trim: true),

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Schema.Custom.UUID do
defmodule Mobilizon.GraphQL.Schema.Custom.UUID do
@moduledoc """
The UUID4 scalar type allows UUID compliant strings to be passed in and out.
Requires `{ :ecto, ">= 0.0.0" }` package: https://github.com/elixir-ecto/ecto
@ -18,7 +18,7 @@ defmodule MobilizonWeb.Schema.Custom.UUID do
parse(&decode/1)
end
@spec decode(Absinthe.Blueprint.Input.String.t()) :: {:ok, term()} | :error
@spec decode(Absinthe.Blueprint.Input.String.t()) :: {:ok, term} | :error
@spec decode(Absinthe.Blueprint.Input.Null.t()) :: {:ok, nil}
defp decode(%Absinthe.Blueprint.Input.String{value: value}) do
UUID.cast(value)

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Schema.EventType do
defmodule Mobilizon.GraphQL.Schema.EventType do
@moduledoc """
Schema representation for Event.
"""
@ -6,15 +6,15 @@ defmodule MobilizonWeb.Schema.EventType do
use Absinthe.Schema.Notation
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
import MobilizonWeb.Schema.Utils
import Mobilizon.GraphQL.Helpers.Error
alias Mobilizon.{Actors, Addresses, Events}
alias Mobilizon.GraphQL.Resolvers.{Event, Picture, Tag}
alias Mobilizon.GraphQL.Schema
alias MobilizonWeb.Resolvers.{Event, Picture, Tag}
import_types(MobilizonWeb.Schema.AddressType)
import_types(MobilizonWeb.Schema.Events.ParticipantType)
import_types(MobilizonWeb.Schema.TagType)
import_types(Schema.AddressType)
import_types(Schema.Events.ParticipantType)
import_types(Schema.TagType)
@desc "An event"
object :event do

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Schema.Events.FeedTokenType do
defmodule Mobilizon.GraphQL.Schema.Events.FeedTokenType do
@moduledoc """
Schema representation for Participant.
"""
@ -8,8 +8,7 @@ defmodule MobilizonWeb.Schema.Events.FeedTokenType do
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias Mobilizon.{Actors, Users}
alias MobilizonWeb.Resolvers
alias Mobilizon.GraphQL.Resolvers.FeedToken
@desc "Represents a participant to an event"
object :feed_token do
@ -41,14 +40,14 @@ defmodule MobilizonWeb.Schema.Events.FeedTokenType do
field :create_feed_token, :feed_token do
arg(:actor_id, :id)
resolve(&Resolvers.FeedToken.create_feed_token/3)
resolve(&FeedToken.create_feed_token/3)
end
@desc "Delete a feed token"
field :delete_feed_token, :deleted_feed_token do
arg(:token, non_null(:string))
resolve(&Resolvers.FeedToken.delete_feed_token/3)
resolve(&FeedToken.delete_feed_token/3)
end
end
end

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Schema.Events.ParticipantType do
defmodule Mobilizon.GraphQL.Schema.Events.ParticipantType do
@moduledoc """
Schema representation for Participant.
"""
@ -8,8 +8,7 @@ defmodule MobilizonWeb.Schema.Events.ParticipantType do
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias Mobilizon.{Actors, Events}
alias MobilizonWeb.Resolvers
alias Mobilizon.GraphQL.Resolvers.Event
@desc "Represents a participant to an event"
object :participant do
@ -54,7 +53,7 @@ defmodule MobilizonWeb.Schema.Events.ParticipantType do
arg(:event_id, non_null(:id))
arg(:actor_id, non_null(:id))
resolve(&Resolvers.Event.actor_join_event/3)
resolve(&Event.actor_join_event/3)
end
@desc "Leave an event"
@ -62,7 +61,7 @@ defmodule MobilizonWeb.Schema.Events.ParticipantType do
arg(:event_id, non_null(:id))
arg(:actor_id, non_null(:id))
resolve(&Resolvers.Event.actor_leave_event/3)
resolve(&Event.actor_leave_event/3)
end
@desc "Accept a participation"
@ -71,7 +70,7 @@ defmodule MobilizonWeb.Schema.Events.ParticipantType do
arg(:role, non_null(:participant_role_enum))
arg(:moderator_actor_id, non_null(:id))
resolve(&Resolvers.Event.update_participation/3)
resolve(&Event.update_participation/3)
end
end
end

View File

@ -1,9 +1,10 @@
defmodule MobilizonWeb.Schema.PictureType do
defmodule Mobilizon.GraphQL.Schema.PictureType do
@moduledoc """
Schema representation for Pictures
"""
use Absinthe.Schema.Notation
alias MobilizonWeb.Resolvers.Picture
alias Mobilizon.GraphQL.Resolvers.Picture
@desc "A picture"
object :picture do

View File

@ -1,12 +1,13 @@
defmodule MobilizonWeb.Schema.ReportType do
defmodule Mobilizon.GraphQL.Schema.ReportType do
@moduledoc """
Schema representation for User
"""
use Absinthe.Schema.Notation
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias Mobilizon.Reports
alias MobilizonWeb.Resolvers.Report
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias Mobilizon.Reports
alias Mobilizon.GraphQL.Resolvers.Report
@desc "A report object"
object :report do

View File

@ -1,10 +1,10 @@
defmodule MobilizonWeb.Schema.SearchType do
defmodule Mobilizon.GraphQL.Schema.SearchType do
@moduledoc """
Schema representation for Search
"""
use Absinthe.Schema.Notation
alias MobilizonWeb.Resolvers
alias Mobilizon.GraphQL.Resolvers.Search
@desc "Search persons result"
object :persons do
@ -31,7 +31,7 @@ defmodule MobilizonWeb.Schema.SearchType do
arg(:page, :integer, default_value: 1)
arg(:limit, :integer, default_value: 10)
resolve(&Resolvers.Search.search_persons/3)
resolve(&Search.search_persons/3)
end
@desc "Search groups"
@ -40,7 +40,7 @@ defmodule MobilizonWeb.Schema.SearchType do
arg(:page, :integer, default_value: 1)
arg(:limit, :integer, default_value: 10)
resolve(&Resolvers.Search.search_groups/3)
resolve(&Search.search_groups/3)
end
@desc "Search events"
@ -49,7 +49,7 @@ defmodule MobilizonWeb.Schema.SearchType do
arg(:page, :integer, default_value: 1)
arg(:limit, :integer, default_value: 10)
resolve(&Resolvers.Search.search_events/3)
resolve(&Search.search_events/3)
end
end
end

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Schema.SortType do
defmodule Mobilizon.GraphQL.Schema.SortType do
@moduledoc """
Allows sorting a collection of elements
"""

View File

@ -1,9 +1,10 @@
defmodule MobilizonWeb.Schema.TagType do
defmodule Mobilizon.GraphQL.Schema.TagType do
@moduledoc """
Schema representation for Tags
"""
use Absinthe.Schema.Notation
alias MobilizonWeb.Resolvers
alias Mobilizon.GraphQL.Resolvers.Tag
@desc "A tag"
object :tag do
@ -14,7 +15,7 @@ defmodule MobilizonWeb.Schema.TagType do
field(
:related,
list_of(:tag),
resolve: &Resolvers.Tag.get_related_tags/3,
resolve: &Tag.get_related_tags/3,
description: "Related tags to this tag"
)
end
@ -24,7 +25,7 @@ defmodule MobilizonWeb.Schema.TagType do
field :tags, non_null(list_of(:tag)) do
arg(:page, :integer, default_value: 1)
arg(:limit, :integer, default_value: 10)
resolve(&Resolvers.Tag.list_tags/3)
resolve(&Tag.list_tags/3)
end
end
end

View File

@ -1,14 +1,17 @@
defmodule MobilizonWeb.Schema.UserType do
defmodule Mobilizon.GraphQL.Schema.UserType do
@moduledoc """
Schema representation for User
"""
use Absinthe.Schema.Notation
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias Mobilizon.Events
alias MobilizonWeb.Resolvers.User
import MobilizonWeb.Schema.Utils
import_types(MobilizonWeb.Schema.SortType)
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
import Mobilizon.GraphQL.Helpers.Error
alias Mobilizon.Events
alias Mobilizon.GraphQL.Resolvers.User
alias Mobilizon.GraphQL.Schema
import_types(Schema.SortType)
@desc "A local user of Mobilizon"
object :user do

View File

@ -53,7 +53,9 @@ defmodule MobilizonWeb.API.Events do
defp process_picture(%{picture: picture}, %Actor{id: actor_id}) do
%{
file:
picture |> Map.get(:file) |> Utils.make_picture_data(description: Map.get(picture, :name)),
picture
|> Map.get(:file)
|> Utils.make_picture_data(description: Map.get(picture, :name)),
actor_id: actor_id
}
end

View File

@ -52,7 +52,7 @@ defmodule MobilizonWeb.Router do
pipe_through(:graphql)
forward("/", Absinthe.Plug,
schema: MobilizonWeb.Schema,
schema: Mobilizon.GraphQL.Schema,
analyze_complexity: true,
max_complexity: 200
)

View File

@ -1,8 +1,10 @@
defmodule MobilizonWeb.Resolvers.AddressResolverTest do
defmodule Mobilizon.GraphQL.Resolvers.AddressTest do
use MobilizonWeb.ConnCase
alias MobilizonWeb.AbsintheHelpers
import Mobilizon.Factory
alias Mobilizon.GraphQL.AbsintheHelpers
describe "Address Resolver" do
test "search/3 search for addresses", %{conn: conn} do
address = insert(:address, description: "10 rue Jangot, Lyon")

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Resolvers.AdminResolverTest do
defmodule Mobilizon.GraphQL.Resolvers.AdminTest do
use MobilizonWeb.ConnCase
import Mobilizon.Factory
@ -10,7 +10,7 @@ defmodule MobilizonWeb.Resolvers.AdminResolverTest do
alias Mobilizon.Federation.ActivityPub.Relay
alias MobilizonWeb.AbsintheHelpers
alias Mobilizon.GraphQL.AbsintheHelpers
alias MobilizonWeb.API
describe "Resolver: List the action logs" do

View File

@ -1,8 +1,10 @@
defmodule MobilizonWeb.Resolvers.CommentResolverTest do
defmodule Mobilizon.GraphQL.Resolvers.CommentTest do
use MobilizonWeb.ConnCase
alias MobilizonWeb.AbsintheHelpers
import Mobilizon.Factory
alias Mobilizon.GraphQL.AbsintheHelpers
@comment %{text: "I love this event"}
setup %{conn: conn} do

View File

@ -1,8 +1,9 @@
defmodule MobilizonWeb.Resolvers.ConfigResolverTest do
alias MobilizonWeb.AbsintheHelpers
defmodule Mobilizon.GraphQL.Resolvers.ConfigTest do
use MobilizonWeb.ConnCase
use Bamboo.Test
alias Mobilizon.GraphQL.AbsintheHelpers
describe "Resolver: Get config" do
test "get_config/3 returns the instance config", context do
query = """

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Resolvers.EventResolverTest do
defmodule MobilizonWeb.Resolvers.EventTest do
use MobilizonWeb.ConnCase
use Bamboo.Test
use Oban.Testing, repo: Mobilizon.Storage.Repo
@ -8,7 +8,9 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
alias Mobilizon.Events
alias Mobilizon.Service.Workers
alias MobilizonWeb.{AbsintheHelpers, Email}
alias Mobilizon.GraphQL.AbsintheHelpers
alias MobilizonWeb.Email
@event %{
description: "some body",

View File

@ -1,8 +1,10 @@
defmodule MobilizonWeb.Resolvers.FeedTokenResolverTest do
defmodule Mobilizon.GraphQL.Resolvers.FeedTokenTest do
use MobilizonWeb.ConnCase
alias MobilizonWeb.AbsintheHelpers
import Mobilizon.Factory
alias Mobilizon.GraphQL.AbsintheHelpers
setup %{conn: conn} do
user = insert(:user)
actor = insert(:actor, user: user, preferred_username: "test")

View File

@ -1,8 +1,10 @@
defmodule MobilizonWeb.Resolvers.GroupResolverTest do
defmodule MobilizonWeb.Resolvers.GroupTest do
use MobilizonWeb.ConnCase
alias MobilizonWeb.AbsintheHelpers
import Mobilizon.Factory
alias Mobilizon.GraphQL.AbsintheHelpers
@non_existent_username "nonexistent"
@new_group_params %{groupname: "new group"}

View File

@ -1,10 +1,10 @@
defmodule MobilizonWeb.Resolvers.MemberResolverTest do
defmodule Mobilizon.GraphQL.Resolvers.MemberTest do
use MobilizonWeb.ConnCase
alias MobilizonWeb.AbsintheHelpers
import Mobilizon.Factory
alias Mobilizon.GraphQL.AbsintheHelpers
setup %{conn: conn} do
user = insert(:user)
actor = insert(:actor, user: user, preferred_username: "test")

View File

@ -1,10 +1,14 @@
defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do
use MobilizonWeb.ConnCase
use Bamboo.Test
alias Mobilizon.Events
alias MobilizonWeb.{AbsintheHelpers, Email}
import Mobilizon.Factory
alias Mobilizon.Events
alias Mobilizon.GraphQL.AbsintheHelpers
alias MobilizonWeb.Email
@event %{
description: "some body",
title: "some title",

View File

@ -1,13 +1,13 @@
defmodule MobilizonWeb.Resolvers.PersonResolverTest do
use MobilizonWeb.ConnCase
defmodule Mobilizon.GraphQL.Resolvers.PersonTest do
use Oban.Testing, repo: Mobilizon.Storage.Repo
use MobilizonWeb.ConnCase
import Mobilizon.Factory
alias Mobilizon.Actors.Actor
alias Mobilizon.Service.Workers
alias MobilizonWeb.AbsintheHelpers
alias Mobilizon.GraphQL.AbsintheHelpers
@non_existent_username "nonexistent"

View File

@ -1,10 +1,13 @@
defmodule MobilizonWeb.Resolvers.PictureResolverTest do
alias MobilizonWeb.AbsintheHelpers
defmodule Mobilizon.GraphQL.Resolvers.PictureTest do
use MobilizonWeb.ConnCase
use Bamboo.Test
alias Mobilizon.Media.Picture
import Mobilizon.Factory
alias Mobilizon.Media.Picture
alias Mobilizon.GraphQL.AbsintheHelpers
setup %{conn: conn} do
user = insert(:user)
actor = insert(:actor, user: user)

View File

@ -1,4 +1,4 @@
defmodule MobilizonWeb.Resolvers.ReportResolverTest do
defmodule Mobilizon.GraphQL.Resolvers.ReportTest do
use MobilizonWeb.ConnCase
import Mobilizon.Factory
@ -8,7 +8,7 @@ defmodule MobilizonWeb.Resolvers.ReportResolverTest do
alias Mobilizon.Reports.{Note, Report}
alias Mobilizon.Users.User
alias MobilizonWeb.AbsintheHelpers
alias Mobilizon.GraphQL.AbsintheHelpers
describe "Resolver: Report a content" do
test "create_report/3 creates a report", %{conn: conn} do

View File

@ -1,10 +1,11 @@
defmodule MobilizonWeb.Resolvers.SearchResolverTest do
defmodule Mobilizon.GraphQL.Resolvers.SearchTest do
use MobilizonWeb.ConnCase
import Mobilizon.Factory
alias Mobilizon.Service.Workers
alias MobilizonWeb.AbsintheHelpers
alias Mobilizon.GraphQL.AbsintheHelpers
setup %{conn: conn} do
user = insert(:user)

View File

@ -1,8 +1,10 @@
defmodule MobilizonWeb.Resolvers.TagResolverTest do
defmodule Mobilizon.GraphQL.Resolvers.TagTest do
use MobilizonWeb.ConnCase
alias MobilizonWeb.AbsintheHelpers
import Mobilizon.Factory
alias Mobilizon.GraphQL.AbsintheHelpers
describe "Tag Resolver" do
test "list_tags/3 returns the list of tags", context do
tag1 = insert(:tag)

View File

@ -1,15 +1,16 @@
defmodule MobilizonWeb.Resolvers.UserResolverTest do
defmodule Mobilizon.GraphQL.Resolvers.UserTest do
use MobilizonWeb.ConnCase
use Bamboo.Test
import Mobilizon.Factory
use Bamboo.Test
alias Mobilizon.{Actors, Config, Users}
alias Mobilizon.Actors.Actor
alias Mobilizon.Users.User
alias MobilizonWeb.{AbsintheHelpers, Email}
alias Mobilizon.GraphQL.AbsintheHelpers
alias MobilizonWeb.Email
@valid_actor_params %{email: "test@test.tld", password: "testest", username: "test"}
@valid_single_actor_params %{preferred_username: "test2", keys: "yolo"}

View File

@ -1,10 +1,12 @@
defmodule MobilizonWeb.AbsintheHelpers do
use Phoenix.ConnTest
@endpoint MobilizonWeb.Endpoint
defmodule Mobilizon.GraphQL.AbsintheHelpers do
@moduledoc """
Absinthe helpers for tests
"""
use Phoenix.ConnTest
@endpoint MobilizonWeb.Endpoint
def query_skeleton(query, query_name) do
%{
"operationName" => "#{query_name}",
@ -23,10 +25,7 @@ defmodule MobilizonWeb.AbsintheHelpers do
def graphql_query(conn, options) do
conn
|> post(
"/api",
build_query(options[:query], Keyword.get(options, :variables, %{}))
)
|> post("/api", build_query(options[:query], Keyword.get(options, :variables, %{})))
|> json_response(200)
end