@graphql-inspector/validate-command 0.0.0-PLACEHOLDER
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 +34 -0
- package/index.js +238 -0
- package/index.mjs +234 -0
- package/package.json +48 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { GlobalArgs, CommandFactory } from '@graphql-inspector/commands';
|
|
2
|
+
import { Source as DocumentSource } from '@graphql-tools/utils';
|
|
3
|
+
import { GraphQLSchema } from 'graphql';
|
|
4
|
+
export { CommandFactory };
|
|
5
|
+
export declare function handler({ schema, documents, strictFragments, maxDepth, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, }: {
|
|
6
|
+
schema: GraphQLSchema;
|
|
7
|
+
documents: DocumentSource[];
|
|
8
|
+
failOnDeprecated: boolean;
|
|
9
|
+
strictFragments: boolean;
|
|
10
|
+
apollo: boolean;
|
|
11
|
+
keepClientFields: boolean;
|
|
12
|
+
maxDepth?: number;
|
|
13
|
+
filter?: string[];
|
|
14
|
+
onlyErrors?: boolean;
|
|
15
|
+
relativePaths?: boolean;
|
|
16
|
+
output?: string;
|
|
17
|
+
silent?: boolean;
|
|
18
|
+
}): void;
|
|
19
|
+
declare const _default: CommandFactory<{}, {
|
|
20
|
+
schema: string;
|
|
21
|
+
documents: string;
|
|
22
|
+
deprecated: boolean;
|
|
23
|
+
noStrictFragments: boolean;
|
|
24
|
+
apollo: boolean;
|
|
25
|
+
keepClientFields: boolean;
|
|
26
|
+
maxDepth?: number | undefined;
|
|
27
|
+
filter?: string[] | undefined;
|
|
28
|
+
onlyErrors?: boolean | undefined;
|
|
29
|
+
relativePaths?: boolean | undefined;
|
|
30
|
+
output?: string | undefined;
|
|
31
|
+
silent?: boolean | undefined;
|
|
32
|
+
ignore?: string[] | undefined;
|
|
33
|
+
} & GlobalArgs>;
|
|
34
|
+
export default _default;
|
package/index.js
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const tslib = require('tslib');
|
|
6
|
+
const commands = require('@graphql-inspector/commands');
|
|
7
|
+
const logger = require('@graphql-inspector/logger');
|
|
8
|
+
const core = require('@graphql-inspector/core');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const graphql = require('graphql');
|
|
12
|
+
|
|
13
|
+
function handler({ schema, documents, strictFragments, maxDepth, 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
|
+
strictFragments,
|
|
16
|
+
maxDepth,
|
|
17
|
+
apollo,
|
|
18
|
+
keepClientFields,
|
|
19
|
+
});
|
|
20
|
+
if (!invalidDocuments.length) {
|
|
21
|
+
logger.Logger.success('All documents are valid');
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
if (failOnDeprecated) {
|
|
25
|
+
invalidDocuments = moveDeprecatedToErrors(invalidDocuments);
|
|
26
|
+
}
|
|
27
|
+
if (relativePaths) {
|
|
28
|
+
invalidDocuments = useRelativePaths(invalidDocuments);
|
|
29
|
+
}
|
|
30
|
+
const errorsCount = countErrors(invalidDocuments);
|
|
31
|
+
const deprecated = countDeprecated(invalidDocuments);
|
|
32
|
+
const shouldFailProcess = errorsCount > 0;
|
|
33
|
+
if (errorsCount) {
|
|
34
|
+
if (!silent) {
|
|
35
|
+
logger.Logger.log(`\nDetected ${errorsCount} invalid document${errorsCount > 1 ? 's' : ''}:\n`);
|
|
36
|
+
}
|
|
37
|
+
printInvalidDocuments(useFilter(invalidDocuments, filter), 'errors', true, silent);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
logger.Logger.success('All documents are valid');
|
|
41
|
+
}
|
|
42
|
+
if (deprecated && !onlyErrors) {
|
|
43
|
+
if (!silent) {
|
|
44
|
+
logger.Logger.info(`\nDetected ${deprecated} document${deprecated > 1 ? 's' : ''} with deprecated fields:\n`);
|
|
45
|
+
}
|
|
46
|
+
printInvalidDocuments(useFilter(invalidDocuments, filter), 'deprecated', false, silent);
|
|
47
|
+
}
|
|
48
|
+
if (output) {
|
|
49
|
+
fs.writeFileSync(output, JSON.stringify({
|
|
50
|
+
status: !shouldFailProcess,
|
|
51
|
+
documents: useFilter(invalidDocuments, filter),
|
|
52
|
+
}, null, 2), {
|
|
53
|
+
encoding: 'utf-8',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (shouldFailProcess) {
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function moveDeprecatedToErrors(docs) {
|
|
62
|
+
return docs.map((doc) => {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
return ({
|
|
65
|
+
source: doc.source,
|
|
66
|
+
errors: [...((_a = doc.errors) !== null && _a !== void 0 ? _a : []), ...((_b = doc.deprecated) !== null && _b !== void 0 ? _b : [])],
|
|
67
|
+
deprecated: [],
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function useRelativePaths(docs) {
|
|
72
|
+
return docs.map((doc) => {
|
|
73
|
+
doc.source.name = path.relative(process.cwd(), doc.source.name);
|
|
74
|
+
return doc;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function useFilter(docs, patterns) {
|
|
78
|
+
if (!patterns || !patterns.length) {
|
|
79
|
+
return docs;
|
|
80
|
+
}
|
|
81
|
+
return docs.filter((doc) => patterns.some((filepath) => doc.source.name.includes(filepath)));
|
|
82
|
+
}
|
|
83
|
+
const index = commands.createCommand((api) => {
|
|
84
|
+
const { loaders } = api;
|
|
85
|
+
return {
|
|
86
|
+
command: 'validate <documents> <schema>',
|
|
87
|
+
describe: 'Validate Fragments and Operations',
|
|
88
|
+
builder(yargs) {
|
|
89
|
+
return yargs
|
|
90
|
+
.positional('schema', {
|
|
91
|
+
describe: 'Point to a schema',
|
|
92
|
+
type: 'string',
|
|
93
|
+
demandOption: true,
|
|
94
|
+
})
|
|
95
|
+
.positional('documents', {
|
|
96
|
+
describe: 'Point to documents',
|
|
97
|
+
type: 'string',
|
|
98
|
+
demandOption: true,
|
|
99
|
+
})
|
|
100
|
+
.options({
|
|
101
|
+
deprecated: {
|
|
102
|
+
alias: 'd',
|
|
103
|
+
describe: 'Fail on deprecated usage',
|
|
104
|
+
type: 'boolean',
|
|
105
|
+
default: false,
|
|
106
|
+
},
|
|
107
|
+
noStrictFragments: {
|
|
108
|
+
describe: 'Do not fail on duplicated fragment names',
|
|
109
|
+
type: 'boolean',
|
|
110
|
+
default: false,
|
|
111
|
+
},
|
|
112
|
+
maxDepth: {
|
|
113
|
+
describe: 'Fail on deep operations',
|
|
114
|
+
type: 'number',
|
|
115
|
+
},
|
|
116
|
+
apollo: {
|
|
117
|
+
describe: 'Support Apollo directives',
|
|
118
|
+
type: 'boolean',
|
|
119
|
+
default: false,
|
|
120
|
+
},
|
|
121
|
+
keepClientFields: {
|
|
122
|
+
describe: 'Keeps the fields with @client, but removes @client directive from them',
|
|
123
|
+
type: 'boolean',
|
|
124
|
+
default: false,
|
|
125
|
+
},
|
|
126
|
+
filter: {
|
|
127
|
+
describe: 'Show results only from a list of files (or file)',
|
|
128
|
+
array: true,
|
|
129
|
+
type: 'string',
|
|
130
|
+
},
|
|
131
|
+
ignore: {
|
|
132
|
+
describe: 'Ignore and do not load these files (supports glob)',
|
|
133
|
+
array: true,
|
|
134
|
+
type: 'string',
|
|
135
|
+
},
|
|
136
|
+
onlyErrors: {
|
|
137
|
+
describe: 'Show only errors',
|
|
138
|
+
type: 'boolean',
|
|
139
|
+
default: false,
|
|
140
|
+
},
|
|
141
|
+
relativePaths: {
|
|
142
|
+
describe: 'Show relative paths',
|
|
143
|
+
type: 'boolean',
|
|
144
|
+
default: false,
|
|
145
|
+
},
|
|
146
|
+
silent: {
|
|
147
|
+
describe: 'Do not print results',
|
|
148
|
+
type: 'boolean',
|
|
149
|
+
default: false,
|
|
150
|
+
},
|
|
151
|
+
output: {
|
|
152
|
+
describe: 'Output JSON file',
|
|
153
|
+
type: 'string',
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
handler(args) {
|
|
158
|
+
var _a;
|
|
159
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
const { headers, token } = commands.parseGlobalArgs(args);
|
|
161
|
+
const apollo = args.apollo || false;
|
|
162
|
+
const aws = args.aws || false;
|
|
163
|
+
const apolloFederation = args.federation || false;
|
|
164
|
+
const method = ((_a = args.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'POST';
|
|
165
|
+
const maxDepth = args.maxDepth || undefined;
|
|
166
|
+
const strictFragments = !args.noStrictFragments;
|
|
167
|
+
const keepClientFields = args.keepClientFields || false;
|
|
168
|
+
const failOnDeprecated = args.deprecated;
|
|
169
|
+
const output = args.output;
|
|
170
|
+
const silent = args.silent || false;
|
|
171
|
+
const relativePaths = args.relativePaths || false;
|
|
172
|
+
const onlyErrors = args.onlyErrors || false;
|
|
173
|
+
const ignore = args.ignore || [];
|
|
174
|
+
const schema = yield loaders.loadSchema(args.schema, {
|
|
175
|
+
headers,
|
|
176
|
+
token,
|
|
177
|
+
method,
|
|
178
|
+
}, apolloFederation, aws);
|
|
179
|
+
const documents = yield loaders.loadDocuments(args.documents, {
|
|
180
|
+
ignore,
|
|
181
|
+
});
|
|
182
|
+
return handler({
|
|
183
|
+
schema,
|
|
184
|
+
documents,
|
|
185
|
+
apollo,
|
|
186
|
+
maxDepth,
|
|
187
|
+
strictFragments,
|
|
188
|
+
keepClientFields,
|
|
189
|
+
failOnDeprecated,
|
|
190
|
+
filter: args.filter,
|
|
191
|
+
silent,
|
|
192
|
+
output,
|
|
193
|
+
relativePaths,
|
|
194
|
+
onlyErrors,
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
});
|
|
200
|
+
function countErrors(invalidDocuments) {
|
|
201
|
+
if (invalidDocuments.length) {
|
|
202
|
+
return invalidDocuments.filter((doc) => doc.errors && doc.errors.length)
|
|
203
|
+
.length;
|
|
204
|
+
}
|
|
205
|
+
return 0;
|
|
206
|
+
}
|
|
207
|
+
function countDeprecated(invalidDocuments) {
|
|
208
|
+
if (invalidDocuments.length) {
|
|
209
|
+
return invalidDocuments.filter((doc) => doc.deprecated && doc.deprecated.length).length;
|
|
210
|
+
}
|
|
211
|
+
return 0;
|
|
212
|
+
}
|
|
213
|
+
function printInvalidDocuments(invalidDocuments, listKey, isError = false, silent = false) {
|
|
214
|
+
if (silent) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
invalidDocuments.forEach((doc) => {
|
|
218
|
+
if (doc.errors.length) {
|
|
219
|
+
renderErrors(doc.source.name, doc[listKey], isError).forEach((line) => {
|
|
220
|
+
logger.Logger.log(line);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
function renderErrors(sourceName, errors, isError = false) {
|
|
226
|
+
const errorsAsString = errors
|
|
227
|
+
.map((e) => ` - ${logger.bolderize(e.message)}`)
|
|
228
|
+
.join('\n');
|
|
229
|
+
return [
|
|
230
|
+
isError ? logger.chalk.redBright('error') : logger.chalk.yellowBright('warn'),
|
|
231
|
+
`in ${sourceName}:\n\n`,
|
|
232
|
+
errorsAsString,
|
|
233
|
+
'\n\n',
|
|
234
|
+
];
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
exports.default = index;
|
|
238
|
+
exports.handler = handler;
|
package/index.mjs
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { __awaiter } from 'tslib';
|
|
2
|
+
import { createCommand, parseGlobalArgs } from '@graphql-inspector/commands';
|
|
3
|
+
import { Logger, chalk, bolderize } from '@graphql-inspector/logger';
|
|
4
|
+
import { validate } from '@graphql-inspector/core';
|
|
5
|
+
import { relative } from 'path';
|
|
6
|
+
import { writeFileSync } from 'fs';
|
|
7
|
+
import { Source, print } from 'graphql';
|
|
8
|
+
|
|
9
|
+
function handler({ schema, documents, strictFragments, maxDepth, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, }) {
|
|
10
|
+
let invalidDocuments = validate(schema, documents.map((doc) => new Source(print(doc.document), doc.location)), {
|
|
11
|
+
strictFragments,
|
|
12
|
+
maxDepth,
|
|
13
|
+
apollo,
|
|
14
|
+
keepClientFields,
|
|
15
|
+
});
|
|
16
|
+
if (!invalidDocuments.length) {
|
|
17
|
+
Logger.success('All documents are valid');
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
if (failOnDeprecated) {
|
|
21
|
+
invalidDocuments = moveDeprecatedToErrors(invalidDocuments);
|
|
22
|
+
}
|
|
23
|
+
if (relativePaths) {
|
|
24
|
+
invalidDocuments = useRelativePaths(invalidDocuments);
|
|
25
|
+
}
|
|
26
|
+
const errorsCount = countErrors(invalidDocuments);
|
|
27
|
+
const deprecated = countDeprecated(invalidDocuments);
|
|
28
|
+
const shouldFailProcess = errorsCount > 0;
|
|
29
|
+
if (errorsCount) {
|
|
30
|
+
if (!silent) {
|
|
31
|
+
Logger.log(`\nDetected ${errorsCount} invalid document${errorsCount > 1 ? 's' : ''}:\n`);
|
|
32
|
+
}
|
|
33
|
+
printInvalidDocuments(useFilter(invalidDocuments, filter), 'errors', true, silent);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
Logger.success('All documents are valid');
|
|
37
|
+
}
|
|
38
|
+
if (deprecated && !onlyErrors) {
|
|
39
|
+
if (!silent) {
|
|
40
|
+
Logger.info(`\nDetected ${deprecated} document${deprecated > 1 ? 's' : ''} with deprecated fields:\n`);
|
|
41
|
+
}
|
|
42
|
+
printInvalidDocuments(useFilter(invalidDocuments, filter), 'deprecated', false, silent);
|
|
43
|
+
}
|
|
44
|
+
if (output) {
|
|
45
|
+
writeFileSync(output, JSON.stringify({
|
|
46
|
+
status: !shouldFailProcess,
|
|
47
|
+
documents: useFilter(invalidDocuments, filter),
|
|
48
|
+
}, null, 2), {
|
|
49
|
+
encoding: 'utf-8',
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (shouldFailProcess) {
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function moveDeprecatedToErrors(docs) {
|
|
58
|
+
return docs.map((doc) => {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
return ({
|
|
61
|
+
source: doc.source,
|
|
62
|
+
errors: [...((_a = doc.errors) !== null && _a !== void 0 ? _a : []), ...((_b = doc.deprecated) !== null && _b !== void 0 ? _b : [])],
|
|
63
|
+
deprecated: [],
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function useRelativePaths(docs) {
|
|
68
|
+
return docs.map((doc) => {
|
|
69
|
+
doc.source.name = relative(process.cwd(), doc.source.name);
|
|
70
|
+
return doc;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function useFilter(docs, patterns) {
|
|
74
|
+
if (!patterns || !patterns.length) {
|
|
75
|
+
return docs;
|
|
76
|
+
}
|
|
77
|
+
return docs.filter((doc) => patterns.some((filepath) => doc.source.name.includes(filepath)));
|
|
78
|
+
}
|
|
79
|
+
const index = createCommand((api) => {
|
|
80
|
+
const { loaders } = api;
|
|
81
|
+
return {
|
|
82
|
+
command: 'validate <documents> <schema>',
|
|
83
|
+
describe: 'Validate Fragments and Operations',
|
|
84
|
+
builder(yargs) {
|
|
85
|
+
return yargs
|
|
86
|
+
.positional('schema', {
|
|
87
|
+
describe: 'Point to a schema',
|
|
88
|
+
type: 'string',
|
|
89
|
+
demandOption: true,
|
|
90
|
+
})
|
|
91
|
+
.positional('documents', {
|
|
92
|
+
describe: 'Point to documents',
|
|
93
|
+
type: 'string',
|
|
94
|
+
demandOption: true,
|
|
95
|
+
})
|
|
96
|
+
.options({
|
|
97
|
+
deprecated: {
|
|
98
|
+
alias: 'd',
|
|
99
|
+
describe: 'Fail on deprecated usage',
|
|
100
|
+
type: 'boolean',
|
|
101
|
+
default: false,
|
|
102
|
+
},
|
|
103
|
+
noStrictFragments: {
|
|
104
|
+
describe: 'Do not fail on duplicated fragment names',
|
|
105
|
+
type: 'boolean',
|
|
106
|
+
default: false,
|
|
107
|
+
},
|
|
108
|
+
maxDepth: {
|
|
109
|
+
describe: 'Fail on deep operations',
|
|
110
|
+
type: 'number',
|
|
111
|
+
},
|
|
112
|
+
apollo: {
|
|
113
|
+
describe: 'Support Apollo directives',
|
|
114
|
+
type: 'boolean',
|
|
115
|
+
default: false,
|
|
116
|
+
},
|
|
117
|
+
keepClientFields: {
|
|
118
|
+
describe: 'Keeps the fields with @client, but removes @client directive from them',
|
|
119
|
+
type: 'boolean',
|
|
120
|
+
default: false,
|
|
121
|
+
},
|
|
122
|
+
filter: {
|
|
123
|
+
describe: 'Show results only from a list of files (or file)',
|
|
124
|
+
array: true,
|
|
125
|
+
type: 'string',
|
|
126
|
+
},
|
|
127
|
+
ignore: {
|
|
128
|
+
describe: 'Ignore and do not load these files (supports glob)',
|
|
129
|
+
array: true,
|
|
130
|
+
type: 'string',
|
|
131
|
+
},
|
|
132
|
+
onlyErrors: {
|
|
133
|
+
describe: 'Show only errors',
|
|
134
|
+
type: 'boolean',
|
|
135
|
+
default: false,
|
|
136
|
+
},
|
|
137
|
+
relativePaths: {
|
|
138
|
+
describe: 'Show relative paths',
|
|
139
|
+
type: 'boolean',
|
|
140
|
+
default: false,
|
|
141
|
+
},
|
|
142
|
+
silent: {
|
|
143
|
+
describe: 'Do not print results',
|
|
144
|
+
type: 'boolean',
|
|
145
|
+
default: false,
|
|
146
|
+
},
|
|
147
|
+
output: {
|
|
148
|
+
describe: 'Output JSON file',
|
|
149
|
+
type: 'string',
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
handler(args) {
|
|
154
|
+
var _a;
|
|
155
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
+
const { headers, token } = parseGlobalArgs(args);
|
|
157
|
+
const apollo = args.apollo || false;
|
|
158
|
+
const aws = args.aws || false;
|
|
159
|
+
const apolloFederation = args.federation || false;
|
|
160
|
+
const method = ((_a = args.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'POST';
|
|
161
|
+
const maxDepth = args.maxDepth || undefined;
|
|
162
|
+
const strictFragments = !args.noStrictFragments;
|
|
163
|
+
const keepClientFields = args.keepClientFields || false;
|
|
164
|
+
const failOnDeprecated = args.deprecated;
|
|
165
|
+
const output = args.output;
|
|
166
|
+
const silent = args.silent || false;
|
|
167
|
+
const relativePaths = args.relativePaths || false;
|
|
168
|
+
const onlyErrors = args.onlyErrors || false;
|
|
169
|
+
const ignore = args.ignore || [];
|
|
170
|
+
const schema = yield loaders.loadSchema(args.schema, {
|
|
171
|
+
headers,
|
|
172
|
+
token,
|
|
173
|
+
method,
|
|
174
|
+
}, apolloFederation, aws);
|
|
175
|
+
const documents = yield loaders.loadDocuments(args.documents, {
|
|
176
|
+
ignore,
|
|
177
|
+
});
|
|
178
|
+
return handler({
|
|
179
|
+
schema,
|
|
180
|
+
documents,
|
|
181
|
+
apollo,
|
|
182
|
+
maxDepth,
|
|
183
|
+
strictFragments,
|
|
184
|
+
keepClientFields,
|
|
185
|
+
failOnDeprecated,
|
|
186
|
+
filter: args.filter,
|
|
187
|
+
silent,
|
|
188
|
+
output,
|
|
189
|
+
relativePaths,
|
|
190
|
+
onlyErrors,
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
});
|
|
196
|
+
function countErrors(invalidDocuments) {
|
|
197
|
+
if (invalidDocuments.length) {
|
|
198
|
+
return invalidDocuments.filter((doc) => doc.errors && doc.errors.length)
|
|
199
|
+
.length;
|
|
200
|
+
}
|
|
201
|
+
return 0;
|
|
202
|
+
}
|
|
203
|
+
function countDeprecated(invalidDocuments) {
|
|
204
|
+
if (invalidDocuments.length) {
|
|
205
|
+
return invalidDocuments.filter((doc) => doc.deprecated && doc.deprecated.length).length;
|
|
206
|
+
}
|
|
207
|
+
return 0;
|
|
208
|
+
}
|
|
209
|
+
function printInvalidDocuments(invalidDocuments, listKey, isError = false, silent = false) {
|
|
210
|
+
if (silent) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
invalidDocuments.forEach((doc) => {
|
|
214
|
+
if (doc.errors.length) {
|
|
215
|
+
renderErrors(doc.source.name, doc[listKey], isError).forEach((line) => {
|
|
216
|
+
Logger.log(line);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
function renderErrors(sourceName, errors, isError = false) {
|
|
222
|
+
const errorsAsString = errors
|
|
223
|
+
.map((e) => ` - ${bolderize(e.message)}`)
|
|
224
|
+
.join('\n');
|
|
225
|
+
return [
|
|
226
|
+
isError ? chalk.redBright('error') : chalk.yellowBright('warn'),
|
|
227
|
+
`in ${sourceName}:\n\n`,
|
|
228
|
+
errorsAsString,
|
|
229
|
+
'\n\n',
|
|
230
|
+
];
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export default index;
|
|
234
|
+
export { handler };
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@graphql-inspector/validate-command",
|
|
3
|
+
"version": "0.0.0-PLACEHOLDER",
|
|
4
|
+
"description": "Validate 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-PLACEHOLDER",
|
|
11
|
+
"@graphql-inspector/core": "0.0.0-PLACEHOLDER",
|
|
12
|
+
"@graphql-inspector/logger": "0.0.0-PLACEHOLDER",
|
|
13
|
+
"tslib": "^2.0.0"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "kamilkisiela/graphql-inspector",
|
|
18
|
+
"directory": "packages/commands/validate"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"graphql",
|
|
22
|
+
"graphql-inspector",
|
|
23
|
+
"graphql-inspector-command",
|
|
24
|
+
"tools"
|
|
25
|
+
],
|
|
26
|
+
"author": {
|
|
27
|
+
"name": "Kamil Kisiela",
|
|
28
|
+
"email": "kamil.kisiela@gmail.com",
|
|
29
|
+
"url": "https://github.com/kamilkisiela"
|
|
30
|
+
},
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"main": "index.js",
|
|
33
|
+
"module": "index.mjs",
|
|
34
|
+
"typings": "index.d.ts",
|
|
35
|
+
"typescript": {
|
|
36
|
+
"definition": "index.d.ts"
|
|
37
|
+
},
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"require": "./index.js",
|
|
41
|
+
"import": "./index.mjs"
|
|
42
|
+
},
|
|
43
|
+
"./*": {
|
|
44
|
+
"require": "./*.js",
|
|
45
|
+
"import": "./*.mjs"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|