Skip to content

Instantly share code, notes, and snippets.

@slashdotdash
Created February 18, 2020 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slashdotdash/48214e75560ff5837f836e6a6b845934 to your computer and use it in GitHub Desktop.
Save slashdotdash/48214e75560ff5837f836e6a6b845934 to your computer and use it in GitHub Desktop.
Publish to an Absinthe GraphQL subscription
defmodule MyApp.ExampleProjector do
use Commanded.Projections.Ecto,
application: MyApp.Application,
repo: MyApp.Projections.Repo,
name: "MyApp.ExampleProjector"
project %AnEvent{name: name}, fn multi ->
Ecto.Multi.insert(multi, :example, %ExampleProjection{name: name})
end
def after_update(_event, _metadata, %{example: example}) do
Absinthe.Subscription.publish(MyAppWeb.Endpoint, example, [example: example.id])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment