Allow tag relations + bump ecto deps
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -40,7 +40,7 @@ defmodule MobilizonWeb.Endpoint do
|
||||
Plug.Parsers,
|
||||
parsers: [:urlencoded, :multipart, :json],
|
||||
pass: ["*/*"],
|
||||
json_decoder: Poison
|
||||
json_decoder: Jason
|
||||
)
|
||||
|
||||
plug(Plug.MethodOverride)
|
||||
|
||||
40
lib/mobilizon_web/resolvers/tag.ex
Normal file
40
lib/mobilizon_web/resolvers/tag.ex
Normal 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
|
||||
@@ -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),
|
||||
|
||||
30
lib/mobilizon_web/schema/tag.ex
Normal file
30
lib/mobilizon_web/schema/tag.ex
Normal 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
|
||||
Reference in New Issue
Block a user