2020-02-18 07:57:00 +00:00
|
|
|
defmodule Mobilizon.GraphQL.Schema.ResourceType do
|
|
|
|
@moduledoc """
|
|
|
|
Schema representation for Resources
|
|
|
|
"""
|
|
|
|
use Absinthe.Schema.Notation
|
|
|
|
alias Mobilizon.GraphQL.Resolvers.Resource
|
2020-06-25 16:47:17 +00:00
|
|
|
alias Mobilizon.Resources
|
|
|
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
2020-02-18 07:57:00 +00:00
|
|
|
|
|
|
|
@desc "A resource"
|
|
|
|
object :resource do
|
2021-02-24 18:06:48 +00:00
|
|
|
interfaces([:activity_object])
|
2020-02-18 07:57:00 +00:00
|
|
|
field(:id, :id, description: "The resource's ID")
|
|
|
|
field(:title, :string, description: "The resource's title")
|
|
|
|
field(:summary, :string, description: "The resource's summary")
|
|
|
|
field(:url, :string, description: "The resource's URL")
|
|
|
|
field(:resource_url, :string, description: "The resource's URL")
|
|
|
|
field(:metadata, :resource_metadata, description: "The resource's metadata")
|
|
|
|
field(:creator, :actor, description: "The resource's creator")
|
|
|
|
field(:actor, :actor, description: "The resource's owner")
|
|
|
|
field(:inserted_at, :naive_datetime, description: "The resource's creation date")
|
|
|
|
field(:updated_at, :naive_datetime, description: "The resource's last update date")
|
2021-06-14 13:13:08 +00:00
|
|
|
field(:published_at, :naive_datetime, description: "The resource's publication date")
|
2020-02-18 07:57:00 +00:00
|
|
|
field(:type, :string, description: "The resource's type (if it's a folder)")
|
|
|
|
field(:path, :string, description: "The resource's path")
|
2020-06-25 16:47:17 +00:00
|
|
|
|
|
|
|
field(:parent, :resource, description: "The resource's parent", resolve: dataloader(Resources))
|
2020-02-18 07:57:00 +00:00
|
|
|
|
|
|
|
field :children, :paginated_resource_list do
|
|
|
|
description("Children resources in folder")
|
2021-06-14 13:12:38 +00:00
|
|
|
|
|
|
|
arg(:page, :integer,
|
|
|
|
default_value: 1,
|
|
|
|
description: "The page in the paginated resource list"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:limit, :integer, default_value: 10, description: "The limit of resources per page")
|
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
resolve(&Resource.find_resources_for_parent/3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-19 16:06:28 +00:00
|
|
|
@desc """
|
|
|
|
A paginated list of resources
|
|
|
|
"""
|
2020-02-18 07:57:00 +00:00
|
|
|
object :paginated_resource_list do
|
|
|
|
field(:elements, list_of(:resource), description: "A list of resources")
|
|
|
|
field(:total, :integer, description: "The total number of resources in the list")
|
|
|
|
end
|
|
|
|
|
2020-11-19 16:06:28 +00:00
|
|
|
@desc """
|
|
|
|
The metadata associated to the resource
|
|
|
|
"""
|
2020-02-18 07:57:00 +00:00
|
|
|
object :resource_metadata do
|
|
|
|
field(:type, :string, description: "The type of the resource")
|
|
|
|
field(:title, :string, description: "The resource's metadata title")
|
|
|
|
field(:description, :string, description: "The resource's metadata description")
|
2021-01-26 09:05:31 +00:00
|
|
|
|
|
|
|
field(:image_remote_url, :string,
|
|
|
|
description: "The resource's metadata image",
|
|
|
|
resolve: &Resource.proxyify_pictures/3
|
|
|
|
)
|
|
|
|
|
2020-11-19 16:06:28 +00:00
|
|
|
field(:width, :integer, description: "The resource's metadata image width")
|
|
|
|
field(:height, :integer, description: "The resource's metadata image height")
|
|
|
|
field(:author_name, :string, description: "The resource's author name")
|
|
|
|
field(:author_url, :string, description: "The resource's author URL")
|
|
|
|
field(:provider_name, :string, description: "The resource's provider name")
|
|
|
|
field(:provider_url, :string, description: "The resource's provider URL")
|
|
|
|
field(:html, :string, description: "The resource's author name")
|
2021-01-26 09:05:31 +00:00
|
|
|
|
|
|
|
field(:favicon_url, :string,
|
|
|
|
description: "The resource's favicon URL",
|
|
|
|
resolve: &Resource.proxyify_pictures/3
|
|
|
|
)
|
2020-02-18 07:57:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
object :resource_queries do
|
|
|
|
@desc "Get a resource"
|
|
|
|
field :resource, :resource do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:path, non_null(:string), description: "The path for the resource")
|
|
|
|
|
|
|
|
arg(:username, non_null(:string),
|
|
|
|
description: "The federated username for the group resource"
|
|
|
|
)
|
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
resolve(&Resource.get_resource/3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
object :resource_mutations do
|
|
|
|
@desc "Create a resource"
|
|
|
|
field :create_resource, :resource do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:parent_id, :id,
|
|
|
|
description: "The ID from the parent resource (folder) this resource is in"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:actor_id, non_null(:id), description: "The group this resource belongs to")
|
|
|
|
arg(:title, non_null(:string), description: "This resource's title")
|
|
|
|
arg(:summary, :string, description: "This resource summary")
|
|
|
|
arg(:resource_url, :string, description: "This resource's own original URL")
|
|
|
|
arg(:type, :string, default_value: "link", description: "The type for this resource")
|
2020-02-18 07:57:00 +00:00
|
|
|
|
|
|
|
resolve(&Resource.create_resource/3)
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Update a resource"
|
|
|
|
field :update_resource, :resource do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:id, non_null(:id), description: "The resource ID")
|
|
|
|
arg(:title, :string, description: "The new resource title")
|
|
|
|
arg(:summary, :string, description: "The new resource summary")
|
|
|
|
arg(:parent_id, :id, description: "The new resource parent ID (if the resource is moved)")
|
|
|
|
arg(:resource_url, :string, description: "The new resource URL")
|
2020-02-18 07:57:00 +00:00
|
|
|
|
|
|
|
resolve(&Resource.update_resource/3)
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Delete a resource"
|
|
|
|
field :delete_resource, :deleted_object do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:id, non_null(:id), description: "The resource ID")
|
2020-02-18 07:57:00 +00:00
|
|
|
resolve(&Resource.delete_resource/3)
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Get a preview for a resource link"
|
|
|
|
field :preview_resource_link, :resource_metadata do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:resource_url, non_null(:string), description: "The link to crawl to get of preview of")
|
2020-02-18 07:57:00 +00:00
|
|
|
resolve(&Resource.preview_resource_link/3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|