New AshGraphql Feature: Subscriptions

You can now add subscriptions using the DSL.

subscriptions do
  pubsub YourAppWeb.Endpoint

  subscribe :something_changed do
    action_types [:create, :update, :destroy]
  end
end

Right now, you still need to add the dependency from github. A release will follow soon.
I created a small demo video showing the setup.

10 Likes

Amazing work! I will try it out asap!

Off-topic: I noticed that around 6:10 of the video, you saved a Ash resource and the formatter changed the resource code blocks order. How did you do that?

Also, another question.

Can you somehow add logic to filter out data based on some criteria?

For example, let’s say I have a resource that contains data for multiple organizations, I want to subscribe to that resource actions, but I don’t want it to allow an me to subscribe to all data from all organizations for that resource, only for the ones that are from my own organization.

What you subscribe to is a query built for a read action, so that read action can contain filters. Additionally, if you have policies that filter the data, they will be applied to all data before a notification is sent.

3 Likes

That is the Spark.Formatter plugin. You can configure it to set a section order for any Spark DSL including Ash.Resource.

https://hexdocs.pm/spark/Spark.Formatter.html

1 Like