Ash GraphQL Subscriptions

Do AshGraphQL subscriptions fire when resources are updated via code interface or only when updated through GraphQL mutations? Having some trouble with getting my subscriptions to fire on my frontend when updating changes on my backend as part of a workflow
10 Replies
barnabasj
barnabasj•2mo ago
it uses Ash notifiers, so as long as it goes through a configured action it should fire, doesn't matter if gql or not
roberto
robertoOP•2mo ago
Would this also be true if im triggering an update action through an iex session?
barnabasj
barnabasj•2mo ago
Should work as long as you called an ash action
roberto
robertoOP•2mo ago
Thanks for confirming! im still running into issues that ive been trying to solve for a couple days now
graphql do
subscriptions do
subscribe :content_section_updated do
pubsub(ZinniaWeb.Endpoint)
action_types([:update])
end
end
end
graphql do
subscriptions do
subscribe :content_section_updated do
pubsub(ZinniaWeb.Endpoint)
action_types([:update])
end
end
end
I'm updating via code interface like:
Zinnia.ContentGeneration.update_content_section!(section, %{state: :completed})
Zinnia.ContentGeneration.update_content_section!(section, %{state: :completed})
I can see the subscription being made via sockets on my react frontend but the messages never come thru weirdly its working for all my other resources but this one
barnabasj
barnabasj•2mo ago
could it be something with permissions, we filter results that a subscribed client isn't allowed to see, and not send that over the wire I would start looking around here https://github.com/ash-project/ash_graphql/blob/d724c46d7d44cd516e26155d144ee7fe3f569867/lib/subscription/batcher.ex#L287-L287 maybe add some IO.inspects here to see what's going on
GitHub
ash_graphql/lib/subscription/batcher.ex at d724c46d7d44cd516e26155d...
The extension for building GraphQL APIs with Ash. Contribute to ash-project/ash_graphql development by creating an account on GitHub.
roberto
robertoOP•2mo ago
ill take a look, could it be because this resource doenst have multitenacy enabled while the others working do?
barnabasj
barnabasj•2mo ago
🤔 could be. Definitely a case I haven't thought of before. If you can reproduce it in a test or in a separate repo. I can talk a look directly
roberto
robertoOP•2mo ago
sounds good OK! took your advice here
roberto
robertoOP•2mo ago
GitHub
ash_graphql/lib/subscription/config.ex at 3fe8b4ce467995875873fb3d8...
The extension for building GraphQL APIs with Ash. Contribute to ash-project/ash_graphql development by creating an account on GitHub.
GitHub
ash_graphql/lib/subscription/notifier.ex at 3fe8b4ce467995875873fb3...
The extension for building GraphQL APIs with Ash. Contribute to ash-project/ash_graphql development by creating an account on GitHub.
roberto
robertoOP•2mo ago
going to try and test out adding multi tenancy to this same resource see if it works - but the resource shoudln't have tenancy its always global yeah confirmed it was the issue 🙂

Did you find this page helpful?