UNPKG

@graphql-cli/coverage

Version:
91 lines (87 loc) 3.4 kB
'use strict'; const tslib = require('tslib'); const common = require('@graphql-cli/common'); const graphqlCliCommon = require('@graphql-inspector/graphql-cli-common'); const coverageCommand = require('@graphql-inspector/coverage-command'); const index = common.defineCommand((api) => { return { command: 'coverage [project]', describe: 'Schema coverage based on documents', builder(yargs) { return yargs .positional('project', { describe: 'Point to a project', type: 'string', }) .options({ schema: { describe: 'Point to a schema', type: 'string', }, documents: { describe: 'Point to operations and fragments', type: 'string', }, write: { alias: 'w', describe: 'Write a file with coverage stats', type: 'string', }, silent: { alias: 's', describe: 'Do not render any stats in the terminal', type: 'boolean', }, require: { alias: 'r', describe: 'Require modules', type: 'array', }, token: { alias: 't', describe: 'Access Token', type: 'string', }, header: { alias: 'h', describe: 'Http Header', type: 'array', }, config: { alias: 'c', type: 'string', describe: 'Location of GraphQL Config', }, }); }, handler(args) { return tslib.__awaiter(this, void 0, void 0, function* () { const writePath = args.write; const silent = args.silent; const { headers, token } = graphqlCliCommon.parseGlobalArgs(args); const config = yield api.useConfig({ rootDir: args.config || process.cwd(), extensions: [graphqlCliCommon.createInspectorExtension('coverage')], }); if (args.documents && args.schema) { const { loadDocuments, loadSchema } = api.useLoaders({ loaders: graphqlCliCommon.loaders }); const schema = yield loadSchema(args.schema, { headers, token, }); const documents = yield loadDocuments(args.documents, { headers, token, }); return coverageCommand.handler({ schema, documents, silent, writePath }); } const project = config.getProject(args.project); const schema = yield project.getSchema(); const documents = yield project.getDocuments(); return coverageCommand.handler({ schema, documents, silent, writePath }); }); }, }; }); module.exports = index; //# sourceMappingURL=index.cjs.js.map