@graphql-cli/coverage
Version:
Introspects GraphQL Schema
89 lines (86 loc) • 3.31 kB
JavaScript
import { __awaiter } from 'tslib';
import { defineCommand } from '@graphql-cli/common';
import { parseGlobalArgs, createInspectorExtension, loaders } from '@graphql-inspector/graphql-cli-common';
import { handler } from '@graphql-inspector/coverage-command';
const index = 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 __awaiter(this, void 0, void 0, function* () {
const writePath = args.write;
const silent = args.silent;
const { headers, token } = parseGlobalArgs(args);
const config = yield api.useConfig({
rootDir: args.config || process.cwd(),
extensions: [createInspectorExtension('coverage')],
});
if (args.documents && args.schema) {
const { loadDocuments, loadSchema } = api.useLoaders({ loaders });
const schema = yield loadSchema(args.schema, {
headers,
token,
});
const documents = yield loadDocuments(args.documents, {
headers,
token,
});
return handler({ schema, documents, silent, writePath });
}
const project = config.getProject(args.project);
const schema = yield project.getSchema();
const documents = yield project.getDocuments();
return handler({ schema, documents, silent, writePath });
});
},
};
});
export default index;
//# sourceMappingURL=index.esm.js.map