Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mfix22/gest

πŸ‘¨β€πŸ’» A sensible GraphQL testing tool - test your GraphQL schema locally and in the cloud
https://github.com/mfix22/gest

cli command-line deployment-testing gest graphiql graphql graphql-client integration-testing jest regression-testing test testing testing-tools

Last synced: about 2 months ago
JSON representation

πŸ‘¨β€πŸ’» A sensible GraphQL testing tool - test your GraphQL schema locally and in the cloud

Awesome Lists containing this project

README

        


Gest - A sensible GraphQL testing CLI and tool.


A sensible GraphQL testing tool.




PRs welcome


tested with jest


tested with gest


MIT License

## Usage

```bash
$ npm install -g gest
```

then send queries with `gest` (pronounced _guest_ [/Ι‘est/]).

```bash
$ gest [options] [query | pathToFileWithQuery]
```

##### Examples

```bash
$ gest '{ test }'
```

or

```bash
$ gest test.graphql

# with `test.graphql` containing
{
test
}
```

or multiple

```bash
$ gest test.graphql '{ test }' introspection.graphql
# will run all three queries!
```

### REPL

If you run `gest` with no arguments, it will open a REPL for you to run queries in:

```bash
$ gest

Query: { test }

{
data: {
test: "success!"
}
}
```

### HTTP

If you specify a `baseURL` in your [`config`](#config), `gest` will send an `POST` request with your query correctly encoded in the body. Your `baseURL` must be a valid URL.

You can specify HTTP headers by using `-H key=value` [flags](#flags).

This is especially convenient if you are using a [`Now`](https://zeit.co/now) workflow.

##### Example

```bash
$ gest -H Authorization=e130294e --baseURL https://test-server-2ae34342.now.sh '{ test }'
```

### Local module

You can use `gest` as a local module in your unit/integration tests

##### Examples

```javascript
const Gest = require('gest')
const schema = require('../src/schema')

const gest = Gest(schema, {
baseURL: 'test-server.now.sh',
headers: {
Authorization: 'Bearer token',
Accept: 'application/json'
}
})

describe('GraphQL', () => {
test('{ test }', () => {
return gest('{ test }').then(({ data, errors }) => {
expect(errors).toBeUndefined()
expect(data).toEqual('success!')
})
})
})
```

or use Global `gest` with [`jest`](https://facebook.github.io/jest/).

```javascript
// will create global `gest()` function
Gest(schema)

// pass a test name and a query
gest(
'test query',
`
{
test
}
`
)
```

**Note**: Global functionality will be turned on by default if `NODE_ENV === test` and if `global.test` or `global.it` exists

## Flags

##### `--all (-A)`

Running `gest --all` will run all files matching `*.query`, `*.graphql`, or `*.gql` and
simply print if each query succeeded without errors

##### `--inspect (-I)`

For convenience, running `gest --inspect` or `gest -I` will pretty print your GraphQL schema

##### `--print (-P)`

Pretty print your GraphQL queries (without using GraphiQL!)

```bash
$ gest [query | pathToQuery] --print
```

###### Example

```bash
$ gest '{test}' --print

{
test
}
```

##### `--schema (-S)`

You can specify the path to your GraphQL schema with `gest --schema ./path/to/schema.js`

##### `--baseURL (-B)`

URL to send GraphQL queries to: `gest --baseURL https://test-server.now.sh`

##### `--header (-H)`

HTTP request headers to send with your queries: `gest --header Accept=application/json`.
Headers will be passed into context as `context.headers` for every query for local testing.

## Convention

The `gest` CLI will look to resolve your GraphQL schema in the current working directory for `schema.js`. If you wish to specify a different schema location, do so as `schema` in your [`config`](#config).

## Config

You can configure the `gest` runtime by adding a `gest` key to your `package.json`, or specifying them as flags.

##### Example

```javascript
// package.json
{
"name": "your_package",
...
"gest": {
"schema": "./path/to/schema",
"baseURL": "https://your.url.sh"
}
}
```

## Why `gest`?

##### Pros

- :+1: No restarting your dev server when you make changes
- :+1: Testing your schema doesn't require a separate window (e.g. Graphiql)
- :+1: Run queries [from files](#usage) (save the queries you use most often)
- :+1: Simple unit testing for your schema
- :+1: Easy regression testing with [`gest --all`](#flags).
- :+1: Simple integration/deployment testing with [`--baseURL`](#http)
- :+1: Handy introspection and pretty printing
- :+1: _Helpful_ error messages!

##### Drawbacks

- :-1: No query autocompletion ([yet](https://github.com/mfix22/gest/issues/1))

## Contributing

1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it locally
2. Install the dependencies: `npm install`
3. Run `npm link` to link the scripts found in `bin` for testing terminal commands
4. Before submitting a pull request, run `npm test`

## Need help?

Running `gest help` will show you all the `gest` options. If you have any other concerns, [post an issue!](https://github.com/mfix22/gest/issues)

## Logo

The official `gest` logo is designed by [`@jakedex`](https://github.com/jakedex)

## License

MIT