Search⌘ K
AI Features

Submit the Subscriptions

Explore how to implement basic GraphQL subscriptions in Elixir with Absinthe to push live order updates to clients. Learn to define subscription fields, configure topics, and trigger real-time data flow using publish functions during mutations. Understand how to test subscriptions with GraphiQL and integrate live updates directly into your API mutations.

Basic subscription

Now that we can create orders, we’re at the perfect spot to introduce the first basic subscription. This subscription will support pushing these orders as they’re created out to subscribed clients. We’ll first need to define a subscription field in our schema, and then we’ll also need a way to trigger this subscription when the :place_order mutation runs:

subscription do
field :new_order, :order do
config fn _args, _info ->
{:ok, topic: "*"}
end
end
end

For the most part, this is an ordinary-looking field. We’ve got another top-level object subscription to house our subscription fields, and then the :new_order, which returns the :order object we’re already familiar with. The fact that it returns a regular :order object is crucial, because this means that all the work we have done to support the ...