You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to set up a 1.3 project with absinthe. However, as soon as I add the plug, my default Page controller test stops passing.
1) test GET / (MyApp.Web.PageControllerTest)
test/my_app/web/controllers/page_controller_test.exs:4
** (Plug.Conn.AlreadySentError) the response was already sent
stacktrace:
(plug) lib/plug/conn.ex:950: Plug.Conn.register_before_send/2
(my_app) lib/my_app/web/router.ex:4: MyApp.Web.Router.browser/2
(my_app) lib/my_app/web/router.ex:1: anonymous fn/1 in MyApp.Web.Router.__match_route__/4
(phoenix) lib/phoenix/router.ex:273: Phoenix.Router.__call__/1
(my_app) lib/my_app/web/endpoint.ex:1: MyApp.Web.Endpoint.plug_builder_call/2
(my_app) lib/my_app/web/endpoint.ex:1: MyApp.Web.Endpoint.call/2
(phoenix) lib/phoenix/test/conn_test.ex:224: Phoenix.ConnTest.dispatch/5
test/my_app/web/controllers/page_controller_test.exs:5: (test)
It seems like as soon I add the plug to the endpoint, the "/" url starts returning early.
Possibly I've missed a step, but I'm not sure where to start looking. Any help would be appreciated
Steps to Reproduce!
1.) phx.new my_app
2.) add schema file in lib/my_app/web/schema.ex
defmodule MyApp.Web.Schema do
use Absinthe.Schema
@fake_db %{
"foo" => %{id: "foo", name: "Foo", value: 4},
"bar" => %{id: "bar", name: "Bar", value: 5}
}
@desc "A valuable Item"
object :item do
field :id, :id
@desc "The item's name"
field :name, :string
field :value, :integer, description: "Recently appraised value"
end
query do
@desc "Get an item by ID"
field :item, :item do
@desc "The ID of the item"
arg :id, type: :id
resolve fn %{id: id}, _ ->
{:ok, Map.get(@fake_db, id)}
end
end
end
end
As per absinthe-graphql.org/guides/plug-phoenix/ , update endpoint.ex as follows
Update the router to forward to the absinthe plug, router file now looks like
defmodule MyApp.Web.Router do
use MyApp.Web, :router
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
end
pipeline :api do
plug :accepts, ["json"]
end
scope "/", MyApp.Web do
pipe_through :browser # Use the default browser stack
get "/", PageController, :index
end
forward "/api", Absinthe.Plug, schema: MyApp.Web.Schema
# Other scopes may use custom stacks.
# scope "/api", MyApp.Web do
# pipe_through :api
# end
end
I tried putting the plug line in a few locations but it made no difference.
The text was updated successfully, but these errors were encountered:
If you're using a router you don't want to do plug Absinthe.Plug, but rather like any other plug that sends responses you want to use it within your router. You already have this actually, via forward "/api", Absinthe.Plug, schema: MyApp.Web.Schema.
If you want to use it within a phoenix pipeline you can just:
scope "/api" do
forward "/api", Absinthe.Plug, schema: MyApp.Web.Schema
end
This may very well be user error :)
I'm trying to set up a 1.3 project with absinthe. However, as soon as I add the plug, my default Page controller test stops passing.
It seems like as soon I add the plug to the endpoint, the "/" url starts returning early.
Possibly I've missed a step, but I'm not sure where to start looking. Any help would be appreciated
Steps to Reproduce!
1.)
phx.new my_app
2.) add schema file in lib/my_app/web/schema.ex
this is the point the tests fail
I tried putting the plug line in a few locations but it made no difference.
The text was updated successfully, but these errors were encountered: