From 47ed2c92d0bebcd2d0b6594955ee15f7d068ee05 Mon Sep 17 00:00:00 2001 From: Barnabas Jovanovics Date: Mon, 5 Aug 2024 16:35:00 +0200 Subject: [PATCH] only listen to the configured actions --- lib/resource/subscription.ex | 6 +++++- lib/resource/subscription/notifier.ex | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) 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