<commit_before># GraphSpec

GraphQL assertion and testing made easy

[![Circle CI](https://circleci.com/gh/rricard/graph-spec/tree/master.svg?style=svg)](https://circleci.com/gh/rricard/graph-spec/tree/master) [![Code Climate](https://codeclimate.com/repos/572b9718ee6f41008b000c4c/badges/785614f6bde8c4d9dc30/gpa.svg)](https://codeclimate.com/repos/572b9718ee6f41008b000c4c/feed) [![Test Coverage](https://codeclimate.com/repos/572b9718ee6f41008b000c4c/badges/785614f6bde8c4d9dc30/coverage.svg)](https://codeclimate.com/repos/572b9718ee6f41008b000c4c/coverage) [![Issue Count](https://codeclimate.com/repos/572b9718ee6f41008b000c4c/badges/785614f6bde8c4d9dc30/issue_count.svg)](https://codeclimate.com/repos/572b9718ee6f41008b000c4c/feed)

---

GraphSpec is a really simple GraphQL assertion library: it is mainly sugar over
something really simple but repetitive to do otherwise.

Using GraphSpec, you can take any GraphQL schema, throw a query and have a deep
validation of the query.

## Installation

```
npm install --save-dev graph-spec
```

## Example

In order to do some classic assertions (using mocha), you can use the default
asserter:

```javascript
import { queryAssert } from "../src"
import mySchema from "./schema"

it("should say hello world", () =>
  queryAssert(mySchema, `
    query Test {
      hello
    }
  `, { hello: "Hello world!" })
)

it("should be able to greet in french", () =>
  queryAssert(mySchema, `
    query Test($greeting: String!) {
      hello(greeting: $greeting)
    }
  `, { hello: "Bon<NAME>!" }, {
    variableValues: {greeting: "Bonjour"},
  })
)
```

Note that you can pass in the options any of the following GraphQL-js options:

- `rootValue`
- `contextValue`
- `variableValues`
- `operationName`

For ease of use, you can create your own asserter, able to carry preset options:

```javascript
import { createQueryAsserter } from "../src"
import mySchema from "./schema"

const queryAssert = createQueryAsserter(mySchema, {
  rootValue: {user: "le monde"},
})

it("should say hello world", () =>
  queryAssert(`
    query Test {<commit_msg>Fix package import in the README example<commit_after># GraphSpec

GraphQL assertion and testing made easy

[![Circle CI](https://circleci.com/gh/rricard/graph-spec/tree/master.svg?style=svg)](https://circleci.com/gh/rricard/graph-spec/tree/master) [![Code Climate](https://codeclimate.com/repos/572b9718ee6f41008b000c4c/badges/785614f6bde8c4d9dc30/gpa.svg)](https://codeclimate.com/repos/572b9718ee6f41008b000c4c/feed) [![Test Coverage](https://codeclimate.com/repos/572b9718ee6f41008b000c4c/badges/785614f6bde8c4d9dc30/coverage.svg)](https://codeclimate.com/repos/572b9718ee6f41008b000c4c/coverage) [![Issue Count](https://codeclimate.com/repos/572b9718ee6f41008b000c4c/badges/785614f6bde8c4d9dc30/issue_count.svg)](https://codeclimate.com/repos/572b9718ee6f41008b000c4c/feed)

---

GraphSpec is a really simple GraphQL assertion library: it is mainly sugar over
something really simple but repetitive to do otherwise.

Using GraphSpec, you can take any GraphQL schema, throw a query and have a deep
validation of the query.

## Installation

```
npm install --save-dev graph-spec
```

## Example

In order to do some classic assertions (using mocha), you can use the default
asserter:

```javascript
import { queryAssert } from "graph-spec"
import mySchema from "./schema"

it("should say hello world", () =>
  queryAssert(mySchema, `
    query Test {
      hello
    }
  `, { hello: "Hello world!" })
)

it("should be able to greet in french", () =>
  queryAssert(mySchema, `
    query Test($greeting: String!) {
      hello(greeting: $greeting)
    }
  `, { hello: "Bonjour world!" }, {
    variableValues: {greeting: "Bonjour"},
  })
)
```

Note that you can pass in the options any of the following GraphQL-js options:

- `rootValue`
- `contextValue`
- `variableValues`
- `operationName`

For ease of use, you can create your own asserter, able to carry preset options:

```javascript
import { createQueryAsserter } from "graph-spec"
import mySchema from "./schema"

const queryAssert = createQueryAsserter(mySchema, {
  rootValue: {user: "le monde"},
})

it("should say hello world", () =>
  queryAssert(`
    query Test {
{'fraction_non_alphanumeric': 0.13077469793887705, 'fraction_numerical': 0.06538734896943853, 'mean_word_length': 4.736413043478261, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 10, 'https://': 16, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3413937', 'n_tokens_mistral': 1643, 'n_tokens_neox': 1452, 'n_words': 349}