Wormwood is a tiny library to aid in testing GraphQL queries against an Absinthe schema. It allows you to test your query documents inside ExUnit test modules, and requires no HTTP requests to occur during testing.
We believe that testing GraphQL queries should be easy. Wormwood lets you scope a test module to one single document (paired with a schema) with ease, and helps to remove any of the boilerplate code such a task would introduce.
With Wormwood, you simply load your document at the top of your module, and query it using a standard function.
That's it!
Install from Hex.pm:
def deps do
[{:wormwood, "~> 0.1.0"}]
end
-
Install Wormwood!
-
use
the Wormwood GQLCase inside the test module...defmodule MyCoolApplication.MyTestCase do use ExUnit.Case use Wormwood.GQLCase #...
-
Use the Wormwood
load_gql/2
macro to specify your schema and load your GraphQL document...defmodule MyCoolApplication.MyTestCase do #... load_gql MyCoolApplication.MyAbsintheSchema, "assets/js/queries/MyQuery.gql" #...
-
Your document and schema are ready to go, you can now call
query_gql/1
inside any of your test statements to execute the loaded document against the specified schema. You can passoptions
to this call, please refer to the Absinthe docs for more information on options.For Example:
#... test "should be a valid query" do result = query_gql(variables: %{}, context: %{:current_user => some_user}) assert {:ok, _query_data} = result end #...
defmodule MyCoolApplication.MyTestCase do
use ExUnit.Case
use Wormwood.GQLCase
load_gql MyCoolApplication.MyAbsintheSchema, "assets/js/queries/MyQuery.gql"
test "should be a valid query" do
result = query_gql(variables: %{}, context: %{:current_user => some_user})
assert {:ok, _query_data} = result
end
end
Check out lib/examples/
for a very simple, static, and self contained Absinthe schema.
You can also dig around in test/examples/
for simple tests that query against that sample schema using Wormwood.
Copyright © 2019 Tinfoil Security Inc.
This project is MIT licensed.
Made with ❤️ and 🔐 by Tinfoil Security