@graphql-inspector/validate-command 0.0.0-canary.a883150 → 0.0.0-canary.ab31d7d

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