$ npm install -g gestthen send queries with gest (pronounced guest [/Ι‘est/]).
$ gest [options] [query | pathToFileWithQuery]$ gest '{ test }'or
$ gest test.graphql
# with `test.graphql` containing
{
test
}or multiple
$ gest test.graphql '{ test }' introspection.graphql
# will run all three queries!If you run gest with no arguments, it will open a REPL for you to run queries in:
$ gest
Query: { test }
{
data: {
test: "success!"
}
}If you specify a baseURL in your 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.
This is especially convenient if you are using a Now workflow.
$ gest -H Authorization=e130294e --baseURL https://test-server-2ae34342.now.sh '{ test }'You can use gest as a local module in your unit/integration tests
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.
// 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
Running gest --all will run all files matching *.query, *.graphql, or *.gql and
simply print if each query succeeded without errors
For convenience, running gest --inspect or gest -I will pretty print your GraphQL schema
Pretty print your GraphQL queries (without using GraphiQL!)
$ gest [query | pathToQuery] --print$ gest '{test}' --print
{
test
}You can specify the path to your GraphQL schema with gest --schema ./path/to/schema.js
URL to send GraphQL queries to: gest --baseURL https://test-server.now.sh
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.
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.
You can configure the gest runtime by adding a gest key to your package.json, or specifying them as flags.
// package.json
{
"name": "your_package",
...
"gest": {
"schema": "./path/to/schema",
"baseURL": "https://your.url.sh"
}
}- π No restarting your dev server when you make changes
- π Testing your schema doesn't require a separate window (e.g. Graphiql)
- π Run queries from files (save the queries you use most often)
- π Simple unit testing for your schema
- π Easy regression testing with
gest --all. - π Simple integration/deployment testing with
--baseURL - π Handy introspection and pretty printing
- π Helpful error messages!
- π No query autocompletion (yet)
- Fork this repository to your own GitHub account and then clone it locally
- Install the dependencies:
npm install - Run
npm linkto link the scripts found inbinfor testing terminal commands - Before submitting a pull request, run
npm test
Running gest help will show you all the gest options. If you have any other concerns, post an issue!
The official gest logo is designed by @jakedex
MIT
