diff --git a/lib/absinthe/plug.ex b/lib/absinthe/plug.ex index d8fdf38..062578a 100644 --- a/lib/absinthe/plug.ex +++ b/lib/absinthe/plug.ex @@ -372,7 +372,7 @@ defmodule Absinthe.Plug do def subscribe_loop(conn, topic, config) do receive do %{event: "subscription:data", payload: %{result: result}} -> - case chunk(conn, "#{encode_json!(result, config)}\n\n") do + case chunk(conn, "event: next\ndata: #{encode_json!(result, config)}\n\n") do {:ok, conn} -> subscribe_loop(conn, topic, config) diff --git a/test/lib/absinthe/plug_test.exs b/test/lib/absinthe/plug_test.exs index 975ebc6..6dc6358 100644 --- a/test/lib/absinthe/plug_test.exs +++ b/test/lib/absinthe/plug_test.exs @@ -472,14 +472,13 @@ defmodule Absinthe.PlugTest do conn = Task.await(request) {_module, state} = conn.adapter - events = - state.chunks - |> String.split() - |> Enum.map(&Jason.decode!/1) - - assert length(events) == 2 - assert Enum.member?(events, %{"data" => %{"update" => "FOO"}}) - assert Enum.member?(events, %{"data" => %{"update" => "BAR"}}) + [event1, event2] = String.split(state.chunks, "\n\n", trim: true) + + assert "event: next\ndata: " <> event1_data = event1 + assert "event: next\ndata: " <> event2_data = event2 + + assert Jason.decode!(event1_data) == %{"data" => %{"update" => "FOO"}} + assert Jason.decode!(event2_data) == %{"data" => %{"update" => "BAR"}} end @query """