The package takes a set of .gql
files, runs them against each endpoint defined
in .graphqlconfig
and creates snapshots containing the responses. Jest used as
a test runner.
Add the package to a project:
pnpm add -D @amazeelabs/graphql-schema-test jest
Create a Jest test file:
const {
listFiles,
createExecutor,
} = require('@amazeelabs/graphql-schema-test');
execute = createExecutor('path/to/.graphqlconfig/file', myOptionalSerializer);
test.each(listFiles('path/to/queries/dir'))('%s', async (_, path) => {
await execute(path);
});
function myOptionalSerializer(responses) {
// serialize data in responses
}
Run tests:
pnpm jest --testMatch '<rootDir>/path/to/my/test/file.js'
For an example, see apps/silverback-drupal/generated/__tests__.
If you are a PhpStorm user and have the GraphQL plugin installed, you are very lucky :) Because you can easily test your queries against any endpoint:
For a Drupal based example, see test:integration
script in
apps/silverback-drupal/package.json.