graphql-validate-fixtures
v3.3.1
Published
Validates JSON fixtures for GraphQL responses against the associated operations and schema
Downloads
17,646
Readme
graphql-validate-fixtures
Validates JSON fixtures for GraphQL responses against the associated operations and schema.
Installation
yarn add graphql-validate-fixtures
Usage
In order to associate a fixture with a GraphQL query or mutation in your app, you must follow one of these conventions:
- Your fixtures are in a directory with a name matching that of the associated GraphQL operation
- Your fixtures have a key called
@operation
at the top level, which has a string value that is the name of the associated operation
Once this is done, you can validate your fixtures using the CLI or Node.js API.
Operation
On startup this tool performs the following actions:
- Loads all schemas
- Discovers all operations belonging to each schema
- Discovers all fixtures and infers operation names as described above
- Validates fixtures against the operation with a matching name
- Reports operation not found error if no schema matches
- Reports ambiguous operation name error if more than one schema matches
Configuration
This tool reads schema information from a graphql-config
config file in the project root.
CLI
# Must provide a list of fixtures as the first argument
yarn run graphql-validate-fixtures 'src/**/fixtures/**/*.graphql.json'
Node
const {evaluateFixtures} = require('graphql-validate-fixtures');
evaluateFixtures({
fixturePaths: ['test/fixtures/one.json', 'test/fixtures/two.json'],
}).then((results) => {
// See the TypeScript definition file for more details on the
// structure of the `results`
results.forEach((result) => console.log(result));
});