Best way to publish server-side Phoenix-Absinthe GraphQL subscriptions?

I have Phoenix channels working such that regular server status information is published at a regular interval.

I’m trying to reimplement this to push these updates through GraphQL subscriptions. Is there a good or correct way to emit these changes? As in, do I need to create a mutation doc to cause a trigger – or is there a function I can call directly?

Any advice or links would be appreciated,
Thanks,
Scott S.

There is a function you can call which triggers a subscription without having a mutation. It is ‘Absinthe.Subscription.publish’.

Read about it here:

At the Very bottom of the page.

I found this documentation to be unclear so in the example call:

Absinthe.Subscription.publish(MyAppWeb.Endpoint, comment, comment_added: “absinthe-graphql/absinthe”)

The “comment” is the new value for the thing that has changed. This would be the same thing you would return from a resolver.

“comment_added” is the field of a root subscription corresponding to the value above.

The string “absinthe-graphq/absinthe” is the topic you registered in the “config” function of the field in the subscription.

3 Likes