@graphql-inspector/validate-command 3.3.0 → 3.4.0
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 +7 -1
- package/index.js +33 -15
- package/index.mjs +33 -15
- package/package.json +4 -4
package/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { GlobalArgs, CommandFactory } from '@graphql-inspector/commands';
|
|
|
2
2
|
import { Source as DocumentSource } from '@graphql-tools/utils';
|
|
3
3
|
import { GraphQLSchema } from 'graphql';
|
|
4
4
|
export { CommandFactory };
|
|
5
|
-
export declare function handler({ schema, documents, strictFragments, maxDepth, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, }: {
|
|
5
|
+
export declare function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCount, maxAliasCount, maxTokenCount, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, }: {
|
|
6
6
|
schema: GraphQLSchema;
|
|
7
7
|
documents: DocumentSource[];
|
|
8
8
|
failOnDeprecated: boolean;
|
|
@@ -10,6 +10,9 @@ export declare function handler({ schema, documents, strictFragments, maxDepth,
|
|
|
10
10
|
apollo: boolean;
|
|
11
11
|
keepClientFields: boolean;
|
|
12
12
|
maxDepth?: number;
|
|
13
|
+
maxDirectiveCount?: number;
|
|
14
|
+
maxAliasCount?: number;
|
|
15
|
+
maxTokenCount?: number;
|
|
13
16
|
filter?: string[];
|
|
14
17
|
onlyErrors?: boolean;
|
|
15
18
|
relativePaths?: boolean;
|
|
@@ -24,6 +27,9 @@ declare const _default: CommandFactory<{}, {
|
|
|
24
27
|
apollo: boolean;
|
|
25
28
|
keepClientFields: boolean;
|
|
26
29
|
maxDepth?: number | undefined;
|
|
30
|
+
maxAliasCount?: number | undefined;
|
|
31
|
+
maxDirectiveCount?: number | undefined;
|
|
32
|
+
maxTokenCount?: number | undefined;
|
|
27
33
|
filter?: string[] | undefined;
|
|
28
34
|
onlyErrors?: boolean | undefined;
|
|
29
35
|
relativePaths?: boolean | undefined;
|
package/index.js
CHANGED
|
@@ -10,10 +10,13 @@ const path = require('path');
|
|
|
10
10
|
const fs = require('fs');
|
|
11
11
|
const graphql = require('graphql');
|
|
12
12
|
|
|
13
|
-
function handler({ schema, documents, strictFragments, maxDepth, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, }) {
|
|
14
|
-
let invalidDocuments = core.validate(schema, documents.map(
|
|
13
|
+
function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCount, maxAliasCount, maxTokenCount, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, }) {
|
|
14
|
+
let invalidDocuments = core.validate(schema, documents.map(doc => new graphql.Source(graphql.print(doc.document), doc.location)), {
|
|
15
15
|
strictFragments,
|
|
16
16
|
maxDepth,
|
|
17
|
+
maxAliasCount,
|
|
18
|
+
maxDirectiveCount,
|
|
19
|
+
maxTokenCount,
|
|
17
20
|
apollo,
|
|
18
21
|
keepClientFields,
|
|
19
22
|
});
|
|
@@ -59,7 +62,7 @@ function handler({ schema, documents, strictFragments, maxDepth, apollo, keepCli
|
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
64
|
function moveDeprecatedToErrors(docs) {
|
|
62
|
-
return docs.map(
|
|
65
|
+
return docs.map(doc => {
|
|
63
66
|
var _a, _b;
|
|
64
67
|
return ({
|
|
65
68
|
source: doc.source,
|
|
@@ -69,7 +72,7 @@ function moveDeprecatedToErrors(docs) {
|
|
|
69
72
|
});
|
|
70
73
|
}
|
|
71
74
|
function useRelativePaths(docs) {
|
|
72
|
-
return docs.map(
|
|
75
|
+
return docs.map(doc => {
|
|
73
76
|
doc.source.name = path.relative(process.cwd(), doc.source.name);
|
|
74
77
|
return doc;
|
|
75
78
|
});
|
|
@@ -78,9 +81,9 @@ function useFilter(docs, patterns) {
|
|
|
78
81
|
if (!patterns || !patterns.length) {
|
|
79
82
|
return docs;
|
|
80
83
|
}
|
|
81
|
-
return docs.filter(
|
|
84
|
+
return docs.filter(doc => patterns.some(filepath => doc.source.name.includes(filepath)));
|
|
82
85
|
}
|
|
83
|
-
const index = commands.createCommand(
|
|
86
|
+
const index = commands.createCommand(api => {
|
|
84
87
|
const { loaders } = api;
|
|
85
88
|
return {
|
|
86
89
|
command: 'validate <documents> <schema>',
|
|
@@ -113,6 +116,18 @@ const index = commands.createCommand((api) => {
|
|
|
113
116
|
describe: 'Fail on deep operations',
|
|
114
117
|
type: 'number',
|
|
115
118
|
},
|
|
119
|
+
maxAliasCount: {
|
|
120
|
+
describe: 'Fail on operations with too many aliases',
|
|
121
|
+
type: 'number',
|
|
122
|
+
},
|
|
123
|
+
maxDirectiveCount: {
|
|
124
|
+
describe: 'Fail on operations with too many directives',
|
|
125
|
+
type: 'number',
|
|
126
|
+
},
|
|
127
|
+
maxTokenCount: {
|
|
128
|
+
describe: 'Fail on operations with too many tokens',
|
|
129
|
+
type: 'number',
|
|
130
|
+
},
|
|
116
131
|
apollo: {
|
|
117
132
|
describe: 'Support Apollo directives',
|
|
118
133
|
type: 'boolean',
|
|
@@ -162,7 +177,10 @@ const index = commands.createCommand((api) => {
|
|
|
162
177
|
const aws = args.aws || false;
|
|
163
178
|
const apolloFederation = args.federation || false;
|
|
164
179
|
const method = ((_a = args.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'POST';
|
|
165
|
-
const maxDepth = args.maxDepth
|
|
180
|
+
const maxDepth = args.maxDepth != null ? args.maxDepth : undefined;
|
|
181
|
+
const maxAliasCount = args.maxAliasCount != null ? args.maxAliasCount : undefined;
|
|
182
|
+
const maxDirectiveCount = args.maxDirectiveCount != null ? args.maxDirectiveCount : undefined;
|
|
183
|
+
const maxTokenCount = args.maxTokenCount != null ? args.maxTokenCount : undefined;
|
|
166
184
|
const strictFragments = !args.noStrictFragments;
|
|
167
185
|
const keepClientFields = args.keepClientFields || false;
|
|
168
186
|
const failOnDeprecated = args.deprecated;
|
|
@@ -184,6 +202,9 @@ const index = commands.createCommand((api) => {
|
|
|
184
202
|
documents,
|
|
185
203
|
apollo,
|
|
186
204
|
maxDepth,
|
|
205
|
+
maxAliasCount,
|
|
206
|
+
maxDirectiveCount,
|
|
207
|
+
maxTokenCount,
|
|
187
208
|
strictFragments,
|
|
188
209
|
keepClientFields,
|
|
189
210
|
failOnDeprecated,
|
|
@@ -199,14 +220,13 @@ const index = commands.createCommand((api) => {
|
|
|
199
220
|
});
|
|
200
221
|
function countErrors(invalidDocuments) {
|
|
201
222
|
if (invalidDocuments.length) {
|
|
202
|
-
return invalidDocuments.filter(
|
|
203
|
-
.length;
|
|
223
|
+
return invalidDocuments.filter(doc => doc.errors && doc.errors.length).length;
|
|
204
224
|
}
|
|
205
225
|
return 0;
|
|
206
226
|
}
|
|
207
227
|
function countDeprecated(invalidDocuments) {
|
|
208
228
|
if (invalidDocuments.length) {
|
|
209
|
-
return invalidDocuments.filter(
|
|
229
|
+
return invalidDocuments.filter(doc => doc.deprecated && doc.deprecated.length).length;
|
|
210
230
|
}
|
|
211
231
|
return 0;
|
|
212
232
|
}
|
|
@@ -214,18 +234,16 @@ function printInvalidDocuments(invalidDocuments, listKey, isError = false, silen
|
|
|
214
234
|
if (silent) {
|
|
215
235
|
return;
|
|
216
236
|
}
|
|
217
|
-
invalidDocuments.forEach(
|
|
237
|
+
invalidDocuments.forEach(doc => {
|
|
218
238
|
if (doc.errors.length) {
|
|
219
|
-
renderErrors(doc.source.name, doc[listKey], isError).forEach(
|
|
239
|
+
renderErrors(doc.source.name, doc[listKey], isError).forEach(line => {
|
|
220
240
|
logger.Logger.log(line);
|
|
221
241
|
});
|
|
222
242
|
}
|
|
223
243
|
});
|
|
224
244
|
}
|
|
225
245
|
function renderErrors(sourceName, errors, isError = false) {
|
|
226
|
-
const errorsAsString = errors
|
|
227
|
-
.map((e) => ` - ${logger.bolderize(e.message)}`)
|
|
228
|
-
.join('\n');
|
|
246
|
+
const errorsAsString = errors.map(e => ` - ${logger.bolderize(e.message)}`).join('\n');
|
|
229
247
|
return [
|
|
230
248
|
isError ? logger.chalk.redBright('error') : logger.chalk.yellowBright('warn'),
|
|
231
249
|
`in ${sourceName}:\n\n`,
|
package/index.mjs
CHANGED
|
@@ -6,10 +6,13 @@ import { relative } from 'path';
|
|
|
6
6
|
import { writeFileSync } from 'fs';
|
|
7
7
|
import { Source, print } from 'graphql';
|
|
8
8
|
|
|
9
|
-
function handler({ schema, documents, strictFragments, maxDepth, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, }) {
|
|
10
|
-
let invalidDocuments = validate(schema, documents.map(
|
|
9
|
+
function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCount, maxAliasCount, maxTokenCount, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, }) {
|
|
10
|
+
let invalidDocuments = validate(schema, documents.map(doc => new Source(print(doc.document), doc.location)), {
|
|
11
11
|
strictFragments,
|
|
12
12
|
maxDepth,
|
|
13
|
+
maxAliasCount,
|
|
14
|
+
maxDirectiveCount,
|
|
15
|
+
maxTokenCount,
|
|
13
16
|
apollo,
|
|
14
17
|
keepClientFields,
|
|
15
18
|
});
|
|
@@ -55,7 +58,7 @@ function handler({ schema, documents, strictFragments, maxDepth, apollo, keepCli
|
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
60
|
function moveDeprecatedToErrors(docs) {
|
|
58
|
-
return docs.map(
|
|
61
|
+
return docs.map(doc => {
|
|
59
62
|
var _a, _b;
|
|
60
63
|
return ({
|
|
61
64
|
source: doc.source,
|
|
@@ -65,7 +68,7 @@ function moveDeprecatedToErrors(docs) {
|
|
|
65
68
|
});
|
|
66
69
|
}
|
|
67
70
|
function useRelativePaths(docs) {
|
|
68
|
-
return docs.map(
|
|
71
|
+
return docs.map(doc => {
|
|
69
72
|
doc.source.name = relative(process.cwd(), doc.source.name);
|
|
70
73
|
return doc;
|
|
71
74
|
});
|
|
@@ -74,9 +77,9 @@ function useFilter(docs, patterns) {
|
|
|
74
77
|
if (!patterns || !patterns.length) {
|
|
75
78
|
return docs;
|
|
76
79
|
}
|
|
77
|
-
return docs.filter(
|
|
80
|
+
return docs.filter(doc => patterns.some(filepath => doc.source.name.includes(filepath)));
|
|
78
81
|
}
|
|
79
|
-
const index = createCommand(
|
|
82
|
+
const index = createCommand(api => {
|
|
80
83
|
const { loaders } = api;
|
|
81
84
|
return {
|
|
82
85
|
command: 'validate <documents> <schema>',
|
|
@@ -109,6 +112,18 @@ const index = createCommand((api) => {
|
|
|
109
112
|
describe: 'Fail on deep operations',
|
|
110
113
|
type: 'number',
|
|
111
114
|
},
|
|
115
|
+
maxAliasCount: {
|
|
116
|
+
describe: 'Fail on operations with too many aliases',
|
|
117
|
+
type: 'number',
|
|
118
|
+
},
|
|
119
|
+
maxDirectiveCount: {
|
|
120
|
+
describe: 'Fail on operations with too many directives',
|
|
121
|
+
type: 'number',
|
|
122
|
+
},
|
|
123
|
+
maxTokenCount: {
|
|
124
|
+
describe: 'Fail on operations with too many tokens',
|
|
125
|
+
type: 'number',
|
|
126
|
+
},
|
|
112
127
|
apollo: {
|
|
113
128
|
describe: 'Support Apollo directives',
|
|
114
129
|
type: 'boolean',
|
|
@@ -158,7 +173,10 @@ const index = createCommand((api) => {
|
|
|
158
173
|
const aws = args.aws || false;
|
|
159
174
|
const apolloFederation = args.federation || false;
|
|
160
175
|
const method = ((_a = args.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'POST';
|
|
161
|
-
const maxDepth = args.maxDepth
|
|
176
|
+
const maxDepth = args.maxDepth != null ? args.maxDepth : undefined;
|
|
177
|
+
const maxAliasCount = args.maxAliasCount != null ? args.maxAliasCount : undefined;
|
|
178
|
+
const maxDirectiveCount = args.maxDirectiveCount != null ? args.maxDirectiveCount : undefined;
|
|
179
|
+
const maxTokenCount = args.maxTokenCount != null ? args.maxTokenCount : undefined;
|
|
162
180
|
const strictFragments = !args.noStrictFragments;
|
|
163
181
|
const keepClientFields = args.keepClientFields || false;
|
|
164
182
|
const failOnDeprecated = args.deprecated;
|
|
@@ -180,6 +198,9 @@ const index = createCommand((api) => {
|
|
|
180
198
|
documents,
|
|
181
199
|
apollo,
|
|
182
200
|
maxDepth,
|
|
201
|
+
maxAliasCount,
|
|
202
|
+
maxDirectiveCount,
|
|
203
|
+
maxTokenCount,
|
|
183
204
|
strictFragments,
|
|
184
205
|
keepClientFields,
|
|
185
206
|
failOnDeprecated,
|
|
@@ -195,14 +216,13 @@ const index = createCommand((api) => {
|
|
|
195
216
|
});
|
|
196
217
|
function countErrors(invalidDocuments) {
|
|
197
218
|
if (invalidDocuments.length) {
|
|
198
|
-
return invalidDocuments.filter(
|
|
199
|
-
.length;
|
|
219
|
+
return invalidDocuments.filter(doc => doc.errors && doc.errors.length).length;
|
|
200
220
|
}
|
|
201
221
|
return 0;
|
|
202
222
|
}
|
|
203
223
|
function countDeprecated(invalidDocuments) {
|
|
204
224
|
if (invalidDocuments.length) {
|
|
205
|
-
return invalidDocuments.filter(
|
|
225
|
+
return invalidDocuments.filter(doc => doc.deprecated && doc.deprecated.length).length;
|
|
206
226
|
}
|
|
207
227
|
return 0;
|
|
208
228
|
}
|
|
@@ -210,18 +230,16 @@ function printInvalidDocuments(invalidDocuments, listKey, isError = false, silen
|
|
|
210
230
|
if (silent) {
|
|
211
231
|
return;
|
|
212
232
|
}
|
|
213
|
-
invalidDocuments.forEach(
|
|
233
|
+
invalidDocuments.forEach(doc => {
|
|
214
234
|
if (doc.errors.length) {
|
|
215
|
-
renderErrors(doc.source.name, doc[listKey], isError).forEach(
|
|
235
|
+
renderErrors(doc.source.name, doc[listKey], isError).forEach(line => {
|
|
216
236
|
Logger.log(line);
|
|
217
237
|
});
|
|
218
238
|
}
|
|
219
239
|
});
|
|
220
240
|
}
|
|
221
241
|
function renderErrors(sourceName, errors, isError = false) {
|
|
222
|
-
const errorsAsString = errors
|
|
223
|
-
.map((e) => ` - ${bolderize(e.message)}`)
|
|
224
|
-
.join('\n');
|
|
242
|
+
const errorsAsString = errors.map(e => ` - ${bolderize(e.message)}`).join('\n');
|
|
225
243
|
return [
|
|
226
244
|
isError ? chalk.redBright('error') : chalk.yellowBright('warn'),
|
|
227
245
|
`in ${sourceName}:\n\n`,
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-inspector/validate-command",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
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.
|
|
11
|
-
"@graphql-inspector/core": "3.
|
|
12
|
-
"@graphql-inspector/logger": "3.
|
|
10
|
+
"@graphql-inspector/commands": "3.4.0",
|
|
11
|
+
"@graphql-inspector/core": "3.4.0",
|
|
12
|
+
"@graphql-inspector/logger": "3.4.0",
|
|
13
13
|
"tslib": "^2.0.0"
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|