Use Absinthe.Subscription.publish/3
to manually publish a mutation after a Commanded Ecto projection has updated a read model in the after_update/3
callback function.
Created
February 18, 2020 15:23
-
-
Save slashdotdash/48214e75560ff5837f836e6a6b845934 to your computer and use it in GitHub Desktop.
Publish to an Absinthe GraphQL subscription
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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