Subscriptions do not work when declared in the domain.

Subscriptions work when declared in the Resource like this:
defmodule JoseValimIsMyHero.Accounts.User do
use Ash.Resource,
domain: JoseValimIsMyHero.Accounts,
data_layer: AshPostgres.DataLayer,
extensions: [AshGraphql.Resource, AshJsonApi.Resource, AshAdmin.Resource]

...

graphql do
type :user

subscriptions do
pubsub JoseValimIsMyHeroWeb.Endpoint

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

...

end
defmodule JoseValimIsMyHero.Accounts.User do
use Ash.Resource,
domain: JoseValimIsMyHero.Accounts,
data_layer: AshPostgres.DataLayer,
extensions: [AshGraphql.Resource, AshJsonApi.Resource, AshAdmin.Resource]

...

graphql do
type :user

subscriptions do
pubsub JoseValimIsMyHeroWeb.Endpoint

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

...

end
However, they do not work when declared in the Domain like this:
defmodule JoseValimIsMyHero.Accounts do
use Ash.Domain, extensions: [AshGraphql.Domain, AshJsonApi.Domain, AshAdmin.Domain]

...

graphql do
queries do
...
end

mutations do
...
end

subscriptions do
subscribe JoseValimIsMyHero.Accounts.User, :user_changed do
action_types [:create, :update, :destroy]
end
end
end

...

resources do
resource JoseValimIsMyHero.Accounts.User
end
end
defmodule JoseValimIsMyHero.Accounts do
use Ash.Domain, extensions: [AshGraphql.Domain, AshJsonApi.Domain, AshAdmin.Domain]

...

graphql do
queries do
...
end

mutations do
...
end

subscriptions do
subscribe JoseValimIsMyHero.Accounts.User, :user_changed do
action_types [:create, :update, :destroy]
end
end
end

...

resources do
resource JoseValimIsMyHero.Accounts.User
end
end
4 Replies
ZachDaniel
ZachDaniel•3mo ago
🤔 likely something relatively simple missing from the underlying DSL info gathering up subscriptions. @barnabasj do you have a few to take a look sometime this week?
barnabasj
barnabasj•3mo ago
sure thing
JVMartyns
JVMartynsOP•3mo ago
Note: - When declared in Resource, it requires the pubsub JoseValimIsMyHeroWeb.Endpoint option to be declared. - The pubsub JoseValimIsMyHeroWeb.Endpoint option gives an error when used in the Domain.
barnabasj
barnabasj•3mo ago
This just wasn't implemented, I added it now https://github.com/ash-project/ash_graphql/pull/341
GitHub
Add domain-level pubsub configuration for subscriptions by barnabas...
This allows users to set pubsub at the domain level instead of requiring it at every resource level. Resources can still override domain-level pubsub with their own configuration.

Did you find this page helpful?