Absinthe no schema for the api route

Hi everyone,

I got this strange error after I visit locallhost:4000/api

{"errors":[{"message":"No query document supplied"}]}

Full trace

[info] GET /api
[debug] Processing with Absinthe.Plug
  Parameters: %{}
  Pipelines: [:api]
[info] Sent 400 in 27ms

Also, I have the route setup with the schema like so and the graphiql route works

defmodule WolfBlogWeb.Router do
  use WolfBlogWeb, :router

  pipeline :api do
    plug :accepts, ["json"]
  end

  scope "/" do
    pipe_through :api

    forward "/api", Absinthe.Plug, schema: WolfBlogWeb.Schema

    forward("/graphiql", Absinthe.Plug.GraphiQL,
      schema: WolfBlogWeb.Schema,
      interface: :playground
    )
  end
end

Also here is my test

defmodule WolfBlogWeb.Schema.Posts.Queries.PostsQueryTest do
  use WolfBlog.DataCase, async: true
  use WolfBlogWeb.ConnCase, async: true

  setup "Start the seeder for testing data" do
    WolfBlog.Seeder.power_up()
  end

  @query """
    {
      posts {
        title
      }
    }
  """
  describe "Testing the Posts Query" do
    test "Should get all posts(1 of 1)" do

      data = get(build_conn(), "/api", query: @query)
      IO.inspect(data)
      assert json_response(data, 200) == %{
        "data" => %{
          "posts" => [
              %{"title" => "Absinthe is great"}
            ]
          }
        }
    end
  end
end

I don’t understand how i can get the graphqil route OK and have queries but not get anything from api route.?!

could dialyzer be a problem also on the route file warning?!

Function '__checks__'/0 has no local return

Error when ran test

1) test Testing the Posts Query Should get all posts(1 of 1) (WolfBlogWeb.Schema.Posts.Queries.PostsQueryTest)
     test/wolf_blog_web/schema/posts/queries/posts_query_test.exs:17
     ** (MatchError) no match of right hand side value: {:already, :owner}
     stacktrace:
       (wolf_blog) test/support/conn_case.ex:32: WolfBlogWeb.ConnCase.__ex_unit_setup_0/1
       (wolf_blog) test/support/conn_case.ex:1: WolfBlogWeb.ConnCase.__ex_unit__/2
       test/wolf_blog_web/schema/posts/queries/posts_query_test.exs:1: WolfBlogWeb.Schema.Posts.Queries.PostsQueryTest.__ex_unit__/2

For me the above error translates that I don’t recieve a value in the left side(empty) to match the right side.

Update it is related to this:

Thanks

Solved

After a help from a friend and some tinkering I made the test work, here is the final version

defmodule WolfBlogWeb.Schema.Posts.Queries.PostsQueryTest do
  use WolfBlogWeb.ConnCase, async: true


  setup do
    WolfBlog.Seeder.power_up()
  end


  @query """
    {
      posts {
        title
      }
    }
  """

  describe "Testing the Posts Query" do
    test "Should get all posts(1 of 1)" do

      conn = build_conn()

      res = get conn, "/graphql", query: @query


      assert json_response(res, 200)["data"]["posts"] == [%{"title" => "Absinthe is great"}]
    end
  end
end

2 Likes