@graphql-inspector/validate-command 3.4.8-alpha-20230403113909-e09091f3 → 3.4.8

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.
@@ -1,17 +1,15 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const tslib = require('tslib');
6
- const fs = require('fs');
7
- const path = require('path');
8
- const graphql = require('graphql');
9
- const commands = require('@graphql-inspector/commands');
10
- const core = require('@graphql-inspector/core');
11
- const logger = require('@graphql-inspector/logger');
12
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = require("fs");
6
+ const path_1 = require("path");
7
+ const graphql_1 = require("graphql");
8
+ const commands_1 = require("@graphql-inspector/commands");
9
+ const core_1 = require("@graphql-inspector/core");
10
+ const logger_1 = require("@graphql-inspector/logger");
13
11
  function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCount, maxAliasCount, maxTokenCount, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, }) {
14
- let invalidDocuments = core.validate(schema, documents.map(doc => new graphql.Source(graphql.print(doc.document), doc.location)), {
12
+ let invalidDocuments = (0, core_1.validate)(schema, documents.map(doc => new graphql_1.Source((0, graphql_1.print)(doc.document), doc.location)), {
15
13
  strictFragments,
16
14
  maxDepth,
17
15
  maxAliasCount,
@@ -21,7 +19,7 @@ function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCou
21
19
  keepClientFields,
22
20
  });
23
21
  if (!invalidDocuments.length) {
24
- logger.Logger.success('All documents are valid');
22
+ logger_1.Logger.success('All documents are valid');
25
23
  return;
26
24
  }
27
25
  if (failOnDeprecated) {
@@ -35,21 +33,21 @@ function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCou
35
33
  const shouldFailProcess = errorsCount > 0;
36
34
  if (errorsCount) {
37
35
  if (!silent) {
38
- logger.Logger.log(`\nDetected ${errorsCount} invalid document${errorsCount > 1 ? 's' : ''}:\n`);
36
+ logger_1.Logger.log(`\nDetected ${errorsCount} invalid document${errorsCount > 1 ? 's' : ''}:\n`);
39
37
  }
40
38
  printInvalidDocuments(useFilter(invalidDocuments, filter), 'errors', true, silent);
41
39
  }
42
40
  else {
43
- logger.Logger.success('All documents are valid');
41
+ logger_1.Logger.success('All documents are valid');
44
42
  }
45
43
  if (deprecated && !onlyErrors) {
46
44
  if (!silent) {
47
- logger.Logger.info(`\nDetected ${deprecated} document${deprecated > 1 ? 's' : ''} with deprecated fields:\n`);
45
+ logger_1.Logger.info(`\nDetected ${deprecated} document${deprecated > 1 ? 's' : ''} with deprecated fields:\n`);
48
46
  }
49
47
  printInvalidDocuments(useFilter(invalidDocuments, filter), 'deprecated', false, silent);
50
48
  }
51
49
  if (output) {
52
- fs.writeFileSync(output, JSON.stringify({
50
+ (0, fs_1.writeFileSync)(output, JSON.stringify({
53
51
  status: !shouldFailProcess,
54
52
  documents: useFilter(invalidDocuments, filter),
55
53
  }, null, 2), 'utf8');
@@ -58,6 +56,7 @@ function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCou
58
56
  process.exit(1);
59
57
  }
60
58
  }
59
+ exports.handler = handler;
61
60
  function moveDeprecatedToErrors(docs) {
62
61
  return docs.map(doc => {
63
62
  var _a, _b;
@@ -70,7 +69,7 @@ function moveDeprecatedToErrors(docs) {
70
69
  }
71
70
  function useRelativePaths(docs) {
72
71
  return docs.map(doc => {
73
- doc.source.name = path.relative(process.cwd(), doc.source.name);
72
+ doc.source.name = (0, path_1.relative)(process.cwd(), doc.source.name);
74
73
  return doc;
75
74
  });
76
75
  }
@@ -80,7 +79,7 @@ function useFilter(docs, patterns) {
80
79
  }
81
80
  return docs.filter(doc => patterns.some(filepath => doc.source.name.includes(filepath)));
82
81
  }
83
- const index = commands.createCommand(api => {
82
+ exports.default = (0, commands_1.createCommand)(api => {
84
83
  const { loaders } = api;
85
84
  return {
86
85
  command: 'validate <documents> <schema>',
@@ -168,8 +167,8 @@ const index = commands.createCommand(api => {
168
167
  },
169
168
  handler(args) {
170
169
  var _a;
171
- return tslib.__awaiter(this, void 0, void 0, function* () {
172
- const { headers, token } = commands.parseGlobalArgs(args);
170
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
171
+ const { headers, token } = (0, commands_1.parseGlobalArgs)(args);
173
172
  const apollo = args.apollo || false;
174
173
  const aws = args.aws || false;
175
174
  const apolloFederation = args.federation || false;
@@ -234,20 +233,17 @@ function printInvalidDocuments(invalidDocuments, listKey, isError = false, silen
234
233
  invalidDocuments.forEach(doc => {
235
234
  if (doc.errors.length) {
236
235
  renderErrors(doc.source.name, doc[listKey], isError).forEach(line => {
237
- logger.Logger.log(line);
236
+ logger_1.Logger.log(line);
238
237
  });
239
238
  }
240
239
  });
241
240
  }
242
241
  function renderErrors(sourceName, errors, isError = false) {
243
- const errorsAsString = errors.map(e => ` - ${logger.bolderize(e.message)}`).join('\n');
242
+ const errorsAsString = errors.map(e => ` - ${(0, logger_1.bolderize)(e.message)}`).join('\n');
244
243
  return [
245
- isError ? logger.chalk.redBright('error') : logger.chalk.yellowBright('warn'),
244
+ isError ? logger_1.chalk.redBright('error') : logger_1.chalk.yellowBright('warn'),
246
245
  `in ${sourceName}:\n\n`,
247
246
  errorsAsString,
248
247
  '\n\n',
249
248
  ];
250
249
  }
251
-
252
- exports.default = index;
253
- exports.handler = handler;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -1,13 +1,12 @@
1
- import { __awaiter } from 'tslib';
1
+ import { __awaiter } from "tslib";
2
2
  import { writeFileSync } from 'fs';
3
3
  import { relative } from 'path';
4
- import { Source, print } from 'graphql';
5
- import { createCommand, parseGlobalArgs } from '@graphql-inspector/commands';
6
- import { validate } from '@graphql-inspector/core';
7
- import { Logger, chalk, bolderize } from '@graphql-inspector/logger';
8
-
9
- function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCount, maxAliasCount, maxTokenCount, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, }) {
10
- let invalidDocuments = validate(schema, documents.map(doc => new Source(print(doc.document), doc.location)), {
4
+ import { print, Source } from 'graphql';
5
+ import { createCommand, parseGlobalArgs, } from '@graphql-inspector/commands';
6
+ import { validate as validateDocuments } from '@graphql-inspector/core';
7
+ import { bolderize, chalk, Logger } from '@graphql-inspector/logger';
8
+ export function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCount, maxAliasCount, maxTokenCount, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, }) {
9
+ let invalidDocuments = validateDocuments(schema, documents.map(doc => new Source(print(doc.document), doc.location)), {
11
10
  strictFragments,
12
11
  maxDepth,
13
12
  maxAliasCount,
@@ -76,7 +75,7 @@ function useFilter(docs, patterns) {
76
75
  }
77
76
  return docs.filter(doc => patterns.some(filepath => doc.source.name.includes(filepath)));
78
77
  }
79
- const index = createCommand(api => {
78
+ export default createCommand(api => {
80
79
  const { loaders } = api;
81
80
  return {
82
81
  command: 'validate <documents> <schema>',
@@ -244,6 +243,3 @@ function renderErrors(sourceName, errors, isError = false) {
244
243
  '\n\n',
245
244
  ];
246
245
  }
247
-
248
- export default index;
249
- export { handler };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-inspector/validate-command",
3
- "version": "3.4.8-alpha-20230403113909-e09091f3",
3
+ "version": "3.4.8",
4
4
  "description": "Validate Documents in GraphQL Inspector",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -9,9 +9,9 @@
9
9
  "dependencies": {
10
10
  "@graphql-tools/utils": "^9.0.0",
11
11
  "tslib": "^2.0.0",
12
- "@graphql-inspector/commands": "3.4.4",
13
- "@graphql-inspector/core": "4.1.0-alpha-20230403113909-e09091f3",
14
- "@graphql-inspector/logger": "3.4.3"
12
+ "@graphql-inspector/commands": "3.4.5",
13
+ "@graphql-inspector/core": "4.0.3",
14
+ "@graphql-inspector/logger": "3.4.4"
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",
@@ -30,20 +30,41 @@
30
30
  "url": "https://github.com/kamilkisiela"
31
31
  },
32
32
  "license": "MIT",
33
- "main": "index.js",
34
- "module": "index.mjs",
35
- "typings": "index.d.ts",
33
+ "main": "cjs/index.js",
34
+ "module": "esm/index.js",
35
+ "typings": "typings/index.d.ts",
36
36
  "typescript": {
37
- "definition": "index.d.ts"
37
+ "definition": "typings/index.d.ts"
38
38
  },
39
+ "type": "module",
39
40
  "exports": {
40
41
  ".": {
41
- "require": "./index.js",
42
- "import": "./index.mjs"
42
+ "require": {
43
+ "types": "./typings/index.d.cts",
44
+ "default": "./cjs/index.js"
45
+ },
46
+ "import": {
47
+ "types": "./typings/index.d.ts",
48
+ "default": "./esm/index.js"
49
+ },
50
+ "default": {
51
+ "types": "./typings/index.d.ts",
52
+ "default": "./esm/index.js"
53
+ }
43
54
  },
44
55
  "./*": {
45
- "require": "./*.js",
46
- "import": "./*.mjs"
56
+ "require": {
57
+ "types": "./typings/*.d.cts",
58
+ "default": "./cjs/*.js"
59
+ },
60
+ "import": {
61
+ "types": "./typings/*.d.ts",
62
+ "default": "./esm/*.js"
63
+ },
64
+ "default": {
65
+ "types": "./typings/*.d.ts",
66
+ "default": "./esm/*.js"
67
+ }
47
68
  },
48
69
  "./package.json": "./package.json"
49
70
  }
@@ -0,0 +1,40 @@
1
+ import { GraphQLSchema } from 'graphql';
2
+ import { CommandFactory, GlobalArgs } from '@graphql-inspector/commands';
3
+ import { Source as DocumentSource } from '@graphql-tools/utils';
4
+ export { CommandFactory };
5
+ export declare function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCount, maxAliasCount, maxTokenCount, 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
+ maxTokenCount?: number;
16
+ filter?: string[];
17
+ onlyErrors?: boolean;
18
+ relativePaths?: boolean;
19
+ output?: string;
20
+ silent?: boolean;
21
+ }): void;
22
+ declare const _default: CommandFactory<{}, {
23
+ schema: string;
24
+ documents: string;
25
+ deprecated: boolean;
26
+ noStrictFragments: boolean;
27
+ apollo: boolean;
28
+ keepClientFields: boolean;
29
+ maxDepth?: number | undefined;
30
+ maxAliasCount?: number | undefined;
31
+ maxDirectiveCount?: number | undefined;
32
+ maxTokenCount?: number | undefined;
33
+ filter?: string[] | undefined;
34
+ onlyErrors?: boolean | undefined;
35
+ relativePaths?: boolean | undefined;
36
+ output?: string | undefined;
37
+ silent?: boolean | undefined;
38
+ ignore?: string[] | undefined;
39
+ } & GlobalArgs>;
40
+ export default _default;
File without changes