absinthe-graphql/absinthe_phoenix

Graphiql Subscriptions Integration

warex03 opened this issue · 2 comments

Hi there, I was trying to implement GraphQL subscriptions and did most of the stuff found in the README. However, when trying to integrate with GraphiQL, it seems to automatically connect to /graphiql/websockets. Here's what it looks like on graphiql

screen shot 2017-11-27 at 12 59 21 pm

And here's what I have changed in my project so far:

app/web/channels/graph_socket.ex

defmodule App.Web.GraphSocket do  
  use Phoenix.Socket
  use Absinthe.Phoenix.Socket, schema: App.Web.Schema

  transport :websocket, Phoenix.Transports.WebSocket

  def connect(params, socket) do
    {:ok, socket}
  end

  def id(_socket), do: nil
end

endpoint.ex

use Absinthe.Phoenix.Endpoint
socket "/graphiql/websocket", App.Web.GraphSocket

router.ex

scope "/graphiql" do
  pipe_through :graphql

  forward "/", Absinthe.Plug.GraphiQL,
    schema: App.Web.Schema,
    socket: App.Web.GraphSocket
end

application.ex

supervisor(Absinthe.Subscription, [App.Web.Endpoint])

What could be the issue here?

I seem to got it working now by setting the socket endpoint properly to just /graphiql:

endpoint.ex

use Absinthe.Phoenix.Endpoint
socket "/graphiql", App.Web.GraphSocket

Closing this issue now. Thanks!

This post saved me from trying to figure out how to create a slim graphql socket. Had the hardest time finding tutorials. Thank you very much for this post/solution @warex03