Absinthe: log errors to console

I’d like to see Absinthe’s errors on the console, right now all I get is [info] Sent 400 in 2ms (notice the 400), but no error message informing what’s wrong with the request data.

Is that possible?

400 generally only happens if the GraphQL document itself was invalid and couldn’t be executed at all. I don’t think there’s any existing logging in place when that happens since it’s really (usually) an error on the client side. It can also happen however if plug parsers isn’t setup properly and the request isn’t getting parsed.

Long story short: PR welcome on adding in some debug logging there. In the meantime check the client side.

1 Like

@benwilson512 is there currently a hook that gets executed before sending the response?

Absinthe doesn’t need its own because Plug already has this: https://hexdocs.pm/plug/Plug.Conn.html#register_before_send/2

# add this in your endpoint.ex somewhere prior to your router or Absinthe.Plug invocation
plug :debug_response

plug MyAppWeb.Router

defp debug_response(conn, _) do
  Plug.Conn.register_before_send(conn, fn conn ->
    conn.resp_body |> IO.puts
    conn
  end)
end

EDIT:

If this is in production you’ll want to tweak this to not print every request, that’d be bad.

3 Likes

That’s useful, thanks!