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