From 09f41328ab71496ac87a17afbaa93d85b03c21f9 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 6 Dec 2023 14:43:51 +0100 Subject: [PATCH] fix(graphql): set default value for resource type parameter Signed-off-by: Thomas Citharel --- lib/federation/activity_pub/types/resources.ex | 4 ++-- lib/graphql/schema/resource.ex | 7 ++++++- lib/mobilizon/resources/resource.ex | 2 +- test/graphql/resolvers/resource_test.exs | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/federation/activity_pub/types/resources.ex b/lib/federation/activity_pub/types/resources.ex index 59974421..fd1831e6 100644 --- a/lib/federation/activity_pub/types/resources.ex +++ b/lib/federation/activity_pub/types/resources.ex @@ -207,9 +207,9 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Resources do {:ok, Resources.get_resource(old_parent_id), Resources.get_resource(new_parent_id)} end - defp prepare_args(%{type: type} = args) do + defp prepare_args(args) do args = - case type do + case Map.get(args, :type, :link) do :folder -> args diff --git a/lib/graphql/schema/resource.ex b/lib/graphql/schema/resource.ex index 18ee1e98..22562c1d 100644 --- a/lib/graphql/schema/resource.ex +++ b/lib/graphql/schema/resource.ex @@ -22,7 +22,12 @@ defmodule Mobilizon.GraphQL.Schema.ResourceType do field(:inserted_at, :naive_datetime, description: "The resource's creation date") field(:updated_at, :naive_datetime, description: "The resource's last update date") field(:published_at, :naive_datetime, description: "The resource's publication date") - field(:type, :string, description: "The resource's type (if it's a folder)") + + field(:type, :string, + default_value: "link", + description: "The resource's type (if it's a folder)" + ) + field(:path, :string, description: "The resource's path") field(:parent, :resource, diff --git a/lib/mobilizon/resources/resource.ex b/lib/mobilizon/resources/resource.ex index e8f19caa..6b09cb0a 100644 --- a/lib/mobilizon/resources/resource.ex +++ b/lib/mobilizon/resources/resource.ex @@ -18,7 +18,7 @@ defmodule Mobilizon.Resources.Resource do summary: String.t(), url: String.t(), resource_url: String.t(), - type: atom(), + type: TypeEnum.t(), metadata: Metadata.t(), children: list(__MODULE__), parent: __MODULE__, diff --git a/test/graphql/resolvers/resource_test.exs b/test/graphql/resolvers/resource_test.exs index 4948c5b3..4f23e67d 100644 --- a/test/graphql/resolvers/resource_test.exs +++ b/test/graphql/resolvers/resource_test.exs @@ -283,7 +283,7 @@ defmodule Mobilizon.GraphQL.Resolvers.ResourceTest do } ) - assert is_nil(res["errors"]) + assert res["errors"] == nil assert res["data"]["resource"]["path"] == "/" assert String.starts_with?(res["data"]["resource"]["id"], "root_")