@graphql-inspector/validate-command 3.4.2 → 3.4.3-alpha-20230215160355-1227dabb
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 +38 -39
- package/index.mjs +38 -39
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -22,41 +22,40 @@ function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCou
|
|
|
22
22
|
});
|
|
23
23
|
if (!invalidDocuments.length) {
|
|
24
24
|
logger.Logger.success('All documents are valid');
|
|
25
|
+
return;
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
logger.Logger.log(`\nDetected ${errorsCount} invalid document${errorsCount > 1 ? 's' : ''}:\n`);
|
|
39
|
-
}
|
|
40
|
-
printInvalidDocuments(useFilter(invalidDocuments, filter), 'errors', true, silent);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
logger.Logger.success('All documents are valid');
|
|
44
|
-
}
|
|
45
|
-
if (deprecated && !onlyErrors) {
|
|
46
|
-
if (!silent) {
|
|
47
|
-
logger.Logger.info(`\nDetected ${deprecated} document${deprecated > 1 ? 's' : ''} with deprecated fields:\n`);
|
|
48
|
-
}
|
|
49
|
-
printInvalidDocuments(useFilter(invalidDocuments, filter), 'deprecated', false, silent);
|
|
50
|
-
}
|
|
51
|
-
if (output) {
|
|
52
|
-
fs.writeFileSync(output, JSON.stringify({
|
|
53
|
-
status: !shouldFailProcess,
|
|
54
|
-
documents: useFilter(invalidDocuments, filter),
|
|
55
|
-
}, null, 2), 'utf8');
|
|
27
|
+
if (failOnDeprecated) {
|
|
28
|
+
invalidDocuments = moveDeprecatedToErrors(invalidDocuments);
|
|
29
|
+
}
|
|
30
|
+
if (relativePaths) {
|
|
31
|
+
invalidDocuments = useRelativePaths(invalidDocuments);
|
|
32
|
+
}
|
|
33
|
+
const errorsCount = countErrors(invalidDocuments);
|
|
34
|
+
const deprecated = countDeprecated(invalidDocuments);
|
|
35
|
+
const shouldFailProcess = errorsCount > 0;
|
|
36
|
+
if (errorsCount) {
|
|
37
|
+
if (!silent) {
|
|
38
|
+
logger.Logger.log(`\nDetected ${errorsCount} invalid document${errorsCount > 1 ? 's' : ''}:\n`);
|
|
56
39
|
}
|
|
57
|
-
|
|
58
|
-
|
|
40
|
+
printInvalidDocuments(useFilter(invalidDocuments, filter), 'errors', true, silent);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
logger.Logger.success('All documents are valid');
|
|
44
|
+
}
|
|
45
|
+
if (deprecated && !onlyErrors) {
|
|
46
|
+
if (!silent) {
|
|
47
|
+
logger.Logger.info(`\nDetected ${deprecated} document${deprecated > 1 ? 's' : ''} with deprecated fields:\n`);
|
|
59
48
|
}
|
|
49
|
+
printInvalidDocuments(useFilter(invalidDocuments, filter), 'deprecated', false, silent);
|
|
50
|
+
}
|
|
51
|
+
if (output) {
|
|
52
|
+
fs.writeFileSync(output, JSON.stringify({
|
|
53
|
+
status: !shouldFailProcess,
|
|
54
|
+
documents: useFilter(invalidDocuments, filter),
|
|
55
|
+
}, null, 2), 'utf8');
|
|
56
|
+
}
|
|
57
|
+
if (shouldFailProcess) {
|
|
58
|
+
process.exit(1);
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
function moveDeprecatedToErrors(docs) {
|
|
@@ -76,7 +75,7 @@ function useRelativePaths(docs) {
|
|
|
76
75
|
});
|
|
77
76
|
}
|
|
78
77
|
function useFilter(docs, patterns) {
|
|
79
|
-
if (!patterns ||
|
|
78
|
+
if (!(patterns === null || patterns === void 0 ? void 0 : patterns.length)) {
|
|
80
79
|
return docs;
|
|
81
80
|
}
|
|
82
81
|
return docs.filter(doc => patterns.some(filepath => doc.source.name.includes(filepath)));
|
|
@@ -175,10 +174,10 @@ const index = commands.createCommand(api => {
|
|
|
175
174
|
const aws = args.aws || false;
|
|
176
175
|
const apolloFederation = args.federation || false;
|
|
177
176
|
const method = ((_a = args.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'POST';
|
|
178
|
-
const maxDepth = args.maxDepth
|
|
179
|
-
const maxAliasCount = args.maxAliasCount
|
|
180
|
-
const maxDirectiveCount = args.maxDirectiveCount
|
|
181
|
-
const maxTokenCount = args.maxTokenCount
|
|
177
|
+
const maxDepth = args.maxDepth == null ? undefined : args.maxDepth;
|
|
178
|
+
const maxAliasCount = args.maxAliasCount == null ? undefined : args.maxAliasCount;
|
|
179
|
+
const maxDirectiveCount = args.maxDirectiveCount == null ? undefined : args.maxDirectiveCount;
|
|
180
|
+
const maxTokenCount = args.maxTokenCount == null ? undefined : args.maxTokenCount;
|
|
182
181
|
const strictFragments = !args.noStrictFragments;
|
|
183
182
|
const keepClientFields = args.keepClientFields || false;
|
|
184
183
|
const failOnDeprecated = args.deprecated;
|
|
@@ -218,13 +217,13 @@ const index = commands.createCommand(api => {
|
|
|
218
217
|
});
|
|
219
218
|
function countErrors(invalidDocuments) {
|
|
220
219
|
if (invalidDocuments.length) {
|
|
221
|
-
return invalidDocuments.filter(doc => doc.errors
|
|
220
|
+
return invalidDocuments.filter(doc => { var _a; return (_a = doc.errors) === null || _a === void 0 ? void 0 : _a.length; }).length;
|
|
222
221
|
}
|
|
223
222
|
return 0;
|
|
224
223
|
}
|
|
225
224
|
function countDeprecated(invalidDocuments) {
|
|
226
225
|
if (invalidDocuments.length) {
|
|
227
|
-
return invalidDocuments.filter(doc => doc.deprecated
|
|
226
|
+
return invalidDocuments.filter(doc => { var _a; return (_a = doc.deprecated) === null || _a === void 0 ? void 0 : _a.length; }).length;
|
|
228
227
|
}
|
|
229
228
|
return 0;
|
|
230
229
|
}
|
package/index.mjs
CHANGED
|
@@ -18,41 +18,40 @@ function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCou
|
|
|
18
18
|
});
|
|
19
19
|
if (!invalidDocuments.length) {
|
|
20
20
|
Logger.success('All documents are valid');
|
|
21
|
+
return;
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
Logger.log(`\nDetected ${errorsCount} invalid document${errorsCount > 1 ? 's' : ''}:\n`);
|
|
35
|
-
}
|
|
36
|
-
printInvalidDocuments(useFilter(invalidDocuments, filter), 'errors', true, silent);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
Logger.success('All documents are valid');
|
|
40
|
-
}
|
|
41
|
-
if (deprecated && !onlyErrors) {
|
|
42
|
-
if (!silent) {
|
|
43
|
-
Logger.info(`\nDetected ${deprecated} document${deprecated > 1 ? 's' : ''} with deprecated fields:\n`);
|
|
44
|
-
}
|
|
45
|
-
printInvalidDocuments(useFilter(invalidDocuments, filter), 'deprecated', false, silent);
|
|
46
|
-
}
|
|
47
|
-
if (output) {
|
|
48
|
-
writeFileSync(output, JSON.stringify({
|
|
49
|
-
status: !shouldFailProcess,
|
|
50
|
-
documents: useFilter(invalidDocuments, filter),
|
|
51
|
-
}, null, 2), 'utf8');
|
|
23
|
+
if (failOnDeprecated) {
|
|
24
|
+
invalidDocuments = moveDeprecatedToErrors(invalidDocuments);
|
|
25
|
+
}
|
|
26
|
+
if (relativePaths) {
|
|
27
|
+
invalidDocuments = useRelativePaths(invalidDocuments);
|
|
28
|
+
}
|
|
29
|
+
const errorsCount = countErrors(invalidDocuments);
|
|
30
|
+
const deprecated = countDeprecated(invalidDocuments);
|
|
31
|
+
const shouldFailProcess = errorsCount > 0;
|
|
32
|
+
if (errorsCount) {
|
|
33
|
+
if (!silent) {
|
|
34
|
+
Logger.log(`\nDetected ${errorsCount} invalid document${errorsCount > 1 ? 's' : ''}:\n`);
|
|
52
35
|
}
|
|
53
|
-
|
|
54
|
-
|
|
36
|
+
printInvalidDocuments(useFilter(invalidDocuments, filter), 'errors', true, silent);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
Logger.success('All documents are valid');
|
|
40
|
+
}
|
|
41
|
+
if (deprecated && !onlyErrors) {
|
|
42
|
+
if (!silent) {
|
|
43
|
+
Logger.info(`\nDetected ${deprecated} document${deprecated > 1 ? 's' : ''} with deprecated fields:\n`);
|
|
55
44
|
}
|
|
45
|
+
printInvalidDocuments(useFilter(invalidDocuments, filter), 'deprecated', false, silent);
|
|
46
|
+
}
|
|
47
|
+
if (output) {
|
|
48
|
+
writeFileSync(output, JSON.stringify({
|
|
49
|
+
status: !shouldFailProcess,
|
|
50
|
+
documents: useFilter(invalidDocuments, filter),
|
|
51
|
+
}, null, 2), 'utf8');
|
|
52
|
+
}
|
|
53
|
+
if (shouldFailProcess) {
|
|
54
|
+
process.exit(1);
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
57
|
function moveDeprecatedToErrors(docs) {
|
|
@@ -72,7 +71,7 @@ function useRelativePaths(docs) {
|
|
|
72
71
|
});
|
|
73
72
|
}
|
|
74
73
|
function useFilter(docs, patterns) {
|
|
75
|
-
if (!patterns ||
|
|
74
|
+
if (!(patterns === null || patterns === void 0 ? void 0 : patterns.length)) {
|
|
76
75
|
return docs;
|
|
77
76
|
}
|
|
78
77
|
return docs.filter(doc => patterns.some(filepath => doc.source.name.includes(filepath)));
|
|
@@ -171,10 +170,10 @@ const index = createCommand(api => {
|
|
|
171
170
|
const aws = args.aws || false;
|
|
172
171
|
const apolloFederation = args.federation || false;
|
|
173
172
|
const method = ((_a = args.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'POST';
|
|
174
|
-
const maxDepth = args.maxDepth
|
|
175
|
-
const maxAliasCount = args.maxAliasCount
|
|
176
|
-
const maxDirectiveCount = args.maxDirectiveCount
|
|
177
|
-
const maxTokenCount = args.maxTokenCount
|
|
173
|
+
const maxDepth = args.maxDepth == null ? undefined : args.maxDepth;
|
|
174
|
+
const maxAliasCount = args.maxAliasCount == null ? undefined : args.maxAliasCount;
|
|
175
|
+
const maxDirectiveCount = args.maxDirectiveCount == null ? undefined : args.maxDirectiveCount;
|
|
176
|
+
const maxTokenCount = args.maxTokenCount == null ? undefined : args.maxTokenCount;
|
|
178
177
|
const strictFragments = !args.noStrictFragments;
|
|
179
178
|
const keepClientFields = args.keepClientFields || false;
|
|
180
179
|
const failOnDeprecated = args.deprecated;
|
|
@@ -214,13 +213,13 @@ const index = createCommand(api => {
|
|
|
214
213
|
});
|
|
215
214
|
function countErrors(invalidDocuments) {
|
|
216
215
|
if (invalidDocuments.length) {
|
|
217
|
-
return invalidDocuments.filter(doc => doc.errors
|
|
216
|
+
return invalidDocuments.filter(doc => { var _a; return (_a = doc.errors) === null || _a === void 0 ? void 0 : _a.length; }).length;
|
|
218
217
|
}
|
|
219
218
|
return 0;
|
|
220
219
|
}
|
|
221
220
|
function countDeprecated(invalidDocuments) {
|
|
222
221
|
if (invalidDocuments.length) {
|
|
223
|
-
return invalidDocuments.filter(doc => doc.deprecated
|
|
222
|
+
return invalidDocuments.filter(doc => { var _a; return (_a = doc.deprecated) === null || _a === void 0 ? void 0 : _a.length; }).length;
|
|
224
223
|
}
|
|
225
224
|
return 0;
|
|
226
225
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-inspector/validate-command",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.3-alpha-20230215160355-1227dabb",
|
|
4
4
|
"description": "Validate Documents in GraphQL Inspector",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@graphql-inspector/commands": "3.4.1",
|
|
11
|
-
"@graphql-inspector/core": "3.5.
|
|
12
|
-
"@graphql-inspector/logger": "3.4.
|
|
11
|
+
"@graphql-inspector/core": "3.5.1",
|
|
12
|
+
"@graphql-inspector/logger": "3.4.2-alpha-20230215160355-1227dabb",
|
|
13
13
|
"tslib": "^2.0.0"
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|