2019-01-14 17:13:17 +01:00
|
|
|
defmodule MobilizonWeb.Schema.Events.ParticipantType do
|
2019-01-14 17:48:08 +01:00
|
|
|
@moduledoc """
|
|
|
|
Schema representation for Participant
|
|
|
|
"""
|
2019-01-14 17:13:17 +01:00
|
|
|
use Absinthe.Schema.Notation
|
2019-01-14 17:48:08 +01:00
|
|
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
2019-01-25 15:41:10 +01:00
|
|
|
alias MobilizonWeb.Resolvers
|
2019-02-01 15:38:35 +01:00
|
|
|
alias Mobilizon.Events
|
|
|
|
alias Mobilizon.Actors
|
2019-01-14 17:13:17 +01:00
|
|
|
|
|
|
|
@desc "Represents a participant to an event"
|
|
|
|
object :participant do
|
2019-02-01 15:38:35 +01:00
|
|
|
field(
|
|
|
|
:event,
|
|
|
|
:event,
|
2019-01-14 17:13:17 +01:00
|
|
|
resolve: dataloader(Events),
|
|
|
|
description: "The event which the actor participates in"
|
|
|
|
)
|
|
|
|
|
2019-02-01 15:38:35 +01:00
|
|
|
field(
|
|
|
|
:actor,
|
|
|
|
:actor,
|
|
|
|
resolve: dataloader(Actors),
|
|
|
|
description: "The actor that participates to the event"
|
|
|
|
)
|
|
|
|
|
2019-01-14 17:13:17 +01:00
|
|
|
field(:role, :integer, description: "The role of this actor at this event")
|
|
|
|
end
|
2019-01-25 15:41:10 +01:00
|
|
|
|
2019-02-01 15:38:35 +01:00
|
|
|
@desc "Represents a deleted participant"
|
|
|
|
object :deleted_participant do
|
|
|
|
field(:event, :deleted_object)
|
|
|
|
field(:actor, :deleted_object)
|
|
|
|
end
|
|
|
|
|
2019-01-25 15:41:10 +01:00
|
|
|
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
|
2019-02-01 15:38:35 +01:00
|
|
|
|
|
|
|
object :participant_mutations do
|
|
|
|
@desc "Join an event"
|
|
|
|
field :join_event, :participant do
|
2019-09-09 09:31:08 +02:00
|
|
|
arg(:event_id, non_null(:id))
|
|
|
|
arg(:actor_id, non_null(:id))
|
2019-02-01 15:38:35 +01:00
|
|
|
|
|
|
|
resolve(&Resolvers.Event.actor_join_event/3)
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Leave an event"
|
|
|
|
field :leave_event, :deleted_participant do
|
2019-09-09 09:31:08 +02:00
|
|
|
arg(:event_id, non_null(:id))
|
|
|
|
arg(:actor_id, non_null(:id))
|
2019-02-01 15:38:35 +01:00
|
|
|
|
|
|
|
resolve(&Resolvers.Event.actor_leave_event/3)
|
|
|
|
end
|
|
|
|
end
|
2019-01-14 17:13:17 +01:00
|
|
|
end
|