hubertlepicki

hubertlepicki

Setting up Absinthe on Phoenix + Bandit project

I am trying to set up Absinthe following the documentation here: Plug and Phoenix Setup — absinthe v1.11.0

on a brand new Phoenix 1.7 project.

I have generated the project with:

mix phx.new api --no-assets --no-ecto --no-dashboard --no-mailer --no-html --no-live --no-gettext --module=API 

and now I try to add Absinthe. I installed dependencies:

  defp deps do
    [
      {:phoenix, "~> 1.7.20"},
      {:telemetry_metrics, "~> 1.0"},
      {:telemetry_poller, "~> 1.0"},
      {:jason, "~> 1.2"},
      {:dns_cluster, "~> 0.1.1"},
      {:bandit, "~> 1.5"},
      {:absinthe_plug, "~> 1.5"}
    ]
  end

And I configured my router:


defmodule APIWeb.Router do
  use APIWeb, :router

  forward "/api/graphql", Absinthe.Plug,
    schema: API.Schema

  forward "/api/graphiql",
    Absinthe.Plug.GraphiQL,
    schema: API.Schema,
    interface: :simple
end

The app compiles but when I make requests to either /api/graphq or /api/graphiql I am getting:

[info] GET /api/graphiql                                                                                                                                                       
[error] ** (Plug.Conn.NotSentError) a response was neither set nor sent from the connection
    (bandit 1.6.7) lib/bandit/pipeline.ex:172: Bandit.Pipeline.commit_response!/1
    (bandit 1.6.7) lib/bandit/pipeline.ex:44: Bandit.Pipeline.run/4                  
    (bandit 1.6.7) lib/bandit/http1/handler.ex:12: Bandit.HTTP1.Handler.handle_data/3                                                                                          
    (bandit 1.6.7) lib/bandit/delegating_handler.ex:18: Bandit.DelegatingHandler.handle_data/3   
    (bandit 1.6.7) lib/bandit/delegating_handler.ex:8: Bandit.DelegatingHandler.handle_continue/2
    (stdlib 6.0.1) gen_server.erl:2163: :gen_server.try_handle_continue/3
    (stdlib 6.0.1) gen_server.erl:2072: :gen_server.loop/7                          
    (stdlib 6.0.1) proc_lib.erl:329: :proc_lib.init_p_do_apply/3

My schema so far is also generated from documentation:

defmodule API.Schema do
  use Absinthe.Schema

  @desc "An item"
  object :item do
    field(:id, :id)
    field(:name, :string)
  end

  # Example data
  @items %{
    "foo" => %{id: "foo", name: "Foo"},
    "bar" => %{id: "bar", name: "Bar"}
  }

  query do
    field :item, :item do
      arg(:id, non_null(:id))

      resolve(fn %{id: item_id}, _ ->
        {:ok, @items[item_id]}
      end)
    end
  end
end

Anyone knows what I’m doing wrong?

Marked As Solved

hubertlepicki

hubertlepicki

OK I generated the app again and did the set up steps and everything is working. I think I may have either generated app that’s too bare bones to work with Absinthe or made some other error along the way. It works now.

Also Liked

hubertlepicki

hubertlepicki

I deleted the previous app and it was never in the repo. I’m sorry :frowning:

stevensonmt

stevensonmt

How did you make the requests?

I’ve noticed sometimes that recompiling in an iex session (started with iex -S mix) is not effective. Have to end that session and start a new one for changes to be applied.

Last Post!

stevensonmt

stevensonmt

How did you make the requests?

I’ve noticed sometimes that recompiling in an iex session (started with iex -S mix) is not effective. Have to end that session and start a new one for changes to be applied.

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
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
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54006 488
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40042 209
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

We're in Beta

About us Mission Statement