Wormwood Save

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.

Project README

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

Open Source Agenda is not affiliated with "Wormwood" Project. README Source: wormwood-elixir/wormwood
Stars
92
Open Issues
7
Last Commit
3 years ago
License
MIT

Open Source Agenda Badge

Open Source Agenda Rating