This commit is contained in:
Barnabas Jovanovics 2024-02-06 09:24:44 +01:00
parent eb96ef8c10
commit bc8449025e
7 changed files with 57 additions and 12 deletions

View file

@ -13,8 +13,6 @@ defmodule AshGraphql.Graphql.Resolver do
%{arguments: arguments, context: context} = resolution,
{domain, resource, %AshGraphql.Resource.Action{name: query_name, action: action}, input?}
) do
dbg()
arguments =
if input? do
arguments[:input] || %{}

View file

@ -442,7 +442,8 @@ defmodule AshGraphql.Resource do
@transformers [
AshGraphql.Resource.Transformers.RequireKeysetForRelayQueries,
AshGraphql.Resource.Transformers.ValidateActions,
AshGraphql.Resource.Transformers.ValidateCompatibleNames
AshGraphql.Resource.Transformers.ValidateCompatibleNames,
AshGraphql.Resource.Transformers.Subscription
]
@verifiers [
@ -1169,7 +1170,6 @@ defmodule AshGraphql.Resource do
__reference__: ref(__ENV__)
}
end)
|> dbg()
end
@doc false

View file

@ -2,8 +2,11 @@ defmodule AshGraphql.Resource.Subscription do
@moduledoc "Represents a configured query on a resource"
defstruct [
:name,
# :arg = filter,
:config,
:resolve
:read_action
# :topic, fn _, _ -> {:ok, topic} | :error,
# :trigger fn notification -> {:ok, topics}
]
@subscription_schema [

View file

@ -8,8 +8,6 @@ defmodule AshGraphql.Resource.Subscription.DefaultResolve do
%{arguments: arguments, context: context} = resolution,
{api, resource, %AshGraphql.Resource.Subscription{}, input?}
) do
dbg()
result =
AshGraphql.Subscription.query_for_subscription(
resource,
@ -19,7 +17,6 @@ defmodule AshGraphql.Resource.Subscription.DefaultResolve do
# |> Ash.Query.filter(id == ^args.id)
|> Ash.Query.limit(1)
|> api.read_one(actor: resolution.context[:current_user])
|> IO.inspect()
resolution
|> Absinthe.Resolution.put_result(result)

View file

@ -0,0 +1,12 @@
defmodule AshGraphq.Resource.Subscription.Notifier do
use Ash.Notifier
@impl Ash.Notifier
def notify(notification) do
IO.inspect(notification, label: :Notifier)
Absinthe.Subscription.publish(AshGraphql.Test.PubSub, notification.data,
subscrible_created: "*"
)
end
end

View file

@ -0,0 +1,32 @@
defmodule AshGraphql.Resource.Transformers.Subscription do
@moduledoc """
Adds the notifier for Subscriptions to the Resource
"""
use Spark.Dsl.Transformer
alias Spark.Dsl.Transformer
def transform(dsl) do
case dsl
|> Transformer.get_entities([:graphql, :subscriptions]) do
[] ->
{:ok, dsl}
_ ->
{:ok,
dsl
|> Transformer.set_option(
[:resource],
:simple_notifiers,
[
AshGraphq.Resource.Subscription.Notifier
] ++
Transformer.get_option(dsl, [:resource], :simple_notifiers, [])
)
|> dbg()}
end
{:ok, dsl}
end
end

View file

@ -6,10 +6,6 @@ defmodule AshGraphql.Test.Subscribable do
require Ash.Query
resource do
simple_notifiers([AshGraphql.Resource.Notifier])
end
graphql do
type :subscribable
@ -20,6 +16,13 @@ defmodule AshGraphql.Test.Subscribable do
mutations do
create :create_subscribable, :create
end
subscriptions do
subscribe(:subscribable_created, fn _, _ ->
IO.inspect("bucket_created")
{:ok, topic: "*"}
end)
end
end
actions do