Allow tag relations + bump ecto deps

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-02-14 14:19:55 +01:00
parent 4caa998ae0
commit 256d50e855
37 changed files with 515 additions and 132 deletions

View File

@@ -5,7 +5,7 @@ defmodule MobilizonWeb.AuthErrorHandler do
import Plug.Conn
def auth_error(conn, {type, _reason}, _opts) do
body = Poison.encode!(%{message: to_string(type)})
body = Jason.encode!(%{message: to_string(type)})
send_resp(conn, 401, body)
end
end

View File

@@ -40,7 +40,7 @@ defmodule MobilizonWeb.Endpoint do
Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
pass: ["*/*"],
json_decoder: Poison
json_decoder: Jason
)
plug(Plug.MethodOverride)

View File

@@ -0,0 +1,40 @@
defmodule MobilizonWeb.Resolvers.Tag do
@moduledoc """
Handles the tag-related GraphQL calls
"""
require Logger
alias Mobilizon.Events.Event
alias Mobilizon.Events.Tag
def list_tags(_parent, %{page: page, limit: limit}, _resolution) do
tags = Mobilizon.Events.list_tags(page, limit)
{:ok, tags}
end
@doc """
Retrieve the list of tags for an event
"""
def list_tags_for_event(%Event{id: id}, _args, _resolution) do
{:ok, Mobilizon.Events.list_tags_for_event(id)}
end
@doc """
Retrieve the list of related tags for a given tag ID
"""
def get_related_tags(_parent, %{tag_id: tag_id}, _resolution) do
with %Tag{} = tag <- Mobilizon.Events.get_tag!(tag_id),
tags <- Mobilizon.Events.tag_neighbors(tag) do
{:ok, tags}
end
end
@doc """
Retrieve the list of related tags for a parent tag
"""
def get_related_tags(%Tag{} = tag, _args, _resolution) do
with tags <- Mobilizon.Events.tag_neighbors(tag) do
{:ok, tags}
end
end
end

View File

@@ -8,6 +8,7 @@ defmodule MobilizonWeb.Schema.EventType do
import_types(MobilizonWeb.Schema.AddressType)
import_types(MobilizonWeb.Schema.Events.ParticipantType)
import_types(MobilizonWeb.Schema.Events.CategoryType)
import_types(MobilizonWeb.Schema.TagType)
alias MobilizonWeb.Resolvers
@desc "An event"
@@ -37,7 +38,12 @@ defmodule MobilizonWeb.Schema.EventType do
)
field(:attributed_to, :actor, description: "Who the event is attributed to (often a group)")
# field(:tags, list_of(:tag))
field(:tags, list_of(:tag),
resolve: &MobilizonWeb.Resolvers.Tag.list_tags_for_event/3,
description: "The event's tags"
)
field(:category, :category, description: "The event's category")
field(:participants, list_of(:participant),

View File

@@ -0,0 +1,30 @@
defmodule MobilizonWeb.Schema.TagType do
@moduledoc """
Schema representation for Tags
"""
use Absinthe.Schema.Notation
alias MobilizonWeb.Resolvers
@desc "A tag"
object :tag do
field(:id, :id, description: "The tag's ID")
field(:slug, :string, description: "The tags's slug")
field(:title, :string, description: "The tag's title")
field(
:related,
list_of(:tag),
resolve: &Resolvers.Tag.get_related_tags/3,
description: "Related tags to this tag"
)
end
object :tag_queries do
@desc "Get the list of tags"
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)
end
end
end