Hi all!
What is the correct way to think about Absinthe.Plug.GraphiQL
and its relationship to Absinthe.Plug
?
I’m building an API that is entirely GraphQL, so I’m eschewing the Phoenix router and using the Absinthe plugs directly. I initially thought that the former would be used in addition to the latter to provide the GraphiQL interface, but I’m getting (Plug.Conn.AlreadySentError) the response was already sent
errors when both plugs were added to my endpoint. It looks like Absinthe.Plug.GraphiQL
encapsulates Absinthe.Plug
, and using the former means I don’t need the latter. Is that correct? The docs aren’t particularly clear about this …
I’ve ended up with this setup, which seems to be working, but it would be good to confirm that I’m on the right track:
defmodule App.Endpoint do
use Phoenix.Endpoint, otp_app: :app
# etc
if Mix.env() == :dev do
plug Absinthe.Plug.GraphiQL,
schema: WriterWeb.Schema,
json_codec: Jason,
interface: :playground
else
plug Absinthe.Plug,
schema: WriterWeb.Schema,
json_codec: Jason
end
end
Thanks!