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: absinthe/guides/subscriptions.md at main · absinthe-graphql/absinthe · GitHub

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

:waving_hand:

Can you post your lib/application.ex here? Judging by the error alone, there is a problem at absinthe/lib/absinthe/subscription.ex at v1.4 · absinthe-graphql/absinthe · GitHub 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

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
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 Postgres...
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
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement