Tinfoil_Security
Wormwood - A Small Library to Help Test Absinthe GQL APIs
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/1function. - Supports
#importstatements 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
Most Liked
joshtaylor
This is awesome!
One of the “problems” with testing GQL is the amount of boilerplate you have to write, mainly around syncing of queries in tests. I ended up doing similar where I included the gql file in a file and loaded it.
uhrobots
Thanks for the reply @joshtaylor!
I’ve also written up a blog post on the Tinfoil website with some more detailed examples and a breakdown of more advanced usage! ![]()
Post: Wormwood - an Explicit Way to Test Absinthe GraphQL APIs | Black Duck Blog
AstonJ
Love the name as well, wormwood = Artemisia absinthium. A powerful herb used for its anti parasitic and anti-inflammatory properties ![]()
Popular in Announcing
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
- #code-sync
- #javascript
- #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









