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
      # ...

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



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.


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! :slight_smile:

Post: https://www.tinfoilsecurity.com/blog/wormwood-graphql-testing


Very timely for me. Thanks for sharing!


Love the name as well, wormwood = Artemisia absinthium. A powerful herb used for its anti parasitic and anti-inflammatory properties :003: