diff --git a/lib/resource/subscription.ex b/lib/resource/subscription.ex index b8b25acf..8404dca6 100644 --- a/lib/resource/subscription.ex +++ b/lib/resource/subscription.ex @@ -2,7 +2,7 @@ defmodule AshGraphql.Resource.Subscription do @moduledoc "Represents a configured query on a resource" defstruct [ :name, - :config, + :actions, :read_action ] @@ -11,6 +11,10 @@ defmodule AshGraphql.Resource.Subscription do type: :atom, doc: "The name to use for the subscription." ], + actions: [ + type: {:or, [{:list, :atom}, :atom]}, + doc: "The create/update/destroy actions the subsciption should listen to. Defaults to all." + ], read_action: [ type: :atom, doc: "The read action to use for reading data" diff --git a/lib/resource/subscription/notifier.ex b/lib/resource/subscription/notifier.ex index 1404eecc..5e73a7e4 100644 --- a/lib/resource/subscription/notifier.ex +++ b/lib/resource/subscription/notifier.ex @@ -7,7 +7,10 @@ defmodule AshGraphql.Resource.Subscription.Notifier do pub_sub = Info.subscription_pubsub(notification.resource) for subscription <- AshGraphql.Resource.Info.subscriptions(notification.resource) do - Absinthe.Subscription.publish(pub_sub, notification.data, [{subscription.name, "*"}]) + if is_nil(subscription.actions) or + notification.action.name in List.wrap(subscription.actions) do + Absinthe.Subscription.publish(pub_sub, notification.data, [{subscription.name, "*"}]) + end end end end