malte

malte

Absinthe subscriptions broken?

I’m trying to use subscriptions in Absinthe, but keep getting this error when I try to start the server:

** (Mix) Could not start application pb: exited in: Pb.Application.start(:normal, [])
    ** (EXIT) an exception was raised:
        ** (FunctionClauseError) no function clause matching in Absinthe.Subscription.child_spec/1
            (absinthe) lib/absinthe/subscription.ex:43: Absinthe.Subscription.child_spec(PbWeb.Endpoint)
            (elixir) lib/supervisor.ex:624: Supervisor.init_child/1
            (elixir) lib/enum.ex:1336: Enum."-map/2-lists^map/1-0-"/2
            (elixir) lib/enum.ex:1336: Enum."-map/2-lists^map/1-0-"/2
            (elixir) lib/supervisor.ex:615: Supervisor.init/2
            (elixir) lib/supervisor.ex:564: Supervisor.start_link/2
            (kernel) application_master.erl:277: :application_master.start_it_old/4

This is in a completely vanilla app, freshly created using:

mix phx.new pb --no-html
cd pb
mix ecto.create

Then following the directions here: https://github.com/absinthe-graphql/absinthe/blob/master/guides/subscriptions.md

I’m following the directions for 1.4.x

And then doing
iex -S mix phx.server

Does anyone know why it breaks for me?

Marked As Solved

idi527

idi527

:wave:

Can you post your lib/application.ex here? Judging by the error alone, there is a problem at https://github.com/absinthe-graphql/absinthe/blob/v1.4/lib/absinthe/subscription.ex#L43 so it’d be helpful to see how you define the children for the supervisor.

According to the guide for version 1.4 it should be like this:

[
  # other children ...
  supervisor(MyAppWeb.Endpoint, []), # this line should already exist
  supervisor(Absinthe.Subscription, [MyAppWeb.Endpoint]), # add this line
  # other children ...
]

On the master branch they’ve added the child_spec approach but note that the guide doesn’t include it. I’d try something like

[
      # Start the Ecto repository
      MyAppWeb.Repo,
      # Start the endpoint when the application starts
      MyAppWeb.Endpoint,
      {Absinthe.Subscription, [MyAppWeb.Endpoint]} # <-- note this is different from the guide
    ]

since in v1.4 child_spec expects a list, not a single module atom.

Also Liked

malte

malte

Actually, the supervisor(...) calls are for 1.3 from what I understand, because in 1.4 the direct call to supervisor() has been supplanted by doing Supervisor.start_link(...).

So on the page I linked above (from absinthe-graphql’s github repo), it says to add it like so:
{Absinthe.Subscription, PbWeb.Endpoint} to the children list. Doing this results in the problem I reported above.

However, doing what you suggest fixes the issue! So in case this may help others, here is what the relevant part of my application.ex looks like:

    # List all child processes to be supervised
    children = [
      # Start the Ecto repository
      Pb.Repo,
      # Start the endpoint when the application starts
      PbWeb.Endpoint,
      # Starts a worker by calling: Pb.Worker.start_link(arg)
      # {Pb.Worker, arg},
      {Absinthe.Subscription, [PbWeb.Endpoint]}
    ]

    # See https://hexdocs.pm/elixir/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: Pb.Supervisor]
    Supervisor.start_link(children, opts)
  end

Thank you very much, idiot!

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New

We're in Beta

About us Mission Statement