Skip to content

Commit

Permalink
only listen to the configured actions
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabasJ committed Aug 5, 2024
1 parent e79e1eb commit 27d8d37
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/resource/subscription.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule AshGraphql.Resource.Subscription do
@moduledoc "Represents a configured query on a resource"
defstruct [
:name,
:config,
:actions,
:read_action
]

Expand All @@ -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"
Expand Down
5 changes: 4 additions & 1 deletion lib/resource/subscription/notifier.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 27d8d37

Please sign in to comment.