Skip to content
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.
Elixir
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows github actions setup Oct 7, 2019
assets test and resolver cleanup Oct 7, 2019
lib Move test modules from lib/examples to test/support Oct 24, 2019
test Move test modules from lib/examples to test/support Oct 24, 2019
.formatter.exs initial commit Oct 2, 2019
.gitignore
LICENSE add mix info and license Oct 3, 2019
README.md readme version update Oct 8, 2019
mix.exs bump hex version Oct 24, 2019
mix.lock add coveralls Oct 5, 2019

README.md

Wormwood

hex Actions Status license-mit graph-ql

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.

Why Wormwood?

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!


Installation

Install from Hex.pm:

def deps do
  [{:wormwood, "~> 0.1.0"}]
end

Getting Started

  1. Install Wormwood!

  2. use the Wormwood GQLCase inside the test module...

    defmodule MyCoolApplication.MyTestCase do
      use ExUnit.Case
      use Wormwood.GQLCase
      #...
  3. 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"
      
      #...
  4. 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 pass options 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
    
    #...
Full example from the above steps:
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

Examples

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.


License

Copyright © 2019 Tinfoil Security Inc.

This project is MIT licensed.


Made with ❤️ and 🔐 by Tinfoil Security

You can’t perform that action at this time.