mirror of
https://github.com/ash-project/ash_graphql.git
synced 2024-09-20 05:13:33 +12:00
wip
This commit is contained in:
parent
eb96ef8c10
commit
bc8449025e
7 changed files with 57 additions and 12 deletions
|
@ -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] || %{}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 [
|
||||
|
|
|
@ -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)
|
||||
|
|
12
lib/resource/subscription/notifier.ex
Normal file
12
lib/resource/subscription/notifier.ex
Normal 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
|
32
lib/resource/transformers/subscription.ex
Normal file
32
lib/resource/transformers/subscription.ex
Normal 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
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue