@graphql-inspector/coverage-command 4.0.4-alpha-20230403113909-e09091f3 → 4.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{index.js → cjs/index.js} +31 -35
- package/cjs/package.json +1 -0
- package/{index.mjs → esm/index.js} +10 -14
- package/package.json +33 -12
- package/typings/index.d.ts +17 -0
- /package/{index.d.ts → typings/index.d.cts} +0 -0
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const logger = require('@graphql-inspector/logger');
|
|
12
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const graphql_1 = require("graphql");
|
|
8
|
+
const commands_1 = require("@graphql-inspector/commands");
|
|
9
|
+
const core_1 = require("@graphql-inspector/core");
|
|
10
|
+
const logger_1 = require("@graphql-inspector/logger");
|
|
13
11
|
function handler({ schema, documents, silent, writePath, }) {
|
|
14
12
|
const shouldWrite = typeof writePath !== 'undefined';
|
|
15
|
-
const coverage =
|
|
13
|
+
const coverage = (0, core_1.coverage)(schema, documents.map(doc => new graphql_1.Source((0, graphql_1.print)(doc.document), doc.location)));
|
|
16
14
|
if (silent !== true) {
|
|
17
15
|
renderCoverage(coverage);
|
|
18
16
|
}
|
|
@@ -20,22 +18,23 @@ function handler({ schema, documents, silent, writePath, }) {
|
|
|
20
18
|
if (typeof writePath !== 'string') {
|
|
21
19
|
throw new Error(`--write is not valid file path: ${writePath}`);
|
|
22
20
|
}
|
|
23
|
-
const absPath =
|
|
24
|
-
const ext =
|
|
21
|
+
const absPath = (0, commands_1.ensureAbsolute)(writePath);
|
|
22
|
+
const ext = (0, path_1.extname)(absPath).replace('.', '').toLocaleLowerCase();
|
|
25
23
|
let output = undefined;
|
|
26
24
|
if (ext === 'json') {
|
|
27
25
|
output = outputJSON(coverage);
|
|
28
26
|
}
|
|
29
27
|
if (output) {
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
(0, fs_1.writeFileSync)(absPath, output, 'utf8');
|
|
29
|
+
logger_1.Logger.success(`Available at ${absPath}\n`);
|
|
32
30
|
}
|
|
33
31
|
else {
|
|
34
32
|
throw new Error(`Extension ${ext} is not supported`);
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
35
|
}
|
|
38
|
-
|
|
36
|
+
exports.handler = handler;
|
|
37
|
+
exports.default = (0, commands_1.createCommand)(api => {
|
|
39
38
|
const { loaders } = api;
|
|
40
39
|
return {
|
|
41
40
|
command: 'coverage <documents> <schema>',
|
|
@@ -67,10 +66,10 @@ const index = commands.createCommand(api => {
|
|
|
67
66
|
},
|
|
68
67
|
handler(args) {
|
|
69
68
|
var _a;
|
|
70
|
-
return
|
|
69
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
71
70
|
const writePath = args.write;
|
|
72
71
|
const silent = args.silent;
|
|
73
|
-
const { headers, token } =
|
|
72
|
+
const { headers, token } = (0, commands_1.parseGlobalArgs)(args);
|
|
74
73
|
const apolloFederation = args.federation || false;
|
|
75
74
|
const aws = args.aws || false;
|
|
76
75
|
const method = ((_a = args.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'POST';
|
|
@@ -89,43 +88,40 @@ function outputJSON(coverage) {
|
|
|
89
88
|
return JSON.stringify(coverage, null, 2);
|
|
90
89
|
}
|
|
91
90
|
function renderCoverage(coverage) {
|
|
92
|
-
|
|
91
|
+
logger_1.Logger.info('Schema coverage based on documents:\n');
|
|
93
92
|
for (const typeName in coverage.types) {
|
|
94
93
|
if (Object.prototype.hasOwnProperty.call(coverage.types, typeName)) {
|
|
95
94
|
const typeCoverage = coverage.types[typeName];
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
logger_1.Logger.log([
|
|
96
|
+
logger_1.chalk.grey((0, core_1.getTypePrefix)(typeCoverage.type)),
|
|
97
|
+
logger_1.chalk.bold(String(typeName)),
|
|
98
|
+
logger_1.chalk.grey('{'),
|
|
100
99
|
].join(' '));
|
|
101
100
|
for (const childName in typeCoverage.children) {
|
|
102
101
|
if (Object.prototype.hasOwnProperty.call(typeCoverage.children, childName)) {
|
|
103
102
|
const childCoverage = typeCoverage.children[childName];
|
|
104
103
|
if (childCoverage.hits) {
|
|
105
|
-
|
|
104
|
+
logger_1.Logger.log([indent(childName, 2), logger_1.chalk.italic.grey(`x ${childCoverage.hits}`)].join(' '));
|
|
106
105
|
}
|
|
107
106
|
else {
|
|
108
|
-
|
|
107
|
+
logger_1.Logger.log([logger_1.chalk.redBright(indent(childName, 2)), logger_1.chalk.italic.grey('x 0')].join(' '));
|
|
109
108
|
}
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
|
-
|
|
111
|
+
logger_1.Logger.log(logger_1.chalk.grey('}\n'));
|
|
113
112
|
}
|
|
114
113
|
}
|
|
115
|
-
|
|
114
|
+
logger_1.Logger.log(`Types covered: ${coverage.stats.numTypes > 0
|
|
116
115
|
? ((coverage.stats.numTypesCovered / coverage.stats.numTypes) * 100).toFixed(1)
|
|
117
116
|
: 'N/A'}%`);
|
|
118
|
-
|
|
117
|
+
logger_1.Logger.log(`Types covered fully: ${coverage.stats.numTypes > 0
|
|
119
118
|
? ((coverage.stats.numTypesCoveredFully / coverage.stats.numTypes) * 100).toFixed(1)
|
|
120
119
|
: 'N/A'}%`);
|
|
121
|
-
|
|
120
|
+
logger_1.Logger.log(`Fields covered: ${coverage.stats.numFields > 0
|
|
122
121
|
? ((coverage.stats.numFiledsCovered / coverage.stats.numFields) * 100).toFixed(1)
|
|
123
122
|
: 'N/A'}%`);
|
|
124
|
-
|
|
123
|
+
logger_1.Logger.log(``);
|
|
125
124
|
}
|
|
126
125
|
function indent(line, space) {
|
|
127
126
|
return line.padStart(line.length + space, ' ');
|
|
128
127
|
}
|
|
129
|
-
|
|
130
|
-
exports.default = index;
|
|
131
|
-
exports.handler = handler;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { __awaiter } from
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
2
|
import { writeFileSync } from 'fs';
|
|
3
3
|
import { extname } from 'path';
|
|
4
|
-
import {
|
|
5
|
-
import { createCommand, parseGlobalArgs,
|
|
6
|
-
import { coverage, getTypePrefix } from '@graphql-inspector/core';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
function handler({ schema, documents, silent, writePath, }) {
|
|
4
|
+
import { print, Source } from 'graphql';
|
|
5
|
+
import { createCommand, ensureAbsolute, parseGlobalArgs, } from '@graphql-inspector/commands';
|
|
6
|
+
import { coverage as calculateCoverage, getTypePrefix, } from '@graphql-inspector/core';
|
|
7
|
+
import { chalk, Logger } from '@graphql-inspector/logger';
|
|
8
|
+
export function handler({ schema, documents, silent, writePath, }) {
|
|
10
9
|
const shouldWrite = typeof writePath !== 'undefined';
|
|
11
|
-
const coverage
|
|
10
|
+
const coverage = calculateCoverage(schema, documents.map(doc => new Source(print(doc.document), doc.location)));
|
|
12
11
|
if (silent !== true) {
|
|
13
|
-
renderCoverage(coverage
|
|
12
|
+
renderCoverage(coverage);
|
|
14
13
|
}
|
|
15
14
|
if (shouldWrite) {
|
|
16
15
|
if (typeof writePath !== 'string') {
|
|
@@ -20,7 +19,7 @@ function handler({ schema, documents, silent, writePath, }) {
|
|
|
20
19
|
const ext = extname(absPath).replace('.', '').toLocaleLowerCase();
|
|
21
20
|
let output = undefined;
|
|
22
21
|
if (ext === 'json') {
|
|
23
|
-
output = outputJSON(coverage
|
|
22
|
+
output = outputJSON(coverage);
|
|
24
23
|
}
|
|
25
24
|
if (output) {
|
|
26
25
|
writeFileSync(absPath, output, 'utf8');
|
|
@@ -31,7 +30,7 @@ function handler({ schema, documents, silent, writePath, }) {
|
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
|
-
|
|
33
|
+
export default createCommand(api => {
|
|
35
34
|
const { loaders } = api;
|
|
36
35
|
return {
|
|
37
36
|
command: 'coverage <documents> <schema>',
|
|
@@ -122,6 +121,3 @@ function renderCoverage(coverage) {
|
|
|
122
121
|
function indent(line, space) {
|
|
123
122
|
return line.padStart(line.length + space, ' ');
|
|
124
123
|
}
|
|
125
|
-
|
|
126
|
-
export default index;
|
|
127
|
-
export { handler };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-inspector/coverage-command",
|
|
3
|
-
"version": "4.0.4
|
|
3
|
+
"version": "4.0.4",
|
|
4
4
|
"description": "Schema Coverage in GraphQL Inspector",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@graphql-tools/utils": "^9.0.0",
|
|
11
11
|
"tslib": "^2.0.0",
|
|
12
|
-
"@graphql-inspector/commands": "3.4.
|
|
13
|
-
"@graphql-inspector/core": "4.
|
|
14
|
-
"@graphql-inspector/logger": "3.4.
|
|
12
|
+
"@graphql-inspector/commands": "3.4.5",
|
|
13
|
+
"@graphql-inspector/core": "4.0.3",
|
|
14
|
+
"@graphql-inspector/logger": "3.4.4"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
@@ -30,20 +30,41 @@
|
|
|
30
30
|
"url": "https://github.com/kamilkisiela"
|
|
31
31
|
},
|
|
32
32
|
"license": "MIT",
|
|
33
|
-
"main": "index.js",
|
|
34
|
-
"module": "index.
|
|
35
|
-
"typings": "index.d.ts",
|
|
33
|
+
"main": "cjs/index.js",
|
|
34
|
+
"module": "esm/index.js",
|
|
35
|
+
"typings": "typings/index.d.ts",
|
|
36
36
|
"typescript": {
|
|
37
|
-
"definition": "index.d.ts"
|
|
37
|
+
"definition": "typings/index.d.ts"
|
|
38
38
|
},
|
|
39
|
+
"type": "module",
|
|
39
40
|
"exports": {
|
|
40
41
|
".": {
|
|
41
|
-
"require":
|
|
42
|
-
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./typings/index.d.cts",
|
|
44
|
+
"default": "./cjs/index.js"
|
|
45
|
+
},
|
|
46
|
+
"import": {
|
|
47
|
+
"types": "./typings/index.d.ts",
|
|
48
|
+
"default": "./esm/index.js"
|
|
49
|
+
},
|
|
50
|
+
"default": {
|
|
51
|
+
"types": "./typings/index.d.ts",
|
|
52
|
+
"default": "./esm/index.js"
|
|
53
|
+
}
|
|
43
54
|
},
|
|
44
55
|
"./*": {
|
|
45
|
-
"require":
|
|
46
|
-
|
|
56
|
+
"require": {
|
|
57
|
+
"types": "./typings/*.d.cts",
|
|
58
|
+
"default": "./cjs/*.js"
|
|
59
|
+
},
|
|
60
|
+
"import": {
|
|
61
|
+
"types": "./typings/*.d.ts",
|
|
62
|
+
"default": "./esm/*.js"
|
|
63
|
+
},
|
|
64
|
+
"default": {
|
|
65
|
+
"types": "./typings/*.d.ts",
|
|
66
|
+
"default": "./esm/*.js"
|
|
67
|
+
}
|
|
47
68
|
},
|
|
48
69
|
"./package.json": "./package.json"
|
|
49
70
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { CommandFactory, GlobalArgs } from '@graphql-inspector/commands';
|
|
3
|
+
import { Source as DocumentSource } from '@graphql-tools/utils';
|
|
4
|
+
export { CommandFactory };
|
|
5
|
+
export declare function handler({ schema, documents, silent, writePath, }: {
|
|
6
|
+
schema: GraphQLSchema;
|
|
7
|
+
documents: DocumentSource[];
|
|
8
|
+
silent?: boolean;
|
|
9
|
+
writePath?: string;
|
|
10
|
+
}): void;
|
|
11
|
+
declare const _default: CommandFactory<{}, {
|
|
12
|
+
schema: string;
|
|
13
|
+
documents: string;
|
|
14
|
+
write?: string | undefined;
|
|
15
|
+
silent?: boolean | undefined;
|
|
16
|
+
} & GlobalArgs>;
|
|
17
|
+
export default _default;
|
|
File without changes
|