I’m using absinthe 1.4.10,absinthe_phoenix 1.4.2, and phoenix 1.3.2.
I want to define a GraphQL subscription that is implemented through a Phoenix channel as described by the readme in the absinthe_phoenix documentation. I believe I have followed all the steps there, but would be happy to learn that I have misconfigured something if I need to change it.
I am trying to use the Absinthe.Plug.GraphiQL
tool as a means of testing my subscription. When I connect to my Phoenix application using the web interface it puts up, the channel receives an unexpected message which causes a crash:
** (exit) exited in: Phoenix.Endpoint.CowboyWebSocket.resume()
** (EXIT) an exception was raised:
** (MatchError) no match of right hand side value: %{"payload" => %{}, "type" => "connection_init"}
(phoenix) lib/phoenix/transports/v2/websocket_serializer.ex:34: Phoenix.Transports.V2.WebSocketSerializer.decode!/2
(yeti_web) lib/yeti_web/channels/user_socket.ex:4: YetiWeb.Serializer.decode!/2
(phoenix) lib/phoenix/transports/websocket.ex:121: Phoenix.Transports.WebSocket.ws_handle/3
(phoenix) lib/phoenix/endpoint/cowboy_websocket.ex:77: Phoenix.Endpoint.CowboyWebSocket.websocket_handle/3
(cowboy) /Users/sthompson/Library/Mobile Documents/com~apple~CloudDocs/Projects/Elixir/yeti/deps/cowboy/src/cowboy_websocket.erl:588: :cowboy_websocket.handler_call/7
(phoenix) lib/phoenix/endpoint/cowboy_websocket.ex:49: Phoenix.Endpoint.CowboyWebSocket.resume/3
(cowboy) /Users/sthompson/Library/Mobile Documents/com~apple~CloudDocs/Projects/Elixir/yeti/deps/cowboy/src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
It appears that GraphiQL (or at least the underlying web socket client) is sending the message {"type":"connection_init","payload":{}}
to the Phoenix socket and when Phoenix’s web socket serializer doesn’t find the fields required to convert a web socket message a message for a Phoenix Channel, it simply barfs.
I’m struggling now to understand at what level this message should be handled. It looks like it’s part of the Apollo GraphQL client libraries that are used by GraphiQL. If it is indeed a client-specific message then it’s not clear that cowboy, Absinthe or Phoenix should be handling it.
If it’s a GraphQL standard web socket message (which haven’t been able to nail down with my web searches) That would imply that it is a concern which should be handled at the Absinthe level.
It could also be a concern for Phoenix. I was expecting to find a point in the Phoenix socket handling for dealing with unexpected messages that come in through a Websocket (I anticipated finding something like GenServer’s handle_info
where unrecognized web socket messages would land). I didn’t have any luck.
And finally, it IS a concern for my application as it is causing me to crash. I presume I could implement my own web socket handler for GraphQL subscriptions, but it would be awfully convenient to rely on Absinthe and Phoenix.
I would be happy to work with any of the Open Source projects in an effort to help resolve the issue. Can anyone suggest which project the problem should be handled in?