UNPKG

1.5 kBMarkdownView Raw
1# `graphql-validate-fixtures`
2
3> Validates JSON fixtures for GraphQL responses against the associated operations and schema
4
5## Installation
6
7```
8npm install graphql-validate-fixtures --save-dev
9```
10
11or, with Yarn:
12
13```
14yarn add graphql-validate-fixtures --dev
15```
16
17## Usage
18
19In order to associate a fixture with a GraphQL query or mutation in your app, you must follow one of these conventions:
20
21* Your fixtures are in a directory with a name matching that of the associated GraphQL operation
22* Your fixtures have a key called `@operation` at the top level, which has a string value that is the name of the associated operation
23
24Once this is done, you can validate your fixtures using the CLI or Node.js API.
25
26### CLI
27
28```sh
29# Must provide a list of fixtures as the first argument, as well
30# as flags for the path to the schema (`--schema-path`) and operations
31# (`--operation-paths`, can be a glob pattern)
32yarn run graphql-validate-fixtures 'src/**/fixtures/**/*.graphql.json' --schema-path 'build/schema.json' --operation-paths 'src/**/*.graphql'
33```
34
35### Node
36
37```js
38const {evaluateFixtures} = require('graphql-validate-fixtures');
39evaluateFixtures({
40 fixturePaths: ['test/fixtures/one.json', 'test/fixtures/two.json'],
41 schemaPath: 'build/schema.json',
42 operationPaths: ['src/Home/Home.graphql'],
43})
44 .then((results) => {
45 // See the TypeScript definition file for more details on the
46 // structure of the `results`
47 results.forEach((result) => console.log(result));
48 });
49```