@graphql-inspector/audit-command 0.0.0-canary.9e26f61
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.d.ts +11 -0
- package/index.js +89 -0
- package/index.mjs +83 -0
- package/package.json +49 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { GlobalArgs } from '@graphql-inspector/commands';
|
|
2
|
+
import { Source as DocumentSource } from '@graphql-tools/utils';
|
|
3
|
+
declare const _default: import("@graphql-inspector/commands").CommandFactory<{}, {
|
|
4
|
+
documents: string;
|
|
5
|
+
detail: boolean;
|
|
6
|
+
} & GlobalArgs>;
|
|
7
|
+
export default _default;
|
|
8
|
+
export declare function handler(args: {
|
|
9
|
+
documents: DocumentSource[];
|
|
10
|
+
detail: boolean;
|
|
11
|
+
}): void;
|
package/index.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
+
|
|
7
|
+
const tslib = require('tslib');
|
|
8
|
+
const commands = require('@graphql-inspector/commands');
|
|
9
|
+
const core = require('@graphql-inspector/core');
|
|
10
|
+
const logger = require('@graphql-inspector/logger');
|
|
11
|
+
const Table = _interopDefault(require('cli-table3'));
|
|
12
|
+
|
|
13
|
+
const index = commands.createCommand(api => {
|
|
14
|
+
return {
|
|
15
|
+
command: 'audit <documents>',
|
|
16
|
+
describe: 'Audit Fragments and Operations for a better understanding of the depth, alias count, and directive count.',
|
|
17
|
+
builder(yargs) {
|
|
18
|
+
return yargs
|
|
19
|
+
.positional('documents', {
|
|
20
|
+
describe: 'Point to some documents',
|
|
21
|
+
type: 'string',
|
|
22
|
+
demandOption: true,
|
|
23
|
+
})
|
|
24
|
+
.options({
|
|
25
|
+
detail: {
|
|
26
|
+
alias: 'd',
|
|
27
|
+
describe: 'Print an overview of all operations and their audit breakdown.',
|
|
28
|
+
type: 'boolean',
|
|
29
|
+
default: false,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
handler(args) {
|
|
34
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const { loaders } = api;
|
|
36
|
+
const ignore = args.ignore || [];
|
|
37
|
+
const documents = yield loaders.loadDocuments(args.documents, {
|
|
38
|
+
ignore,
|
|
39
|
+
});
|
|
40
|
+
return handler({ documents, detail: args.detail });
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
function handler(args) {
|
|
46
|
+
const fragments = new Map();
|
|
47
|
+
const operations = new Map();
|
|
48
|
+
const getFragmentReference = (fragmentName) => fragments.get(fragmentName);
|
|
49
|
+
for (const record of args.documents) {
|
|
50
|
+
if (record.document) {
|
|
51
|
+
for (const definition of record.document.definitions) {
|
|
52
|
+
if (definition.kind === 'FragmentDefinition') {
|
|
53
|
+
fragments.set(definition.name.value, definition);
|
|
54
|
+
}
|
|
55
|
+
else if (definition.kind === 'OperationDefinition') {
|
|
56
|
+
if (definition.name) {
|
|
57
|
+
operations.set(definition.name.value, definition);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
let maxDepth = 0;
|
|
64
|
+
let maxAliases = 0;
|
|
65
|
+
let maxDirectives = 0;
|
|
66
|
+
const results = [];
|
|
67
|
+
for (const [name, operation] of operations.entries()) {
|
|
68
|
+
const depth = core.countDepth(operation, 0, getFragmentReference);
|
|
69
|
+
const aliases = core.countAliases(operation, getFragmentReference);
|
|
70
|
+
const directives = core.countDirectives(operation, getFragmentReference);
|
|
71
|
+
results.push([name, depth, aliases, directives]);
|
|
72
|
+
maxDepth = Math.max(maxDepth, depth);
|
|
73
|
+
maxAliases = Math.max(maxAliases, aliases);
|
|
74
|
+
maxDirectives = Math.max(maxDirectives, directives);
|
|
75
|
+
}
|
|
76
|
+
if (args.detail) {
|
|
77
|
+
const table = new Table({
|
|
78
|
+
head: ['Operation Name', 'Depth', 'Aliases', 'Directives'],
|
|
79
|
+
});
|
|
80
|
+
table.push(...results);
|
|
81
|
+
logger.Logger.log(table.toString());
|
|
82
|
+
}
|
|
83
|
+
logger.Logger.log(`Maximum depth is ${logger.chalk.bold(maxDepth)}`);
|
|
84
|
+
logger.Logger.log(`Maximum alias amount is ${logger.chalk.bold(maxAliases)}`);
|
|
85
|
+
logger.Logger.log(`Maximum directive amount is ${logger.chalk.bold(maxDirectives)}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
exports.default = index;
|
|
89
|
+
exports.handler = handler;
|
package/index.mjs
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { __awaiter } from 'tslib';
|
|
2
|
+
import { createCommand } from '@graphql-inspector/commands';
|
|
3
|
+
import { countDepth, countAliases, countDirectives } from '@graphql-inspector/core';
|
|
4
|
+
import { Logger, chalk } from '@graphql-inspector/logger';
|
|
5
|
+
import Table from 'cli-table3';
|
|
6
|
+
|
|
7
|
+
const index = createCommand(api => {
|
|
8
|
+
return {
|
|
9
|
+
command: 'audit <documents>',
|
|
10
|
+
describe: 'Audit Fragments and Operations for a better understanding of the depth, alias count, and directive count.',
|
|
11
|
+
builder(yargs) {
|
|
12
|
+
return yargs
|
|
13
|
+
.positional('documents', {
|
|
14
|
+
describe: 'Point to some documents',
|
|
15
|
+
type: 'string',
|
|
16
|
+
demandOption: true,
|
|
17
|
+
})
|
|
18
|
+
.options({
|
|
19
|
+
detail: {
|
|
20
|
+
alias: 'd',
|
|
21
|
+
describe: 'Print an overview of all operations and their audit breakdown.',
|
|
22
|
+
type: 'boolean',
|
|
23
|
+
default: false,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
handler(args) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const { loaders } = api;
|
|
30
|
+
const ignore = args.ignore || [];
|
|
31
|
+
const documents = yield loaders.loadDocuments(args.documents, {
|
|
32
|
+
ignore,
|
|
33
|
+
});
|
|
34
|
+
return handler({ documents, detail: args.detail });
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
function handler(args) {
|
|
40
|
+
const fragments = new Map();
|
|
41
|
+
const operations = new Map();
|
|
42
|
+
const getFragmentReference = (fragmentName) => fragments.get(fragmentName);
|
|
43
|
+
for (const record of args.documents) {
|
|
44
|
+
if (record.document) {
|
|
45
|
+
for (const definition of record.document.definitions) {
|
|
46
|
+
if (definition.kind === 'FragmentDefinition') {
|
|
47
|
+
fragments.set(definition.name.value, definition);
|
|
48
|
+
}
|
|
49
|
+
else if (definition.kind === 'OperationDefinition') {
|
|
50
|
+
if (definition.name) {
|
|
51
|
+
operations.set(definition.name.value, definition);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
let maxDepth = 0;
|
|
58
|
+
let maxAliases = 0;
|
|
59
|
+
let maxDirectives = 0;
|
|
60
|
+
const results = [];
|
|
61
|
+
for (const [name, operation] of operations.entries()) {
|
|
62
|
+
const depth = countDepth(operation, 0, getFragmentReference);
|
|
63
|
+
const aliases = countAliases(operation, getFragmentReference);
|
|
64
|
+
const directives = countDirectives(operation, getFragmentReference);
|
|
65
|
+
results.push([name, depth, aliases, directives]);
|
|
66
|
+
maxDepth = Math.max(maxDepth, depth);
|
|
67
|
+
maxAliases = Math.max(maxAliases, aliases);
|
|
68
|
+
maxDirectives = Math.max(maxDirectives, directives);
|
|
69
|
+
}
|
|
70
|
+
if (args.detail) {
|
|
71
|
+
const table = new Table({
|
|
72
|
+
head: ['Operation Name', 'Depth', 'Aliases', 'Directives'],
|
|
73
|
+
});
|
|
74
|
+
table.push(...results);
|
|
75
|
+
Logger.log(table.toString());
|
|
76
|
+
}
|
|
77
|
+
Logger.log(`Maximum depth is ${chalk.bold(maxDepth)}`);
|
|
78
|
+
Logger.log(`Maximum alias amount is ${chalk.bold(maxAliases)}`);
|
|
79
|
+
Logger.log(`Maximum directive amount is ${chalk.bold(maxDirectives)}`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export default index;
|
|
83
|
+
export { handler };
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@graphql-inspector/audit-command",
|
|
3
|
+
"version": "0.0.0-canary.9e26f61",
|
|
4
|
+
"description": "Audit Documents in GraphQL Inspector",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"peerDependencies": {
|
|
7
|
+
"graphql": "^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@graphql-inspector/commands": "0.0.0-canary.9e26f61",
|
|
11
|
+
"@graphql-inspector/core": "0.0.0-canary.9e26f61",
|
|
12
|
+
"@graphql-inspector/logger": "0.0.0-canary.9e26f61",
|
|
13
|
+
"cli-table3": "0.6.2",
|
|
14
|
+
"tslib": "^2.0.0"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "kamilkisiela/graphql-inspector",
|
|
19
|
+
"directory": "packages/commands/audit"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"graphql",
|
|
23
|
+
"graphql-inspector",
|
|
24
|
+
"graphql-inspector-command",
|
|
25
|
+
"tools"
|
|
26
|
+
],
|
|
27
|
+
"author": {
|
|
28
|
+
"name": "Laurin Quast",
|
|
29
|
+
"email": "laurinquast@googlemail.com",
|
|
30
|
+
"url": "https://github.com/kamilkisiela"
|
|
31
|
+
},
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"main": "index.js",
|
|
34
|
+
"module": "index.mjs",
|
|
35
|
+
"typings": "index.d.ts",
|
|
36
|
+
"typescript": {
|
|
37
|
+
"definition": "index.d.ts"
|
|
38
|
+
},
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"require": "./index.js",
|
|
42
|
+
"import": "./index.mjs"
|
|
43
|
+
},
|
|
44
|
+
"./*": {
|
|
45
|
+
"require": "./*.js",
|
|
46
|
+
"import": "./*.mjs"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|