Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tinfoil/wormwood
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.
https://github.com/tinfoil/wormwood
absinthe elixir exunit graphql
Last synced: 3 months ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/tinfoil/wormwood
- Owner: wormwood-elixir
- License: mit
- Created: 2019-10-02T20:43:14.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-09-21T19:05:06.000Z (about 4 years ago)
- Last Synced: 2024-05-19T16:03:39.939Z (6 months ago)
- Topics: absinthe, elixir, exunit, graphql
- Language: Elixir
- Homepage: https://hex.pm/packages/wormwood
- Size: 90.8 KB
- Stars: 92
- Watchers: 10
- Forks: 11
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Wormwood
[![hex](https://img.shields.io/hexpm/v/wormwood.svg)](https://hex.pm/packages/wormwood)
![Actions Status](https://github.com/tinfoil/wormwood/workflows/Elixir%20CI/badge.svg)
[![license-mit](https://img.shields.io/badge/license-MIT-blue)](https://github.com/tinfoil/wormwood/blob/master/LICENSE)
![graph-ql](https://img.shields.io/badge/%E2%99%A5-graphql-ff69b4)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](https://hex.pm/packages/wormwood):
```elixir
def deps do
[{:wormwood, "~> 0.1.0"}]
end
```----------
### Getting Started
1. Install Wormwood!
2. `use` the Wormwood GQLCase inside the test module...```elixir
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...```elixir
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](https://hexdocs.pm/absinthe/Absinthe.html#run/3-options) for more information on options.
For Example:
```elixir
#...
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:
```elixir
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.](https://www.tinfoilsecurity.com/go/opensource)
This project is [MIT licensed](https://github.com/tinfoil/wormwood/blob/master/LICENSE).
----------
Made with ❤️ and 🔐 by Tinfoil Security