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