crisdegraciadev
Help on testing with Absinthe
Hey guys,
I’m relatively new to Elixir world. Currently I’m working on a GraphQL API with Absinthe. All is going right, I have done some logic, some tests to the business logic layer, etc.
Now I’m trying to test my web layer (resolvers), but every time I’m stuck getting this response every time I try to make a request from ExUnit.
%{
"errors" => [
%{
"locations" => [%{"column" => 1, "line" => 1}],
"message" => "Parsing failed at `--plug_con`"
}
]
}
The app works just fine from Postman, here it’s my test file
defmodule Test.Web.Resolver.Session do
alias Mix.Tasks.Phx.Routes
use Test.Setup.ConnCase, async: true
@login_mutation """
query GetUser($id: ID!){
user(id: $id) {
id,
email,
firstName,
posts {
id,
title
}
}
}
"""
setup %{conn: conn} do
:ok
end
test "prueba", %{conn: conn} do
conn =
post(conn, "/api/graphql", %{
"mutation" => @login_mutation,
"variables" => %{id: 1}
})
IO.inspect(conn)
IO.inspect(json_response(conn, 200))
end
end
Any idea why is this happening?
Marked As Solved
benwilson512
Hi @crisdegraciadev welcome! That is a very strange error, I’ve never seen it before.
There are definitely a few things that are strange about your test though.
- You have something called
@login_mutationthat is a graphql query, not a mutation. It also doesn’t look like it does a login - you are using the
"mutation"key for the document, but the document key in the POST body should always be"query"whether it’s a mutation doc or otherwise
Are you able to put your code up somewhere that I can see this happen?
Also Liked
dimitarvp
It helps future readers if you show how you solved it.
paulstatezny
I just ran into this as well.
Just to clarify, the problem here was @benwilson512 's (2):
you are using the
"mutation"key for the document, but the document key in the POST body should always be"query"whether it’s a mutation doc or otherwise
So this:
post(conn, "/api/graphql", %{
"mutation" => @login_mutation,
"variables" => %{id: 1}
})
Should have been this:
post(conn, "/api/graphql", %{
"query" => @login_mutation,
"variables" => %{id: 1}
})
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








