UNPKG

2.51 kBMarkdownView Raw
1# `graphql-validate-fixtures`
2
3[![Build Status](https://github.com/Shopify/quilt/workflows/Node-CI/badge.svg?branch=main)](https://github.com/Shopify/quilt/actions?query=workflow%3ANode-CI)
4[![Build Status](https://github.com/Shopify/quilt/workflows/Ruby-CI/badge.svg?branch=main)](https://github.com/Shopify/quilt/actions?query=workflow%3ARuby-CI)
5[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE.md) [![npm version](https://badge.fury.io/js/graphql-validate-fixtures .svg)](https://badge.fury.io/js/graphql-validate-fixtures .svg) {{#if usedInBrowser}} [![npm bundle size (minified + gzip)](https://img.shields.io/bundlephobia/minzip/graphql-validate-fixtures .svg)](https://img.shields.io/bundlephobia/minzip/graphql-validate-fixtures .svg) {{/if}}
6
7Validates JSON fixtures for GraphQL responses against the associated operations and schema.
8
9## Installation
10
11```bash
12$ yarn add graphql-validate-fixtures
13```
14
15## Usage
16
17In order to associate a fixture with a GraphQL query or mutation in your app, you must follow one of these conventions:
18
19- Your fixtures are in a directory with a name matching that of the associated GraphQL operation
20- Your fixtures have a key called `@operation` at the top level, which has a string value that is the name of the associated operation
21
22Once this is done, you can validate your fixtures using the CLI or Node.js API.
23
24### Operation
25
26On startup this tool performs the following actions:
27
28- Loads all schemas
29- Discovers all operations belonging to each schema
30- Discovers all fixtures and infers operation names as described [above](#Usage)
31- Validates fixtures against the operation with a matching name
32 - Reports operation not found error if no schema matches
33 - Reports ambiguous operation name error if more than one schema matches
34
35### Configuration
36
37This tool reads schema information from a [`.graphqlconfig`](https://github.com/Shopify/graphql-tools-web/tree/main/packages/graphql-tool-utilities#configuration) file in the project root.
38
39### CLI
40
41```sh
42# Must provide a list of fixtures as the first argument
43yarn run graphql-validate-fixtures 'src/**/fixtures/**/*.graphql.json'
44```
45
46### Node
47
48```js
49const {evaluateFixtures} = require('graphql-validate-fixtures');
50evaluateFixtures({
51 fixturePaths: ['test/fixtures/one.json', 'test/fixtures/two.json'],
52}).then(results => {
53 // See the TypeScript definition file for more details on the
54 // structure of the `results`
55 results.forEach(result => console.log(result));
56});
57```