Wormwood is a small open source lib to help unit test GraphQL query documents against an Absinthe API. It requires no Plug.Conn
s and removes lots of boilerplate using macros!
You can load in a GQL document file using a simple macro, and quickly execute the query against your Absinthe schema!
Simple example:
defmodule Wormwood.Test.Examples.GetUsersTest do
use ExUnit.Case
use Wormwood.GQLCase
load_gql My.Absinthe.Schema, "assets/GetUsers.gql"
describe "GetUsers.gql" do
test "Should return a list of all the users" do
# running the query! No conn or JSON required.
result = query_gql(variables: %{}, context: %{:current_user => ...})
assert {:ok, query_data} = result
# ...
end
end
end
Quick Feature List:
- Avoid’s boilerplate code when unit testing your Absinthe API.
- Pass context, and variables into your query using the
query_gql/1
function. - Supports
#import
statements in GQL documents for fragments! - Executes GQL document files and plain query strings.
- Allows you to test the same query documents you ship to your users!
- Provides methods to help query using a custom Absinthe pipeline.
Github: https://github.com/tinfoil/wormwood
Hex: https://hex.pm/packages/wormwood
Hexdocs: https://hexdocs.pm/wormwood/readme.html
– Tinfoil Engineering Team