@graphql-inspector/validate-command 0.0.0-canary.35db993 → 0.0.0-canary.36985fe

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,34 @@
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, 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;
3
19
  declare const _default: CommandFactory<{}, {
4
20
  schema: string;
5
21
  documents: string;
6
- deprecated?: boolean | undefined;
22
+ deprecated: boolean;
7
23
  noStrictFragments: boolean;
8
- apollo?: boolean | undefined;
9
- keepClientFields?: boolean | undefined;
24
+ apollo: boolean;
25
+ keepClientFields: boolean;
10
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;
11
33
  } & GlobalArgs>;
12
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 CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@graphql-inspector/validate-command",
3
- "version": "0.0.0-canary.35db993",
3
+ "version": "0.0.0-canary.36985fe",
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"
8
8
  },
9
9
  "dependencies": {
10
- "@graphql-inspector/commands": "0.0.0-canary.35db993",
11
- "@graphql-inspector/core": "0.0.0-canary.35db993",
12
- "@graphql-inspector/logger": "0.0.0-canary.35db993",
10
+ "@graphql-inspector/commands": "0.0.0-canary.36985fe",
11
+ "@graphql-inspector/core": "0.0.0-canary.36985fe",
12
+ "@graphql-inspector/logger": "0.0.0-canary.36985fe",
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,142 +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, 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
- const { headers, token } = commands.parseGlobalArgs(args);
57
- const schema = yield loaders.loadSchema(args.schema, {
58
- headers,
59
- token,
60
- });
61
- const documents = yield loaders.loadDocuments(args.documents);
62
- const invalidDocuments = core.validate(schema, documents.map((doc) => new graphql.Source(graphql.print(doc.document), doc.location)), {
63
- strictFragments: !args.noStrictFragments,
64
- maxDepth: args.maxDepth || undefined,
65
- apollo: args.apollo || false,
66
- keepClientFields: args.keepClientFields || false,
67
- });
68
- if (!invalidDocuments.length) {
69
- logger.Logger.success('All documents are valid');
70
- }
71
- else {
72
- const errorsCount = countErrors(invalidDocuments);
73
- const deprecated = countDeprecated(invalidDocuments);
74
- if (errorsCount) {
75
- logger.Logger.log(`\nDetected ${errorsCount} invalid document${errorsCount > 1 ? 's' : ''}:\n`);
76
- invalidDocuments.forEach((doc) => {
77
- if (doc.errors.length) {
78
- renderInvalidDocument(doc).forEach((line) => {
79
- logger.Logger.log(line);
80
- });
81
- }
82
- });
83
- }
84
- else if (!args.deprecated) {
85
- logger.Logger.success('All documents are valid');
86
- }
87
- if (deprecated) {
88
- logger.Logger.info(`\nDetected ${deprecated} document${deprecated > 1 ? 's' : ''} with deprecated fields:\n`);
89
- invalidDocuments.forEach((doc) => {
90
- if (doc.deprecated.length) {
91
- renderDeprecatedUsageInDocument(doc, args.deprecated).forEach((line) => {
92
- logger.Logger.log(line);
93
- });
94
- }
95
- });
96
- }
97
- if (errorsCount || (deprecated && args.deprecated)) {
98
- process.exit(1);
99
- }
100
- }
101
- });
102
- },
103
- };
104
- });
105
- function countErrors(invalidDocuments) {
106
- if (invalidDocuments.length) {
107
- return invalidDocuments.filter((doc) => doc.errors && doc.errors.length)
108
- .length;
109
- }
110
- return 0;
111
- }
112
- function countDeprecated(invalidDocuments) {
113
- if (invalidDocuments.length) {
114
- return invalidDocuments.filter((doc) => doc.deprecated && doc.deprecated.length).length;
115
- }
116
- return 0;
117
- }
118
- function renderInvalidDocument(invalidDoc) {
119
- const errors = invalidDoc.errors
120
- .map((e) => ` - ${logger.bolderize(e.message)}`)
121
- .join('\n');
122
- return [
123
- logger.chalk.redBright('error'),
124
- `in ${invalidDoc.source.name}:\n\n`,
125
- errors,
126
- '\n\n',
127
- ];
128
- }
129
- function renderDeprecatedUsageInDocument(invalidDoc, isCritical = false) {
130
- const deprecated = invalidDoc.deprecated
131
- .map((e) => ` - ${logger.bolderize(e.message)}`)
132
- .join('\n');
133
- return [
134
- isCritical ? logger.chalk.redBright('error') : logger.chalk.yellowBright('warn'),
135
- `in ${invalidDoc.source.name}:\n\n`,
136
- deprecated,
137
- '\n\n',
138
- ];
139
- }
140
-
141
- module.exports = index;
142
- //# 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, 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 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,mBAAmB,EAAE,gBAAgB,GAAG,GAAG,GAAG,CAAC;AACpE,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,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C;AACN;;;;"}
package/index.esm.js DELETED
@@ -1,140 +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, 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
- const { headers, token } = parseGlobalArgs(args);
55
- const schema = yield loaders.loadSchema(args.schema, {
56
- headers,
57
- token,
58
- });
59
- const documents = yield loaders.loadDocuments(args.documents);
60
- const invalidDocuments = validate(schema, documents.map((doc) => new Source(print(doc.document), doc.location)), {
61
- strictFragments: !args.noStrictFragments,
62
- maxDepth: args.maxDepth || undefined,
63
- apollo: args.apollo || false,
64
- keepClientFields: args.keepClientFields || false,
65
- });
66
- if (!invalidDocuments.length) {
67
- Logger.success('All documents are valid');
68
- }
69
- else {
70
- const errorsCount = countErrors(invalidDocuments);
71
- const deprecated = countDeprecated(invalidDocuments);
72
- if (errorsCount) {
73
- Logger.log(`\nDetected ${errorsCount} invalid document${errorsCount > 1 ? 's' : ''}:\n`);
74
- invalidDocuments.forEach((doc) => {
75
- if (doc.errors.length) {
76
- renderInvalidDocument(doc).forEach((line) => {
77
- Logger.log(line);
78
- });
79
- }
80
- });
81
- }
82
- else if (!args.deprecated) {
83
- Logger.success('All documents are valid');
84
- }
85
- if (deprecated) {
86
- Logger.info(`\nDetected ${deprecated} document${deprecated > 1 ? 's' : ''} with deprecated fields:\n`);
87
- invalidDocuments.forEach((doc) => {
88
- if (doc.deprecated.length) {
89
- renderDeprecatedUsageInDocument(doc, args.deprecated).forEach((line) => {
90
- Logger.log(line);
91
- });
92
- }
93
- });
94
- }
95
- if (errorsCount || (deprecated && args.deprecated)) {
96
- process.exit(1);
97
- }
98
- }
99
- });
100
- },
101
- };
102
- });
103
- function countErrors(invalidDocuments) {
104
- if (invalidDocuments.length) {
105
- return invalidDocuments.filter((doc) => doc.errors && doc.errors.length)
106
- .length;
107
- }
108
- return 0;
109
- }
110
- function countDeprecated(invalidDocuments) {
111
- if (invalidDocuments.length) {
112
- return invalidDocuments.filter((doc) => doc.deprecated && doc.deprecated.length).length;
113
- }
114
- return 0;
115
- }
116
- function renderInvalidDocument(invalidDoc) {
117
- const errors = invalidDoc.errors
118
- .map((e) => ` - ${bolderize(e.message)}`)
119
- .join('\n');
120
- return [
121
- chalk.redBright('error'),
122
- `in ${invalidDoc.source.name}:\n\n`,
123
- errors,
124
- '\n\n',
125
- ];
126
- }
127
- function renderDeprecatedUsageInDocument(invalidDoc, isCritical = false) {
128
- const deprecated = invalidDoc.deprecated
129
- .map((e) => ` - ${bolderize(e.message)}`)
130
- .join('\n');
131
- return [
132
- isCritical ? chalk.redBright('error') : chalk.yellowBright('warn'),
133
- `in ${invalidDoc.source.name}:\n\n`,
134
- deprecated,
135
- '\n\n',
136
- ];
137
- }
138
-
139
- export default index;
140
- //# 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, 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 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,mBAAmB,EAAE,gBAAgB,GAAG,GAAG,GAAG,CAAC;A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