diff --git a/lib/mobilizon_web/schema/utils.ex b/lib/graphql/helpers/error.ex similarity index 86% rename from lib/mobilizon_web/schema/utils.ex rename to lib/graphql/helpers/error.ex index 2619e7fb1..ae70f819d 100644 --- a/lib/mobilizon_web/schema/utils.ex +++ b/lib/graphql/helpers/error.ex @@ -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 diff --git a/lib/mobilizon_web/resolvers/address.ex b/lib/graphql/resolvers/address.ex similarity index 72% rename from lib/mobilizon_web/resolvers/address.ex rename to lib/graphql/resolvers/address.ex index eefc35cfb..f2d5fc402 100644 --- a/lib/mobilizon_web/resolvers/address.ex +++ b/lib/graphql/resolvers/address.ex @@ -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}, diff --git a/lib/mobilizon_web/resolvers/admin.ex b/lib/graphql/resolvers/admin.ex similarity index 83% rename from lib/mobilizon_web/resolvers/admin.ex rename to lib/graphql/resolvers/admin.ex index 8ea664bc9..9a99421d5 100644 --- a/lib/mobilizon_web/resolvers/admin.ex +++ b/lib/graphql/resolvers/admin.ex @@ -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} -> diff --git a/lib/mobilizon_web/resolvers/comment.ex b/lib/graphql/resolvers/comment.ex similarity index 84% rename from lib/mobilizon_web/resolvers/comment.ex rename to lib/graphql/resolvers/comment.ex index 0810c3a9c..002e1f7d3 100644 --- a/lib/mobilizon_web/resolvers/comment.ex +++ b/lib/graphql/resolvers/comment.ex @@ -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 diff --git a/lib/mobilizon_web/resolvers/config.ex b/lib/graphql/resolvers/config.ex similarity index 91% rename from lib/mobilizon_web/resolvers/config.ex rename to lib/graphql/resolvers/config.ex index a3a4d4485..dbfbbbe26 100644 --- a/lib/mobilizon_web/resolvers/config.ex +++ b/lib/graphql/resolvers/config.ex @@ -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 = diff --git a/lib/mobilizon_web/resolvers/event.ex b/lib/graphql/resolvers/event.ex similarity index 97% rename from lib/mobilizon_web/resolvers/event.ex rename to lib/graphql/resolvers/event.ex index 59a0100e8..a502e1cfe 100644 --- a/lib/mobilizon_web/resolvers/event.ex +++ b/lib/graphql/resolvers/event.ex @@ -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), diff --git a/lib/mobilizon_web/resolvers/feed_token.ex b/lib/graphql/resolvers/feed_token.ex similarity index 69% rename from lib/mobilizon_web/resolvers/feed_token.ex rename to lib/graphql/resolvers/feed_token.ex index 530044434..8546677e6 100644 --- a/lib/mobilizon_web/resolvers/feed_token.ex +++ b/lib/graphql/resolvers/feed_token.ex @@ -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 diff --git a/lib/mobilizon_web/resolvers/group.ex b/lib/graphql/resolvers/group.ex similarity index 95% rename from lib/mobilizon_web/resolvers/group.ex rename to lib/graphql/resolvers/group.ex index 98220d670..c2ff0409d 100644 --- a/lib/mobilizon_web/resolvers/group.ex +++ b/lib/graphql/resolvers/group.ex @@ -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}}] -> diff --git a/lib/mobilizon_web/resolvers/member.ex b/lib/graphql/resolvers/member.ex similarity index 86% rename from lib/mobilizon_web/resolvers/member.ex rename to lib/graphql/resolvers/member.ex index 1cfd320a2..65cdd249c 100644 --- a/lib/mobilizon_web/resolvers/member.ex +++ b/lib/graphql/resolvers/member.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Resolvers.Member do +defmodule Mobilizon.GraphQL.Resolvers.Member do @moduledoc """ Handles the member-related GraphQL calls """ diff --git a/lib/mobilizon_web/resolvers/person.ex b/lib/graphql/resolvers/person.ex similarity index 97% rename from lib/mobilizon_web/resolvers/person.ex rename to lib/graphql/resolvers/person.ex index 82d9b172e..8ec9241b0 100644 --- a/lib/mobilizon_web/resolvers/person.ex +++ b/lib/graphql/resolvers/person.ex @@ -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 diff --git a/lib/mobilizon_web/resolvers/picture.ex b/lib/graphql/resolvers/picture.ex similarity index 94% rename from lib/mobilizon_web/resolvers/picture.ex rename to lib/graphql/resolvers/picture.ex index 1b5c73c29..941ef6fd7 100644 --- a/lib/mobilizon_web/resolvers/picture.ex +++ b/lib/graphql/resolvers/picture.ex @@ -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, diff --git a/lib/mobilizon_web/resolvers/report.ex b/lib/graphql/resolvers/report.ex similarity index 98% rename from lib/mobilizon_web/resolvers/report.ex rename to lib/graphql/resolvers/report.ex index 823e58a34..e8b78199c 100644 --- a/lib/mobilizon_web/resolvers/report.ex +++ b/lib/graphql/resolvers/report.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Resolvers.Report do +defmodule Mobilizon.GraphQL.Resolvers.Report do @moduledoc """ Handles the report-related GraphQL calls. """ diff --git a/lib/mobilizon_web/resolvers/search.ex b/lib/graphql/resolvers/search.ex similarity index 93% rename from lib/mobilizon_web/resolvers/search.ex rename to lib/graphql/resolvers/search.ex index f6b7995ad..acb74b963 100644 --- a/lib/mobilizon_web/resolvers/search.ex +++ b/lib/graphql/resolvers/search.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Resolvers.Search do +defmodule Mobilizon.GraphQL.Resolvers.Search do @moduledoc """ Handles the event-related GraphQL calls """ diff --git a/lib/mobilizon_web/resolvers/tag.ex b/lib/graphql/resolvers/tag.ex similarity index 92% rename from lib/mobilizon_web/resolvers/tag.ex rename to lib/graphql/resolvers/tag.ex index 75f26a6cb..b7a5dd117 100644 --- a/lib/mobilizon_web/resolvers/tag.ex +++ b/lib/graphql/resolvers/tag.ex @@ -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) diff --git a/lib/mobilizon_web/resolvers/user.ex b/lib/graphql/resolvers/user.ex similarity index 86% rename from lib/mobilizon_web/resolvers/user.ex rename to lib/graphql/resolvers/user.ex index c9ab7c2b4..4b4993ed3 100644 --- a/lib/mobilizon_web/resolvers/user.ex +++ b/lib/graphql/resolvers/user.ex @@ -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 diff --git a/lib/mobilizon_web/schema.ex b/lib/graphql/schema.ex similarity index 84% rename from lib/mobilizon_web/schema.ex rename to lib/graphql/schema.ex index c78bd3f75..eb2c882e7 100644 --- a/lib/mobilizon_web/schema.ex +++ b/lib/graphql/schema.ex @@ -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 diff --git a/lib/mobilizon_web/schema/actor.ex b/lib/graphql/schema/actor.ex similarity index 92% rename from lib/mobilizon_web/schema/actor.ex rename to lib/graphql/schema/actor.ex index 2b21f1a2e..162b9c60a 100644 --- a/lib/mobilizon_web/schema/actor.ex +++ b/lib/graphql/schema/actor.ex @@ -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 diff --git a/lib/mobilizon_web/schema/actors/application.ex b/lib/graphql/schema/actors/application.ex similarity index 96% rename from lib/mobilizon_web/schema/actors/application.ex rename to lib/graphql/schema/actors/application.ex index 8bfdf41fa..339991982 100644 --- a/lib/mobilizon_web/schema/actors/application.ex +++ b/lib/graphql/schema/actors/application.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Schema.Actors.ApplicationType do +defmodule Mobilizon.GraphQL.Schema.Actors.ApplicationType do @moduledoc """ Schema representation for Group. """ diff --git a/lib/mobilizon_web/schema/actors/follower.ex b/lib/graphql/schema/actors/follower.ex similarity index 93% rename from lib/mobilizon_web/schema/actors/follower.ex rename to lib/graphql/schema/actors/follower.ex index 258103c1a..efa297a0b 100644 --- a/lib/mobilizon_web/schema/actors/follower.ex +++ b/lib/graphql/schema/actors/follower.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Schema.Actors.FollowerType do +defmodule Mobilizon.GraphQL.Schema.Actors.FollowerType do @moduledoc """ Schema representation for Follower """ diff --git a/lib/mobilizon_web/schema/actors/group.ex b/lib/graphql/schema/actors/group.ex similarity index 95% rename from lib/mobilizon_web/schema/actors/group.ex rename to lib/graphql/schema/actors/group.ex index a243ef6b3..de7642425 100644 --- a/lib/mobilizon_web/schema/actors/group.ex +++ b/lib/graphql/schema/actors/group.ex @@ -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 diff --git a/lib/mobilizon_web/schema/actors/member.ex b/lib/graphql/schema/actors/member.ex similarity index 83% rename from lib/mobilizon_web/schema/actors/member.ex rename to lib/graphql/schema/actors/member.ex index 920138897..907785130 100644 --- a/lib/mobilizon_web/schema/actors/member.ex +++ b/lib/graphql/schema/actors/member.ex @@ -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 diff --git a/lib/mobilizon_web/schema/actors/person.ex b/lib/graphql/schema/actors/person.ex similarity index 96% rename from lib/mobilizon_web/schema/actors/person.ex rename to lib/graphql/schema/actors/person.ex index 2cbc4c78c..c4c145b4a 100644 --- a/lib/mobilizon_web/schema/actors/person.ex +++ b/lib/graphql/schema/actors/person.ex @@ -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 diff --git a/lib/mobilizon_web/schema/address.ex b/lib/graphql/schema/address.ex similarity index 91% rename from lib/mobilizon_web/schema/address.ex rename to lib/graphql/schema/address.ex index aea2a8156..13ce22449 100644 --- a/lib/mobilizon_web/schema/address.ex +++ b/lib/graphql/schema/address.ex @@ -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 diff --git a/lib/mobilizon_web/schema/admin.ex b/lib/graphql/schema/admin.ex similarity index 97% rename from lib/mobilizon_web/schema/admin.ex rename to lib/graphql/schema/admin.ex index f1e7543f5..b7dc5cb96 100644 --- a/lib/mobilizon_web/schema/admin.ex +++ b/lib/graphql/schema/admin.ex @@ -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 diff --git a/lib/mobilizon_web/schema/comment.ex b/lib/graphql/schema/comment.ex similarity index 95% rename from lib/mobilizon_web/schema/comment.ex rename to lib/graphql/schema/comment.ex index 8f68d16d5..8794a7f4a 100644 --- a/lib/mobilizon_web/schema/comment.ex +++ b/lib/graphql/schema/comment.ex @@ -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]) diff --git a/lib/mobilizon_web/schema/config.ex b/lib/graphql/schema/config.ex similarity index 91% rename from lib/mobilizon_web/schema/config.ex rename to lib/graphql/schema/config.ex index 46f9fa233..95116de83 100644 --- a/lib/mobilizon_web/schema/config.ex +++ b/lib/graphql/schema/config.ex @@ -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 diff --git a/lib/mobilizon_web/schema/custom/point.ex b/lib/graphql/schema/custom/point.ex similarity index 94% rename from lib/mobilizon_web/schema/custom/point.ex rename to lib/graphql/schema/custom/point.ex index 7bd3cf974..432aa85f9 100644 --- a/lib/mobilizon_web/schema/custom/point.ex +++ b/lib/graphql/schema/custom/point.ex @@ -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), diff --git a/lib/mobilizon_web/schema/custom/uuid4.ex b/lib/graphql/schema/custom/uuid4.ex similarity index 93% rename from lib/mobilizon_web/schema/custom/uuid4.ex rename to lib/graphql/schema/custom/uuid4.ex index 4540e3344..112011773 100644 --- a/lib/mobilizon_web/schema/custom/uuid4.ex +++ b/lib/graphql/schema/custom/uuid4.ex @@ -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) diff --git a/lib/mobilizon_web/schema/event.ex b/lib/graphql/schema/event.ex similarity index 97% rename from lib/mobilizon_web/schema/event.ex rename to lib/graphql/schema/event.ex index b0c617221..9c816476e 100644 --- a/lib/mobilizon_web/schema/event.ex +++ b/lib/graphql/schema/event.ex @@ -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 diff --git a/lib/mobilizon_web/schema/events/feed_token.ex b/lib/graphql/schema/events/feed_token.ex similarity index 84% rename from lib/mobilizon_web/schema/events/feed_token.ex rename to lib/graphql/schema/events/feed_token.ex index ac8ba8b5d..8c9dc438b 100644 --- a/lib/mobilizon_web/schema/events/feed_token.ex +++ b/lib/graphql/schema/events/feed_token.ex @@ -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 diff --git a/lib/mobilizon_web/schema/events/participant.ex b/lib/graphql/schema/events/participant.ex similarity index 86% rename from lib/mobilizon_web/schema/events/participant.ex rename to lib/graphql/schema/events/participant.ex index 7873d433f..7136f6998 100644 --- a/lib/mobilizon_web/schema/events/participant.ex +++ b/lib/graphql/schema/events/participant.ex @@ -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 diff --git a/lib/mobilizon_web/schema/picture.ex b/lib/graphql/schema/picture.ex similarity index 93% rename from lib/mobilizon_web/schema/picture.ex rename to lib/graphql/schema/picture.ex index 5290505d5..fb94517b6 100644 --- a/lib/mobilizon_web/schema/picture.ex +++ b/lib/graphql/schema/picture.ex @@ -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 diff --git a/lib/mobilizon_web/schema/report.ex b/lib/graphql/schema/report.ex similarity index 97% rename from lib/mobilizon_web/schema/report.ex rename to lib/graphql/schema/report.ex index e0edc07e6..db3890f4d 100644 --- a/lib/mobilizon_web/schema/report.ex +++ b/lib/graphql/schema/report.ex @@ -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 diff --git a/lib/mobilizon_web/schema/search.ex b/lib/graphql/schema/search.ex similarity index 85% rename from lib/mobilizon_web/schema/search.ex rename to lib/graphql/schema/search.ex index a752c0ffb..fbba6a911 100644 --- a/lib/mobilizon_web/schema/search.ex +++ b/lib/graphql/schema/search.ex @@ -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 diff --git a/lib/mobilizon_web/schema/sort.ex b/lib/graphql/schema/sort.ex similarity index 81% rename from lib/mobilizon_web/schema/sort.ex rename to lib/graphql/schema/sort.ex index 2f44e786e..217709555 100644 --- a/lib/mobilizon_web/schema/sort.ex +++ b/lib/graphql/schema/sort.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Schema.SortType do +defmodule Mobilizon.GraphQL.Schema.SortType do @moduledoc """ Allows sorting a collection of elements """ diff --git a/lib/mobilizon_web/schema/tag.ex b/lib/graphql/schema/tag.ex similarity index 78% rename from lib/mobilizon_web/schema/tag.ex rename to lib/graphql/schema/tag.ex index 7c4237ccd..eee428c6d 100644 --- a/lib/mobilizon_web/schema/tag.ex +++ b/lib/graphql/schema/tag.ex @@ -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 diff --git a/lib/mobilizon_web/schema/user.ex b/lib/graphql/schema/user.ex similarity index 96% rename from lib/mobilizon_web/schema/user.ex rename to lib/graphql/schema/user.ex index d23547e29..d5ca3e6a4 100644 --- a/lib/mobilizon_web/schema/user.ex +++ b/lib/graphql/schema/user.ex @@ -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 diff --git a/lib/mobilizon_web/api/events.ex b/lib/mobilizon_web/api/events.ex index 2db2b7984..b3a7b58bf 100644 --- a/lib/mobilizon_web/api/events.ex +++ b/lib/mobilizon_web/api/events.ex @@ -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 diff --git a/lib/mobilizon_web/router.ex b/lib/mobilizon_web/router.ex index 1f20cf162..caff1d7f3 100644 --- a/lib/mobilizon_web/router.ex +++ b/lib/mobilizon_web/router.ex @@ -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 ) diff --git a/test/mobilizon_web/resolvers/address_test.exs b/test/graphql/resolvers/address_test.exs similarity index 94% rename from test/mobilizon_web/resolvers/address_test.exs rename to test/graphql/resolvers/address_test.exs index 47a944c3b..f55eb7430 100644 --- a/test/mobilizon_web/resolvers/address_test.exs +++ b/test/graphql/resolvers/address_test.exs @@ -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") diff --git a/test/mobilizon_web/resolvers/admin_test.exs b/test/graphql/resolvers/admin_test.exs similarity index 98% rename from test/mobilizon_web/resolvers/admin_test.exs rename to test/graphql/resolvers/admin_test.exs index 30c9d0362..7bc2d8578 100644 --- a/test/mobilizon_web/resolvers/admin_test.exs +++ b/test/graphql/resolvers/admin_test.exs @@ -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 diff --git a/test/mobilizon_web/resolvers/comment_test.exs b/test/graphql/resolvers/comment_test.exs similarity index 98% rename from test/mobilizon_web/resolvers/comment_test.exs rename to test/graphql/resolvers/comment_test.exs index 3465ecb91..d44692531 100644 --- a/test/mobilizon_web/resolvers/comment_test.exs +++ b/test/graphql/resolvers/comment_test.exs @@ -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 diff --git a/test/mobilizon_web/resolvers/config_test.exs b/test/graphql/resolvers/config_test.exs similarity index 85% rename from test/mobilizon_web/resolvers/config_test.exs rename to test/graphql/resolvers/config_test.exs index d9cb1bc97..a126df976 100644 --- a/test/mobilizon_web/resolvers/config_test.exs +++ b/test/graphql/resolvers/config_test.exs @@ -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 = """ diff --git a/test/mobilizon_web/resolvers/event_test.exs b/test/graphql/resolvers/event_test.exs similarity index 99% rename from test/mobilizon_web/resolvers/event_test.exs rename to test/graphql/resolvers/event_test.exs index efa54a9ea..b1ebd9d3a 100644 --- a/test/mobilizon_web/resolvers/event_test.exs +++ b/test/graphql/resolvers/event_test.exs @@ -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", diff --git a/test/mobilizon_web/resolvers/feed_token_test.exs b/test/graphql/resolvers/feed_token_test.exs similarity index 98% rename from test/mobilizon_web/resolvers/feed_token_test.exs rename to test/graphql/resolvers/feed_token_test.exs index 01b277e26..2810ed737 100644 --- a/test/mobilizon_web/resolvers/feed_token_test.exs +++ b/test/graphql/resolvers/feed_token_test.exs @@ -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") diff --git a/test/mobilizon_web/resolvers/group_test.exs b/test/graphql/resolvers/group_test.exs similarity index 98% rename from test/mobilizon_web/resolvers/group_test.exs rename to test/graphql/resolvers/group_test.exs index 6ad4c22c3..4c0b29cff 100644 --- a/test/mobilizon_web/resolvers/group_test.exs +++ b/test/graphql/resolvers/group_test.exs @@ -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"} diff --git a/test/mobilizon_web/resolvers/member_test.exs b/test/graphql/resolvers/member_test.exs similarity index 98% rename from test/mobilizon_web/resolvers/member_test.exs rename to test/graphql/resolvers/member_test.exs index cda9c1818..b98906ce7 100644 --- a/test/mobilizon_web/resolvers/member_test.exs +++ b/test/graphql/resolvers/member_test.exs @@ -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") diff --git a/test/mobilizon_web/resolvers/participant_test.exs b/test/graphql/resolvers/participant_test.exs similarity index 99% rename from test/mobilizon_web/resolvers/participant_test.exs rename to test/graphql/resolvers/participant_test.exs index 7aadfd4a5..66e744758 100644 --- a/test/mobilizon_web/resolvers/participant_test.exs +++ b/test/graphql/resolvers/participant_test.exs @@ -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", diff --git a/test/mobilizon_web/resolvers/person_test.exs b/test/graphql/resolvers/person_test.exs similarity index 99% rename from test/mobilizon_web/resolvers/person_test.exs rename to test/graphql/resolvers/person_test.exs index f2af5cc02..730d3d51d 100644 --- a/test/mobilizon_web/resolvers/person_test.exs +++ b/test/graphql/resolvers/person_test.exs @@ -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" diff --git a/test/mobilizon_web/resolvers/picture_test.exs b/test/graphql/resolvers/picture_test.exs similarity index 97% rename from test/mobilizon_web/resolvers/picture_test.exs rename to test/graphql/resolvers/picture_test.exs index e1dde528d..a8daeca0a 100644 --- a/test/mobilizon_web/resolvers/picture_test.exs +++ b/test/graphql/resolvers/picture_test.exs @@ -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) diff --git a/test/mobilizon_web/resolvers/report_test.exs b/test/graphql/resolvers/report_test.exs similarity index 99% rename from test/mobilizon_web/resolvers/report_test.exs rename to test/graphql/resolvers/report_test.exs index e068c735a..2a0838453 100644 --- a/test/mobilizon_web/resolvers/report_test.exs +++ b/test/graphql/resolvers/report_test.exs @@ -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 diff --git a/test/mobilizon_web/resolvers/search_test.exs b/test/graphql/resolvers/search_test.exs similarity index 98% rename from test/mobilizon_web/resolvers/search_test.exs rename to test/graphql/resolvers/search_test.exs index 9e3d89b05..6f8d436d4 100644 --- a/test/mobilizon_web/resolvers/search_test.exs +++ b/test/graphql/resolvers/search_test.exs @@ -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) diff --git a/test/mobilizon_web/resolvers/tag_test.exs b/test/graphql/resolvers/tag_test.exs similarity index 92% rename from test/mobilizon_web/resolvers/tag_test.exs rename to test/graphql/resolvers/tag_test.exs index ac2880279..3ef15f951 100644 --- a/test/mobilizon_web/resolvers/tag_test.exs +++ b/test/graphql/resolvers/tag_test.exs @@ -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) diff --git a/test/mobilizon_web/resolvers/user_test.exs b/test/graphql/resolvers/user_test.exs similarity index 99% rename from test/mobilizon_web/resolvers/user_test.exs rename to test/graphql/resolvers/user_test.exs index e0dd8194f..74ee63979 100644 --- a/test/mobilizon_web/resolvers/user_test.exs +++ b/test/graphql/resolvers/user_test.exs @@ -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"} diff --git a/test/support/abinthe_helpers.ex b/test/support/abinthe_helpers.ex index d9c8a0c12..8bf05438d 100644 --- a/test/support/abinthe_helpers.ex +++ b/test/support/abinthe_helpers.ex @@ -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