small medium large xlarge

08 Sep 2017, 14:21
Bruce Williams (18 posts)

This forum is for discussions about the book “Craft GraphQL APIs in Elixir with Absinthe.”

We look forward to hearing from you!

21 Sep 2017, 13:31
turbofail (1 post)


in chapter 6, in “Setting up Subscriptions”, in snippet 06-chp.subscriptions/1-start/lib/plate_slate_web/channels/user_socket.ex, just indicated to add use Absinthe.Phoenix.Socket, schema: PlateSlateWeb.Schema.

But this cause an exception in absinthe_phoenix (Absinthe.Phoenix.Channel) because no absinthe config:

[error] an exception was raised:
    ** (BadMapError) expected a map, got: nil
        (elixir) lib/map.ex:424: Map.get(nil, :opts, [])
        (absinthe_phoenix) lib/absinthe/phoenix/channel.ex:24: Absinthe.Phoenix.Channel.join/3
        (phoenix) lib/phoenix/channel/server.ex:188: Phoenix.Channel.Server.init/1
        (stdlib) gen_server.erl:365: :gen_server.init_it/2
        (stdlib) gen_server.erl:333: :gen_server.init_it/6
        (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3


To add absinthe config, put {:ok, assign(socket, :absinthe, %{schema: PlateSlateWeb.Schema})} in connect function to solve the problem.

I put it here for anyone with the same problem

26 Sep 2017, 15:14
Dan Todor (5 posts)

I got to the same chapter, everything compiles just fine, but when I test it in GraphiQL, instead of the advised subscription success, I get “Subscriptions cannot be run over HTTP.” … By looking in the Absinthe source code, I see a test specifically for that. Is that a limitation of GraphQL, or speciffic to Absinthe ? In either way, I think it would negate the usual setup that I’m using, nginx proxying for Phoenix app … Is that the right thing to do ? Anyway, thanks for the great book, it’s been a pleasure so far :)

26 Sep 2017, 18:53
Ben Wilson (8 posts)

Hey folks! Sorry you ran into some issues, there were a few last minute changes to the dependencies that threw things off a bit. If you do mix deps.update absinthe absinthe_phoenix it should pull to the latest 1.4.0-rc.1 version for both (confirm in your mix.lock file). With that version the code described in the book should work without issue.

Let us know if that isn’t the case.

30 Sep 2017, 04:23
Dan Todor (5 posts)

Updated to 1.4.0 rc2, exactly same result. “Subscriptions cannot be run over HTTP.”

02 Oct 2017, 12:34
Dan Todor (5 posts)


test "subscriptions over HTTP return an error" do

So I guess it really shouldn’t work … How to make it work tough ?

02 Oct 2017, 13:19
Ben Wilson (8 posts)

Hey Dan sorry, the update comments were specifically about the Map.get(nil, :opts, []) errors.

Subscriptions for GraphiQL are supposed to happen over websockets, not via regular HTTP requests. If you’re getting that error it indicates that your GraphiQL UI isn’t connecting to phoenix channels properly.

Can you show me where you forward to Graphiql in your project?

03 Oct 2017, 18:23
Dan Todor (5 posts)

This is the part, I think :)

scope “/” do pipe_through :api

forward "/api", Absinthe.Plug,
  schema: BmappWeb.Schema

forward "/graphiql", Absinthe.Plug.GraphiQL,
  schema: BmappWeb.Schema,
  socket: BmappWeb.UserSocket



06 Nov 2017, 17:41
Ben Wilson (8 posts)

Hey Dan sorry for the delayed reply. At the moment on the simple interface support subscriptions, although that will be improved prior to the final release of the book. You’ll want to add interface: :simple to your GraphiQL plug.

You must be logged in to comment