Move queries and mutations to submodules
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
7bc5589002
commit
0988ff390c
@ -13,6 +13,7 @@ defmodule MobilizonWeb.Schema do
|
|||||||
import_types(Absinthe.Type.Custom)
|
import_types(Absinthe.Type.Custom)
|
||||||
import_types(Absinthe.Plug.Types)
|
import_types(Absinthe.Plug.Types)
|
||||||
|
|
||||||
|
import_types(MobilizonWeb.Schema.UserType)
|
||||||
import_types(MobilizonWeb.Schema.ActorInterface)
|
import_types(MobilizonWeb.Schema.ActorInterface)
|
||||||
import_types(MobilizonWeb.Schema.Actors.PersonType)
|
import_types(MobilizonWeb.Schema.Actors.PersonType)
|
||||||
import_types(MobilizonWeb.Schema.Actors.GroupType)
|
import_types(MobilizonWeb.Schema.Actors.GroupType)
|
||||||
@ -116,20 +117,6 @@ defmodule MobilizonWeb.Schema do
|
|||||||
Root Query
|
Root Query
|
||||||
"""
|
"""
|
||||||
query do
|
query do
|
||||||
@desc "Get all events"
|
|
||||||
field :events, list_of(:event) do
|
|
||||||
arg(:page, :integer, default_value: 1)
|
|
||||||
arg(:limit, :integer, default_value: 10)
|
|
||||||
resolve(&Resolvers.Event.list_events/3)
|
|
||||||
end
|
|
||||||
|
|
||||||
@desc "Get all groups"
|
|
||||||
field :groups, list_of(:group) do
|
|
||||||
arg(:page, :integer, default_value: 1)
|
|
||||||
arg(:limit, :integer, default_value: 10)
|
|
||||||
resolve(&Resolvers.Group.list_groups/3)
|
|
||||||
end
|
|
||||||
|
|
||||||
@desc "Search through events, persons and groups"
|
@desc "Search through events, persons and groups"
|
||||||
field :search, list_of(:search_result) do
|
field :search, list_of(:search_result) do
|
||||||
arg(:search, non_null(:string))
|
arg(:search, non_null(:string))
|
||||||
@ -138,180 +125,24 @@ defmodule MobilizonWeb.Schema do
|
|||||||
resolve(&Resolvers.Event.search_events_and_actors/3)
|
resolve(&Resolvers.Event.search_events_and_actors/3)
|
||||||
end
|
end
|
||||||
|
|
||||||
@desc "Get an event by uuid"
|
import_fields(:user_queries)
|
||||||
field :event, :event do
|
import_fields(:person_queries)
|
||||||
arg(:uuid, non_null(:uuid))
|
import_fields(:group_queries)
|
||||||
resolve(&Resolvers.Event.find_event/3)
|
import_fields(:event_queries)
|
||||||
end
|
import_fields(:participant_queries)
|
||||||
|
import_fields(:category_queries)
|
||||||
@desc "Get all participants for an event uuid"
|
|
||||||
field :participants, list_of(:participant) do
|
|
||||||
arg(:uuid, non_null(:uuid))
|
|
||||||
arg(:page, :integer, default_value: 1)
|
|
||||||
arg(:limit, :integer, default_value: 10)
|
|
||||||
resolve(&Resolvers.Event.list_participants_for_event/3)
|
|
||||||
end
|
|
||||||
|
|
||||||
@desc "Get a group by it's preferred username"
|
|
||||||
field :group, :group do
|
|
||||||
arg(:preferred_username, non_null(:string))
|
|
||||||
resolve(&Resolvers.Group.find_group/3)
|
|
||||||
end
|
|
||||||
|
|
||||||
@desc "Get an user"
|
|
||||||
field :user, :user do
|
|
||||||
arg(:id, non_null(:id))
|
|
||||||
resolve(&Resolvers.User.find_user/3)
|
|
||||||
end
|
|
||||||
|
|
||||||
@desc "Get the current user"
|
|
||||||
field :logged_user, :user do
|
|
||||||
resolve(&Resolvers.User.get_current_user/3)
|
|
||||||
end
|
|
||||||
|
|
||||||
@desc "Get the current actor for the logged-in user"
|
|
||||||
field :logged_person, :person do
|
|
||||||
resolve(&Resolvers.Person.get_current_person/3)
|
|
||||||
end
|
|
||||||
|
|
||||||
@desc "Get a person by it's preferred username"
|
|
||||||
field :person, :person do
|
|
||||||
arg(:preferred_username, non_null(:string))
|
|
||||||
resolve(&Resolvers.Person.find_person/3)
|
|
||||||
end
|
|
||||||
|
|
||||||
@desc "Get the persons for an user"
|
|
||||||
field :identities, list_of(:person) do
|
|
||||||
resolve(&Resolvers.Person.identities/3)
|
|
||||||
end
|
|
||||||
|
|
||||||
@desc "Get the list of categories"
|
|
||||||
field :categories, non_null(list_of(:category)) do
|
|
||||||
arg(:page, :integer, default_value: 1)
|
|
||||||
arg(:limit, :integer, default_value: 10)
|
|
||||||
resolve(&Resolvers.Category.list_categories/3)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@desc """
|
@desc """
|
||||||
Root Mutation
|
Root Mutation
|
||||||
"""
|
"""
|
||||||
mutation do
|
mutation do
|
||||||
@desc "Create an event"
|
import_fields(:user_mutations)
|
||||||
field :create_event, type: :event do
|
import_fields(:person_mutations)
|
||||||
arg(:title, non_null(:string))
|
import_fields(:group_mutations)
|
||||||
arg(:description, non_null(:string))
|
import_fields(:event_mutations)
|
||||||
arg(:begins_on, non_null(:datetime))
|
import_fields(:category_mutations)
|
||||||
arg(:ends_on, :datetime)
|
import_fields(:comment_mutations)
|
||||||
arg(:state, :integer)
|
|
||||||
arg(:status, :integer)
|
|
||||||
arg(:public, :boolean)
|
|
||||||
arg(:thumbnail, :string)
|
|
||||||
arg(:large_image, :string)
|
|
||||||
arg(:publish_at, :datetime)
|
|
||||||
arg(:online_address, :string)
|
|
||||||
arg(:phone_address, :string)
|
|
||||||
arg(:organizer_actor_id, non_null(:id))
|
|
||||||
arg(:category, non_null(:string))
|
|
||||||
|
|
||||||
resolve(&Resolvers.Event.create_event/3)
|
|
||||||
end
|
|
||||||
|
|
||||||
@desc "Delete an event"
|
|
||||||
field :delete_event, :deleted_object do
|
|
||||||
arg(:event_id, non_null(:integer))
|
|
||||||
arg(:actor_id, non_null(:integer))
|
|
||||||
|
|
||||||
resolve(&Resolvers.Event.delete_event/3)
|
|
||||||
end
|
|
||||||
|
|
||||||
@desc "Create a comment"
|
|
||||||
field :create_comment, type: :comment do
|
|
||||||
arg(:text, non_null(:string))
|
|
||||||
arg(:actor_username, non_null(:string))
|
|
||||||
|
|
||||||
resolve(&Resolvers.Comment.create_comment/3)
|
|
||||||
end
|
|
||||||
|
|
||||||
@desc "Create a category with a title, description and picture"
|
|
||||||
field :create_category, type: :category do
|
|
||||||
arg(:title, non_null(:string))
|
|
||||||
arg(:description, non_null(:string))
|
|
||||||
arg(:picture, non_null(:upload))
|
|
||||||
resolve(&Resolvers.Category.create_category/3)
|
|
||||||
end
|
|
||||||
|
|
||||||
@desc "Create an user"
|
|
||||||
field :create_user, type: :user do
|
|
||||||
arg(:email, non_null(:string))
|
|
||||||
arg(:password, non_null(:string))
|
|
||||||
|
|
||||||
resolve(handle_errors(&Resolvers.User.create_user/3))
|
|
||||||
end
|
|
||||||
|
|
||||||
@desc "Validate an user after registration"
|
|
||||||
field :validate_user, type: :login do
|
|
||||||
arg(:token, non_null(:string))
|
|
||||||
resolve(&Resolvers.User.validate_user/3)
|
|
||||||
end
|
|
||||||
|
|
||||||
@desc "Resend registration confirmation token"
|
|
||||||
field :resend_confirmation_email, type: :string do
|
|
||||||
arg(:email, non_null(:string))
|
|
||||||
arg(:locale, :string, default_value: "en")
|
|
||||||
resolve(&Resolvers.User.resend_confirmation_email/3)
|
|
||||||
end
|
|
||||||
|
|
||||||
@desc "Send a link through email to reset user password"
|
|
||||||
field :send_reset_password, type: :string do
|
|
||||||
arg(:email, non_null(:string))
|
|
||||||
arg(:locale, :string, default_value: "en")
|
|
||||||
resolve(&Resolvers.User.send_reset_password/3)
|
|
||||||
end
|
|
||||||
|
|
||||||
@desc "Reset user password"
|
|
||||||
field :reset_password, type: :login do
|
|
||||||
arg(:token, non_null(:string))
|
|
||||||
arg(:password, non_null(:string))
|
|
||||||
arg(:locale, :string, default_value: "en")
|
|
||||||
resolve(&Resolvers.User.reset_password/3)
|
|
||||||
end
|
|
||||||
|
|
||||||
@desc "Login an user"
|
|
||||||
field :login, :login do
|
|
||||||
arg(:email, non_null(:string))
|
|
||||||
arg(:password, non_null(:string))
|
|
||||||
resolve(&Resolvers.User.login_user/3)
|
|
||||||
end
|
|
||||||
|
|
||||||
@desc "Change default actor for user"
|
|
||||||
field :change_default_actor, :user do
|
|
||||||
arg(:preferred_username, non_null(:string))
|
|
||||||
resolve(&Resolvers.User.change_default_actor/3)
|
|
||||||
end
|
|
||||||
|
|
||||||
@desc "Create a new person for user"
|
|
||||||
field :create_person, :person do
|
|
||||||
arg(:preferred_username, non_null(:string))
|
|
||||||
arg(:name, :string, description: "The displayed name for the new profile")
|
|
||||||
|
|
||||||
arg(:description, :string, description: "The summary for the new profile", default_value: "")
|
|
||||||
|
|
||||||
resolve(&Resolvers.Person.create_person/3)
|
|
||||||
end
|
|
||||||
|
|
||||||
@desc "Create a group"
|
|
||||||
field :create_group, :group do
|
|
||||||
arg(:preferred_username, non_null(:string), description: "The name for the group")
|
|
||||||
arg(:name, :string, description: "The displayed name for the group")
|
|
||||||
arg(:description, :string, description: "The summary for the group", default_value: "")
|
|
||||||
|
|
||||||
arg(:admin_actor_username, :string,
|
|
||||||
description: "The actor's username which will be the admin (otherwise user's default one)"
|
|
||||||
)
|
|
||||||
|
|
||||||
resolve(&Resolvers.Group.create_group/3)
|
|
||||||
end
|
|
||||||
|
|
||||||
# @desc "Upload a picture"
|
# @desc "Upload a picture"
|
||||||
# field :upload_picture, :picture do
|
# field :upload_picture, :picture do
|
||||||
@ -319,24 +150,4 @@ defmodule MobilizonWeb.Schema do
|
|||||||
# resolve(&Resolvers.Upload.upload_picture/3)
|
# resolve(&Resolvers.Upload.upload_picture/3)
|
||||||
# end
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_errors(fun) do
|
|
||||||
fn source, args, info ->
|
|
||||||
case Absinthe.Resolution.call(fun, source, args, info) do
|
|
||||||
{:error, %Ecto.Changeset{} = changeset} -> format_changeset(changeset)
|
|
||||||
val -> val
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def format_changeset(changeset) do
|
|
||||||
# {:error, [email: {"has already been taken", []}]}
|
|
||||||
errors =
|
|
||||||
changeset.errors
|
|
||||||
|> Enum.map(fn {_key, {value, context}} ->
|
|
||||||
[message: "#{value}", details: context]
|
|
||||||
end)
|
|
||||||
|
|
||||||
{:error, errors}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -5,6 +5,7 @@ defmodule MobilizonWeb.Schema.Actors.GroupType do
|
|||||||
use Absinthe.Schema.Notation
|
use Absinthe.Schema.Notation
|
||||||
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
||||||
import_types(MobilizonWeb.Schema.Actors.MemberType)
|
import_types(MobilizonWeb.Schema.Actors.MemberType)
|
||||||
|
alias MobilizonWeb.Resolvers
|
||||||
|
|
||||||
@desc """
|
@desc """
|
||||||
Represents a group of actors
|
Represents a group of actors
|
||||||
|
@ -4,8 +4,8 @@ defmodule MobilizonWeb.Schema.Actors.PersonType do
|
|||||||
"""
|
"""
|
||||||
use Absinthe.Schema.Notation
|
use Absinthe.Schema.Notation
|
||||||
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
||||||
import_types(MobilizonWeb.Schema.UserType)
|
|
||||||
alias Mobilizon.Events
|
alias Mobilizon.Events
|
||||||
|
alias MobilizonWeb.Resolvers
|
||||||
|
|
||||||
@desc """
|
@desc """
|
||||||
Represents a person identity
|
Represents a person identity
|
||||||
@ -46,4 +46,34 @@ defmodule MobilizonWeb.Schema.Actors.PersonType do
|
|||||||
description: "A list of the events this actor has organized"
|
description: "A list of the events this actor has organized"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
object :person_queries do
|
||||||
|
@desc "Get the current actor for the logged-in user"
|
||||||
|
field :logged_person, :person do
|
||||||
|
resolve(&Resolvers.Person.get_current_person/3)
|
||||||
|
end
|
||||||
|
|
||||||
|
@desc "Get a person by it's preferred username"
|
||||||
|
field :person, :person do
|
||||||
|
arg(:preferred_username, non_null(:string))
|
||||||
|
resolve(&Resolvers.Person.find_person/3)
|
||||||
|
end
|
||||||
|
|
||||||
|
@desc "Get the persons for an user"
|
||||||
|
field :identities, list_of(:person) do
|
||||||
|
resolve(&Resolvers.Person.identities/3)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
object :person_mutations do
|
||||||
|
@desc "Create a new person for user"
|
||||||
|
field :create_person, :person do
|
||||||
|
arg(:preferred_username, non_null(:string))
|
||||||
|
arg(:name, :string, description: "The displayed name for the new profile")
|
||||||
|
|
||||||
|
arg(:description, :string, description: "The summary for the new profile", default_value: "")
|
||||||
|
|
||||||
|
resolve(&Resolvers.Person.create_person/3)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,6 +3,7 @@ defmodule MobilizonWeb.Schema.CommentType do
|
|||||||
Schema representation for Comment
|
Schema representation for Comment
|
||||||
"""
|
"""
|
||||||
use Absinthe.Schema.Notation
|
use Absinthe.Schema.Notation
|
||||||
|
alias MobilizonWeb.Resolvers.Comment
|
||||||
|
|
||||||
@desc "A comment"
|
@desc "A comment"
|
||||||
object :comment do
|
object :comment do
|
||||||
@ -29,4 +30,14 @@ defmodule MobilizonWeb.Schema.CommentType do
|
|||||||
value(:moderated, description: "Visible only after a moderator accepted")
|
value(:moderated, description: "Visible only after a moderator accepted")
|
||||||
value(:invite, description: "visible only to people invited")
|
value(:invite, description: "visible only to people invited")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
object :comment_mutations do
|
||||||
|
@desc "Create a comment"
|
||||||
|
field :create_comment, type: :comment do
|
||||||
|
arg(:text, non_null(:string))
|
||||||
|
arg(:actor_username, non_null(:string))
|
||||||
|
|
||||||
|
resolve(&Comment.create_comment/3)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,6 +8,7 @@ defmodule MobilizonWeb.Schema.EventType do
|
|||||||
import_types(MobilizonWeb.Schema.AddressType)
|
import_types(MobilizonWeb.Schema.AddressType)
|
||||||
import_types(MobilizonWeb.Schema.Events.ParticipantType)
|
import_types(MobilizonWeb.Schema.Events.ParticipantType)
|
||||||
import_types(MobilizonWeb.Schema.Events.CategoryType)
|
import_types(MobilizonWeb.Schema.Events.CategoryType)
|
||||||
|
alias MobilizonWeb.Resolvers
|
||||||
|
|
||||||
@desc "An event"
|
@desc "An event"
|
||||||
object :event do
|
object :event do
|
||||||
@ -70,4 +71,49 @@ defmodule MobilizonWeb.Schema.EventType do
|
|||||||
value(:confirmed, description: "The event is confirmed")
|
value(:confirmed, description: "The event is confirmed")
|
||||||
value(:cancelled, description: "The event is cancelled")
|
value(:cancelled, description: "The event is cancelled")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
object :event_queries do
|
||||||
|
@desc "Get all events"
|
||||||
|
field :events, list_of(:event) do
|
||||||
|
arg(:page, :integer, default_value: 1)
|
||||||
|
arg(:limit, :integer, default_value: 10)
|
||||||
|
resolve(&Resolvers.Event.list_events/3)
|
||||||
|
end
|
||||||
|
|
||||||
|
@desc "Get an event by uuid"
|
||||||
|
field :event, :event do
|
||||||
|
arg(:uuid, non_null(:uuid))
|
||||||
|
resolve(&Resolvers.Event.find_event/3)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
object :event_mutations do
|
||||||
|
@desc "Create an event"
|
||||||
|
field :create_event, type: :event do
|
||||||
|
arg(:title, non_null(:string))
|
||||||
|
arg(:description, non_null(:string))
|
||||||
|
arg(:begins_on, non_null(:datetime))
|
||||||
|
arg(:ends_on, :datetime)
|
||||||
|
arg(:state, :integer)
|
||||||
|
arg(:status, :integer)
|
||||||
|
arg(:public, :boolean)
|
||||||
|
arg(:thumbnail, :string)
|
||||||
|
arg(:large_image, :string)
|
||||||
|
arg(:publish_at, :datetime)
|
||||||
|
arg(:online_address, :string)
|
||||||
|
arg(:phone_address, :string)
|
||||||
|
arg(:organizer_actor_id, non_null(:id))
|
||||||
|
arg(:category, non_null(:string))
|
||||||
|
|
||||||
|
resolve(&Resolvers.Event.create_event/3)
|
||||||
|
end
|
||||||
|
|
||||||
|
@desc "Delete an event"
|
||||||
|
field :delete_event, :deleted_object do
|
||||||
|
arg(:event_id, non_null(:integer))
|
||||||
|
arg(:actor_id, non_null(:integer))
|
||||||
|
|
||||||
|
resolve(&Resolvers.Event.delete_event/3)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,6 +3,7 @@ defmodule MobilizonWeb.Schema.Events.CategoryType do
|
|||||||
Schema representation for Category
|
Schema representation for Category
|
||||||
"""
|
"""
|
||||||
use Absinthe.Schema.Notation
|
use Absinthe.Schema.Notation
|
||||||
|
alias MobilizonWeb.Resolvers
|
||||||
|
|
||||||
@desc "A category"
|
@desc "A category"
|
||||||
object :category do
|
object :category do
|
||||||
@ -11,4 +12,23 @@ defmodule MobilizonWeb.Schema.Events.CategoryType do
|
|||||||
field(:picture, :picture, description: "The category's picture")
|
field(:picture, :picture, description: "The category's picture")
|
||||||
field(:title, :string, description: "The category's title")
|
field(:title, :string, description: "The category's title")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
object :category_queries do
|
||||||
|
@desc "Get the list of categories"
|
||||||
|
field :categories, non_null(list_of(:category)) do
|
||||||
|
arg(:page, :integer, default_value: 1)
|
||||||
|
arg(:limit, :integer, default_value: 10)
|
||||||
|
resolve(&Resolvers.Category.list_categories/3)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
object :category_mutations do
|
||||||
|
@desc "Create a category with a title, description and picture"
|
||||||
|
field :create_category, type: :category do
|
||||||
|
arg(:title, non_null(:string))
|
||||||
|
arg(:description, non_null(:string))
|
||||||
|
arg(:picture, non_null(:upload))
|
||||||
|
resolve(&Resolvers.Category.create_category/3)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -4,6 +4,7 @@ defmodule MobilizonWeb.Schema.Events.ParticipantType do
|
|||||||
"""
|
"""
|
||||||
use Absinthe.Schema.Notation
|
use Absinthe.Schema.Notation
|
||||||
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
||||||
|
alias MobilizonWeb.Resolvers
|
||||||
|
|
||||||
@desc "Represents a participant to an event"
|
@desc "Represents a participant to an event"
|
||||||
object :participant do
|
object :participant do
|
||||||
@ -15,4 +16,14 @@ defmodule MobilizonWeb.Schema.Events.ParticipantType do
|
|||||||
field(:actor, :actor, description: "The actor that participates to the event")
|
field(:actor, :actor, description: "The actor that participates to the event")
|
||||||
field(:role, :integer, description: "The role of this actor at this event")
|
field(:role, :integer, description: "The role of this actor at this event")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
object :participant_queries do
|
||||||
|
@desc "Get all participants for an event uuid"
|
||||||
|
field :participants, list_of(:participant) do
|
||||||
|
arg(:uuid, non_null(:uuid))
|
||||||
|
arg(:page, :integer, default_value: 1)
|
||||||
|
arg(:limit, :integer, default_value: 10)
|
||||||
|
resolve(&Resolvers.Event.list_participants_for_event/3)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,6 +3,8 @@ defmodule MobilizonWeb.Schema.UserType do
|
|||||||
Schema representation for User
|
Schema representation for User
|
||||||
"""
|
"""
|
||||||
use Absinthe.Schema.Notation
|
use Absinthe.Schema.Notation
|
||||||
|
alias MobilizonWeb.Resolvers.User
|
||||||
|
import MobilizonWeb.Schema.Utils
|
||||||
|
|
||||||
@desc "A local user of Mobilizon"
|
@desc "A local user of Mobilizon"
|
||||||
object :user do
|
object :user do
|
||||||
@ -33,4 +35,68 @@ defmodule MobilizonWeb.Schema.UserType do
|
|||||||
description: "The token sent when requesting password token"
|
description: "The token sent when requesting password token"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
object :user_queries do
|
||||||
|
@desc "Get an user"
|
||||||
|
field :user, :user do
|
||||||
|
arg(:id, non_null(:id))
|
||||||
|
resolve(&User.find_user/3)
|
||||||
|
end
|
||||||
|
|
||||||
|
@desc "Get the current user"
|
||||||
|
field :logged_user, :user do
|
||||||
|
resolve(&User.get_current_user/3)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
object :user_mutations do
|
||||||
|
@desc "Create an user"
|
||||||
|
field :create_user, type: :user do
|
||||||
|
arg(:email, non_null(:string))
|
||||||
|
arg(:password, non_null(:string))
|
||||||
|
|
||||||
|
resolve(handle_errors(&User.create_user/3))
|
||||||
|
end
|
||||||
|
|
||||||
|
@desc "Validate an user after registration"
|
||||||
|
field :validate_user, type: :login do
|
||||||
|
arg(:token, non_null(:string))
|
||||||
|
resolve(&User.validate_user/3)
|
||||||
|
end
|
||||||
|
|
||||||
|
@desc "Resend registration confirmation token"
|
||||||
|
field :resend_confirmation_email, type: :string do
|
||||||
|
arg(:email, non_null(:string))
|
||||||
|
arg(:locale, :string, default_value: "en")
|
||||||
|
resolve(&User.resend_confirmation_email/3)
|
||||||
|
end
|
||||||
|
|
||||||
|
@desc "Send a link through email to reset user password"
|
||||||
|
field :send_reset_password, type: :string do
|
||||||
|
arg(:email, non_null(:string))
|
||||||
|
arg(:locale, :string, default_value: "en")
|
||||||
|
resolve(&User.send_reset_password/3)
|
||||||
|
end
|
||||||
|
|
||||||
|
@desc "Reset user password"
|
||||||
|
field :reset_password, type: :login do
|
||||||
|
arg(:token, non_null(:string))
|
||||||
|
arg(:password, non_null(:string))
|
||||||
|
arg(:locale, :string, default_value: "en")
|
||||||
|
resolve(&User.reset_password/3)
|
||||||
|
end
|
||||||
|
|
||||||
|
@desc "Login an user"
|
||||||
|
field :login, :login do
|
||||||
|
arg(:email, non_null(:string))
|
||||||
|
arg(:password, non_null(:string))
|
||||||
|
resolve(&User.login_user/3)
|
||||||
|
end
|
||||||
|
|
||||||
|
@desc "Change default actor for user"
|
||||||
|
field :change_default_actor, :user do
|
||||||
|
arg(:preferred_username, non_null(:string))
|
||||||
|
resolve(&User.change_default_actor/3)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
21
lib/mobilizon_web/schema/utils.ex
Normal file
21
lib/mobilizon_web/schema/utils.ex
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
defmodule MobilizonWeb.Schema.Utils do
|
||||||
|
def handle_errors(fun) do
|
||||||
|
fn source, args, info ->
|
||||||
|
case Absinthe.Resolution.call(fun, source, args, info) do
|
||||||
|
{:error, %Ecto.Changeset{} = changeset} -> format_changeset(changeset)
|
||||||
|
val -> val
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def format_changeset(changeset) do
|
||||||
|
# {:error, [email: {"has already been taken", []}]}
|
||||||
|
errors =
|
||||||
|
changeset.errors
|
||||||
|
|> Enum.map(fn {_key, {value, context}} ->
|
||||||
|
[message: "#{value}", details: context]
|
||||||
|
end)
|
||||||
|
|
||||||
|
{:error, errors}
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user