@graphql-inspector/diff-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,5 +1,13 @@
1
- import { GlobalArgs, CommandFactory } from '@graphql-inspector/commands';
1
+ import { CommandFactory, GlobalArgs } from '@graphql-inspector/commands';
2
+ import { GraphQLSchema } from 'graphql';
2
3
  export { CommandFactory };
4
+ export declare function handler(input: {
5
+ oldSchema: GraphQLSchema;
6
+ newSchema: GraphQLSchema;
7
+ onComplete?: string;
8
+ onUsage?: string;
9
+ rules?: Array<string | number>;
10
+ }): Promise<void>;
3
11
  declare const _default: CommandFactory<{}, {
4
12
  oldSchema: string;
5
13
  newSchema: string;
package/index.js ADDED
@@ -0,0 +1,198 @@
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 core = require('@graphql-inspector/core');
8
+ const logger = require('@graphql-inspector/logger');
9
+ const fs = require('fs');
10
+
11
+ function handler(input) {
12
+ return tslib.__awaiter(this, void 0, void 0, function* () {
13
+ const onComplete = input.onComplete
14
+ ? resolveCompletionHandler(input.onComplete)
15
+ : failOnBreakingChanges;
16
+ const rules = input.rules
17
+ ? input.rules
18
+ .filter(isString)
19
+ .map((name) => {
20
+ const rule = resolveRule(name);
21
+ if (!rule) {
22
+ throw new Error(`\Rule '${name}' does not exist!\n`);
23
+ }
24
+ return rule;
25
+ })
26
+ .filter((f) => f)
27
+ : [];
28
+ const changes = yield core.diff(input.oldSchema, input.newSchema, rules, {
29
+ checkUsage: input.onUsage ? resolveUsageHandler(input.onUsage) : undefined,
30
+ });
31
+ if (changes.length === 0) {
32
+ logger.Logger.success('No changes detected');
33
+ return;
34
+ }
35
+ logger.Logger.log(`\nDetected the following changes (${changes.length}) between schemas:\n`);
36
+ const breakingChanges = changes.filter((change) => change.criticality.level === core.CriticalityLevel.Breaking);
37
+ const dangerousChanges = changes.filter((change) => change.criticality.level === core.CriticalityLevel.Dangerous);
38
+ const nonBreakingChanges = changes.filter((change) => change.criticality.level === core.CriticalityLevel.NonBreaking);
39
+ if (breakingChanges.length) {
40
+ reportBreakingChanges(breakingChanges);
41
+ }
42
+ if (dangerousChanges.length) {
43
+ reportDangerousChanges(dangerousChanges);
44
+ }
45
+ if (nonBreakingChanges.length) {
46
+ reportNonBreakingChanges(nonBreakingChanges);
47
+ }
48
+ onComplete({ breakingChanges, dangerousChanges, nonBreakingChanges });
49
+ });
50
+ }
51
+ const index = commands.createCommand((api) => {
52
+ const { loaders } = api;
53
+ return {
54
+ command: 'diff <oldSchema> <newSchema>',
55
+ describe: 'Compare two GraphQL Schemas',
56
+ builder(yargs) {
57
+ return yargs
58
+ .positional('oldSchema', {
59
+ describe: 'Point to an old schema',
60
+ type: 'string',
61
+ demandOption: true,
62
+ })
63
+ .positional('newSchema', {
64
+ describe: 'Point to a new schema',
65
+ type: 'string',
66
+ demandOption: true,
67
+ })
68
+ .options({
69
+ rule: {
70
+ describe: 'Add rules',
71
+ array: true,
72
+ },
73
+ onComplete: {
74
+ describe: 'Handle Completion',
75
+ type: 'string',
76
+ },
77
+ onUsage: {
78
+ describe: 'Checks usage of schema',
79
+ type: 'string',
80
+ },
81
+ });
82
+ },
83
+ handler(args) {
84
+ var _a;
85
+ return tslib.__awaiter(this, void 0, void 0, function* () {
86
+ try {
87
+ const oldSchemaPointer = args.oldSchema;
88
+ const newSchemaPointer = args.newSchema;
89
+ const apolloFederation = args.federation || false;
90
+ const aws = args.aws || false;
91
+ const method = ((_a = args.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'POST';
92
+ const { headers, leftHeaders, rightHeaders, token } = commands.parseGlobalArgs(args);
93
+ const oldSchemaHeaders = Object.assign(Object.assign({}, (headers !== null && headers !== void 0 ? headers : {})), (leftHeaders !== null && leftHeaders !== void 0 ? leftHeaders : {}));
94
+ const newSchemaHeaders = Object.assign(Object.assign({}, (headers !== null && headers !== void 0 ? headers : {})), (rightHeaders !== null && rightHeaders !== void 0 ? rightHeaders : {}));
95
+ const oldSchema = yield loaders.loadSchema(oldSchemaPointer, {
96
+ oldSchemaHeaders,
97
+ token,
98
+ method,
99
+ }, apolloFederation, aws);
100
+ const newSchema = yield loaders.loadSchema(newSchemaPointer, {
101
+ newSchemaHeaders,
102
+ token,
103
+ method,
104
+ }, apolloFederation, aws);
105
+ yield handler({
106
+ oldSchema,
107
+ newSchema,
108
+ rules: args.rule,
109
+ onComplete: args.onComplete,
110
+ });
111
+ }
112
+ catch (error) {
113
+ logger.Logger.error(error);
114
+ throw error;
115
+ }
116
+ });
117
+ },
118
+ };
119
+ });
120
+ function sortChanges(changes) {
121
+ return changes.slice().sort((a, b) => {
122
+ const aPath = a.path || '';
123
+ const bPath = b.path || '';
124
+ if (aPath > bPath) {
125
+ return 1;
126
+ }
127
+ if (bPath > aPath) {
128
+ return -1;
129
+ }
130
+ return 0;
131
+ });
132
+ }
133
+ function reportBreakingChanges(changes) {
134
+ const label = logger.symbols.error;
135
+ const sorted = sortChanges(changes);
136
+ sorted.forEach((change) => {
137
+ logger.Logger.log(`${label} ${logger.bolderize(change.message)}`);
138
+ });
139
+ }
140
+ function reportDangerousChanges(changes) {
141
+ const label = logger.symbols.warning;
142
+ const sorted = sortChanges(changes);
143
+ sorted.forEach((change) => {
144
+ logger.Logger.log(`${label} ${logger.bolderize(change.message)}`);
145
+ });
146
+ }
147
+ function reportNonBreakingChanges(changes) {
148
+ const label = logger.symbols.success;
149
+ const sorted = sortChanges(changes);
150
+ sorted.forEach((change) => {
151
+ logger.Logger.log(`${label} ${logger.bolderize(change.message)}`);
152
+ });
153
+ }
154
+ function resolveRule(name) {
155
+ const filepath = commands.ensureAbsolute(name);
156
+ if (fs.existsSync(filepath)) {
157
+ return require(filepath);
158
+ }
159
+ return core.DiffRule[name];
160
+ }
161
+ function resolveCompletionHandler(name) {
162
+ const filepath = commands.ensureAbsolute(name);
163
+ try {
164
+ require.resolve(filepath);
165
+ }
166
+ catch (error) {
167
+ throw new Error(`CompletionHandler '${name}' does not exist!`);
168
+ }
169
+ const mod = require(filepath);
170
+ return (mod === null || mod === void 0 ? void 0 : mod.default) || mod;
171
+ }
172
+ function resolveUsageHandler(name) {
173
+ const filepath = commands.ensureAbsolute(name);
174
+ try {
175
+ require.resolve(filepath);
176
+ }
177
+ catch (error) {
178
+ throw new Error(`UsageHandler '${name}' does not exist!`);
179
+ }
180
+ const mod = require(filepath);
181
+ return (mod === null || mod === void 0 ? void 0 : mod.default) || mod;
182
+ }
183
+ function failOnBreakingChanges({ breakingChanges }) {
184
+ const breakingCount = breakingChanges.length;
185
+ if (breakingCount) {
186
+ logger.Logger.error(`Detected ${breakingCount} breaking change${breakingCount > 1 ? 's' : ''}`);
187
+ process.exit(1);
188
+ }
189
+ else {
190
+ logger.Logger.success('No breaking changes detected');
191
+ }
192
+ }
193
+ function isString(val) {
194
+ return typeof val === 'string';
195
+ }
196
+
197
+ exports.default = index;
198
+ exports.handler = handler;
package/index.mjs ADDED
@@ -0,0 +1,194 @@
1
+ import { __awaiter } from 'tslib';
2
+ import { createCommand, parseGlobalArgs, ensureAbsolute } from '@graphql-inspector/commands';
3
+ import { diff, CriticalityLevel, DiffRule } from '@graphql-inspector/core';
4
+ import { Logger, symbols, bolderize } from '@graphql-inspector/logger';
5
+ import { existsSync } from 'fs';
6
+
7
+ function handler(input) {
8
+ return __awaiter(this, void 0, void 0, function* () {
9
+ const onComplete = input.onComplete
10
+ ? resolveCompletionHandler(input.onComplete)
11
+ : failOnBreakingChanges;
12
+ const rules = input.rules
13
+ ? input.rules
14
+ .filter(isString)
15
+ .map((name) => {
16
+ const rule = resolveRule(name);
17
+ if (!rule) {
18
+ throw new Error(`\Rule '${name}' does not exist!\n`);
19
+ }
20
+ return rule;
21
+ })
22
+ .filter((f) => f)
23
+ : [];
24
+ const changes = yield diff(input.oldSchema, input.newSchema, rules, {
25
+ checkUsage: input.onUsage ? resolveUsageHandler(input.onUsage) : undefined,
26
+ });
27
+ if (changes.length === 0) {
28
+ Logger.success('No changes detected');
29
+ return;
30
+ }
31
+ Logger.log(`\nDetected the following changes (${changes.length}) between schemas:\n`);
32
+ const breakingChanges = changes.filter((change) => change.criticality.level === CriticalityLevel.Breaking);
33
+ const dangerousChanges = changes.filter((change) => change.criticality.level === CriticalityLevel.Dangerous);
34
+ const nonBreakingChanges = changes.filter((change) => change.criticality.level === CriticalityLevel.NonBreaking);
35
+ if (breakingChanges.length) {
36
+ reportBreakingChanges(breakingChanges);
37
+ }
38
+ if (dangerousChanges.length) {
39
+ reportDangerousChanges(dangerousChanges);
40
+ }
41
+ if (nonBreakingChanges.length) {
42
+ reportNonBreakingChanges(nonBreakingChanges);
43
+ }
44
+ onComplete({ breakingChanges, dangerousChanges, nonBreakingChanges });
45
+ });
46
+ }
47
+ const index = createCommand((api) => {
48
+ const { loaders } = api;
49
+ return {
50
+ command: 'diff <oldSchema> <newSchema>',
51
+ describe: 'Compare two GraphQL Schemas',
52
+ builder(yargs) {
53
+ return yargs
54
+ .positional('oldSchema', {
55
+ describe: 'Point to an old schema',
56
+ type: 'string',
57
+ demandOption: true,
58
+ })
59
+ .positional('newSchema', {
60
+ describe: 'Point to a new schema',
61
+ type: 'string',
62
+ demandOption: true,
63
+ })
64
+ .options({
65
+ rule: {
66
+ describe: 'Add rules',
67
+ array: true,
68
+ },
69
+ onComplete: {
70
+ describe: 'Handle Completion',
71
+ type: 'string',
72
+ },
73
+ onUsage: {
74
+ describe: 'Checks usage of schema',
75
+ type: 'string',
76
+ },
77
+ });
78
+ },
79
+ handler(args) {
80
+ var _a;
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ try {
83
+ const oldSchemaPointer = args.oldSchema;
84
+ const newSchemaPointer = args.newSchema;
85
+ const apolloFederation = args.federation || false;
86
+ const aws = args.aws || false;
87
+ const method = ((_a = args.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'POST';
88
+ const { headers, leftHeaders, rightHeaders, token } = parseGlobalArgs(args);
89
+ const oldSchemaHeaders = Object.assign(Object.assign({}, (headers !== null && headers !== void 0 ? headers : {})), (leftHeaders !== null && leftHeaders !== void 0 ? leftHeaders : {}));
90
+ const newSchemaHeaders = Object.assign(Object.assign({}, (headers !== null && headers !== void 0 ? headers : {})), (rightHeaders !== null && rightHeaders !== void 0 ? rightHeaders : {}));
91
+ const oldSchema = yield loaders.loadSchema(oldSchemaPointer, {
92
+ oldSchemaHeaders,
93
+ token,
94
+ method,
95
+ }, apolloFederation, aws);
96
+ const newSchema = yield loaders.loadSchema(newSchemaPointer, {
97
+ newSchemaHeaders,
98
+ token,
99
+ method,
100
+ }, apolloFederation, aws);
101
+ yield handler({
102
+ oldSchema,
103
+ newSchema,
104
+ rules: args.rule,
105
+ onComplete: args.onComplete,
106
+ });
107
+ }
108
+ catch (error) {
109
+ Logger.error(error);
110
+ throw error;
111
+ }
112
+ });
113
+ },
114
+ };
115
+ });
116
+ function sortChanges(changes) {
117
+ return changes.slice().sort((a, b) => {
118
+ const aPath = a.path || '';
119
+ const bPath = b.path || '';
120
+ if (aPath > bPath) {
121
+ return 1;
122
+ }
123
+ if (bPath > aPath) {
124
+ return -1;
125
+ }
126
+ return 0;
127
+ });
128
+ }
129
+ function reportBreakingChanges(changes) {
130
+ const label = symbols.error;
131
+ const sorted = sortChanges(changes);
132
+ sorted.forEach((change) => {
133
+ Logger.log(`${label} ${bolderize(change.message)}`);
134
+ });
135
+ }
136
+ function reportDangerousChanges(changes) {
137
+ const label = symbols.warning;
138
+ const sorted = sortChanges(changes);
139
+ sorted.forEach((change) => {
140
+ Logger.log(`${label} ${bolderize(change.message)}`);
141
+ });
142
+ }
143
+ function reportNonBreakingChanges(changes) {
144
+ const label = symbols.success;
145
+ const sorted = sortChanges(changes);
146
+ sorted.forEach((change) => {
147
+ Logger.log(`${label} ${bolderize(change.message)}`);
148
+ });
149
+ }
150
+ function resolveRule(name) {
151
+ const filepath = ensureAbsolute(name);
152
+ if (existsSync(filepath)) {
153
+ return require(filepath);
154
+ }
155
+ return DiffRule[name];
156
+ }
157
+ function resolveCompletionHandler(name) {
158
+ const filepath = ensureAbsolute(name);
159
+ try {
160
+ require.resolve(filepath);
161
+ }
162
+ catch (error) {
163
+ throw new Error(`CompletionHandler '${name}' does not exist!`);
164
+ }
165
+ const mod = require(filepath);
166
+ return (mod === null || mod === void 0 ? void 0 : mod.default) || mod;
167
+ }
168
+ function resolveUsageHandler(name) {
169
+ const filepath = ensureAbsolute(name);
170
+ try {
171
+ require.resolve(filepath);
172
+ }
173
+ catch (error) {
174
+ throw new Error(`UsageHandler '${name}' does not exist!`);
175
+ }
176
+ const mod = require(filepath);
177
+ return (mod === null || mod === void 0 ? void 0 : mod.default) || mod;
178
+ }
179
+ function failOnBreakingChanges({ breakingChanges }) {
180
+ const breakingCount = breakingChanges.length;
181
+ if (breakingCount) {
182
+ Logger.error(`Detected ${breakingCount} breaking change${breakingCount > 1 ? 's' : ''}`);
183
+ process.exit(1);
184
+ }
185
+ else {
186
+ Logger.success('No breaking changes detected');
187
+ }
188
+ }
189
+ function isString(val) {
190
+ return typeof val === 'string';
191
+ }
192
+
193
+ export default index;
194
+ export { handler };
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@graphql-inspector/diff-command",
3
- "version": "0.0.0-canary.35db993",
3
+ "version": "0.0.0-canary.36985fe",
4
4
  "description": "Compare GraphQL Schemas",
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,161 +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 fs = require('fs');
8
-
9
- const index = commands.createCommand((api) => {
10
- const { loaders, interceptPositional, interceptOptions, } = api;
11
- return {
12
- command: 'diff <oldSchema> <newSchema>',
13
- describe: 'Compare two GraphQL Schemas',
14
- builder(yargs) {
15
- return yargs
16
- .positional('oldSchema', interceptPositional('oldSchema', {
17
- describe: 'Point to an old schema',
18
- type: 'string',
19
- demandOption: true,
20
- }))
21
- .positional('newSchema', interceptPositional('newSchema', {
22
- describe: 'Point to a new schema',
23
- type: 'string',
24
- demandOption: true,
25
- }))
26
- .options(interceptOptions({
27
- rule: {
28
- describe: 'Add rules',
29
- array: true,
30
- },
31
- onComplete: {
32
- describe: 'Handle Completion',
33
- type: 'string',
34
- },
35
- }));
36
- },
37
- handler(args) {
38
- return tslib.__awaiter(this, void 0, void 0, function* () {
39
- try {
40
- const oldSchemaPointer = args.oldSchema;
41
- const newSchemaPointer = args.newSchema;
42
- const { headers, token } = commands.parseGlobalArgs(args);
43
- const oldSchema = yield loaders.loadSchema(oldSchemaPointer, {
44
- headers,
45
- token,
46
- });
47
- const newSchema = yield loaders.loadSchema(newSchemaPointer, {
48
- headers,
49
- token,
50
- });
51
- const onComplete = args.onComplete
52
- ? resolveCompletionHandler(args.onComplete)
53
- : failOnBreakingChanges;
54
- const rules = args.rule
55
- ? args.rule
56
- .filter(isString)
57
- .map((name) => {
58
- const rule = resolveRule(name);
59
- if (!rule) {
60
- throw new Error(`\Rule '${name}' does not exist!\n`);
61
- }
62
- return rule;
63
- })
64
- .filter((f) => f)
65
- : [];
66
- const changes = core.diff(oldSchema, newSchema, rules);
67
- if (changes.length === 0) {
68
- logger.Logger.success('No changes detected');
69
- return;
70
- }
71
- logger.Logger.log(`\nDetected the following changes (${changes.length}) between schemas:\n`);
72
- const breakingChanges = changes.filter((change) => change.criticality.level === core.CriticalityLevel.Breaking);
73
- const dangerousChanges = changes.filter((change) => change.criticality.level === core.CriticalityLevel.Dangerous);
74
- const nonBreakingChanges = changes.filter((change) => change.criticality.level === core.CriticalityLevel.NonBreaking);
75
- if (breakingChanges.length) {
76
- reportBreakingChanges(breakingChanges);
77
- }
78
- if (dangerousChanges.length) {
79
- reportDangerousChanges(dangerousChanges);
80
- }
81
- if (nonBreakingChanges.length) {
82
- reportNonBreakingChanges(nonBreakingChanges);
83
- }
84
- onComplete({ breakingChanges, dangerousChanges, nonBreakingChanges });
85
- }
86
- catch (error) {
87
- logger.Logger.error(error);
88
- throw error;
89
- }
90
- });
91
- },
92
- };
93
- });
94
- function sortChanges(changes) {
95
- return changes.slice().sort((a, b) => {
96
- const aPath = a.path || '';
97
- const bPath = b.path || '';
98
- if (aPath > bPath) {
99
- return 1;
100
- }
101
- if (bPath > aPath) {
102
- return -1;
103
- }
104
- return 0;
105
- });
106
- }
107
- function reportBreakingChanges(changes) {
108
- const label = logger.symbols.error;
109
- const sorted = sortChanges(changes);
110
- sorted.forEach((change) => {
111
- logger.Logger.log(`${label} ${logger.bolderize(change.message)}`);
112
- });
113
- }
114
- function reportDangerousChanges(changes) {
115
- const label = logger.symbols.warning;
116
- const sorted = sortChanges(changes);
117
- sorted.forEach((change) => {
118
- logger.Logger.log(`${label} ${logger.bolderize(change.message)}`);
119
- });
120
- }
121
- function reportNonBreakingChanges(changes) {
122
- const label = logger.symbols.success;
123
- const sorted = sortChanges(changes);
124
- sorted.forEach((change) => {
125
- logger.Logger.log(`${label} ${logger.bolderize(change.message)}`);
126
- });
127
- }
128
- function resolveRule(name) {
129
- const filepath = commands.ensureAbsolute(name);
130
- if (fs.existsSync(filepath)) {
131
- return require(filepath);
132
- }
133
- return core.DiffRule[name];
134
- }
135
- function resolveCompletionHandler(name) {
136
- const filepath = commands.ensureAbsolute(name);
137
- try {
138
- require.resolve(filepath);
139
- }
140
- catch (error) {
141
- throw new Error(`CompletionHandler '${name}' does not exist!`);
142
- }
143
- const mod = require(filepath);
144
- return (mod === null || mod === void 0 ? void 0 : mod.default) || mod;
145
- }
146
- function failOnBreakingChanges({ breakingChanges }) {
147
- const breakingCount = breakingChanges.length;
148
- if (breakingCount) {
149
- logger.Logger.error(`Detected ${breakingCount} breaking change${breakingCount > 1 ? 's' : ''}`);
150
- process.exit(1);
151
- }
152
- else {
153
- logger.Logger.success('No breaking changes detected');
154
- }
155
- }
156
- function isString(val) {
157
- return typeof val === 'string';
158
- }
159
-
160
- module.exports = index;
161
- //# sourceMappingURL=index.cjs.js.map
package/index.cjs.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../../dist/commands/diff/src/index.js"],"sourcesContent":["import { __awaiter } from \"tslib\";\nimport { createCommand, ensureAbsolute, parseGlobalArgs, } from '@graphql-inspector/commands';\nimport { symbols, Logger, bolderize } from '@graphql-inspector/logger';\nimport { diff as diffSchema, CriticalityLevel, DiffRule, } from '@graphql-inspector/core';\nimport { existsSync } from 'fs';\nexport default createCommand((api) => {\n const { loaders, interceptPositional, interceptOptions, } = api;\n return {\n command: 'diff <oldSchema> <newSchema>',\n describe: 'Compare two GraphQL Schemas',\n builder(yargs) {\n return yargs\n .positional('oldSchema', interceptPositional('oldSchema', {\n describe: 'Point to an old schema',\n type: 'string',\n demandOption: true,\n }))\n .positional('newSchema', interceptPositional('newSchema', {\n describe: 'Point to a new schema',\n type: 'string',\n demandOption: true,\n }))\n .options(interceptOptions({\n rule: {\n describe: 'Add rules',\n array: true,\n },\n onComplete: {\n describe: 'Handle Completion',\n type: 'string',\n },\n }));\n },\n handler(args) {\n return __awaiter(this, void 0, void 0, function* () {\n try {\n const oldSchemaPointer = args.oldSchema;\n const newSchemaPointer = args.newSchema;\n const { headers, token } = parseGlobalArgs(args);\n const oldSchema = yield loaders.loadSchema(oldSchemaPointer, {\n headers,\n token,\n });\n const newSchema = yield loaders.loadSchema(newSchemaPointer, {\n headers,\n token,\n });\n const onComplete = args.onComplete\n ? resolveCompletionHandler(args.onComplete)\n : failOnBreakingChanges;\n const rules = args.rule\n ? args.rule\n .filter(isString)\n .map((name) => {\n const rule = resolveRule(name);\n if (!rule) {\n throw new Error(`\\Rule '${name}' does not exist!\\n`);\n }\n return rule;\n })\n .filter((f) => f)\n : [];\n const changes = diffSchema(oldSchema, newSchema, rules);\n if (changes.length === 0) {\n Logger.success('No changes detected');\n return;\n }\n Logger.log(`\\nDetected the following changes (${changes.length}) between schemas:\\n`);\n const breakingChanges = changes.filter((change) => change.criticality.level === CriticalityLevel.Breaking);\n const dangerousChanges = changes.filter((change) => change.criticality.level === CriticalityLevel.Dangerous);\n const nonBreakingChanges = changes.filter((change) => change.criticality.level === CriticalityLevel.NonBreaking);\n if (breakingChanges.length) {\n reportBreakingChanges(breakingChanges);\n }\n if (dangerousChanges.length) {\n reportDangerousChanges(dangerousChanges);\n }\n if (nonBreakingChanges.length) {\n reportNonBreakingChanges(nonBreakingChanges);\n }\n onComplete({ breakingChanges, dangerousChanges, nonBreakingChanges });\n }\n catch (error) {\n Logger.error(error);\n throw error;\n }\n });\n },\n };\n});\nfunction sortChanges(changes) {\n return changes.slice().sort((a, b) => {\n const aPath = a.path || '';\n const bPath = b.path || '';\n if (aPath > bPath) {\n return 1;\n }\n if (bPath > aPath) {\n return -1;\n }\n return 0;\n });\n}\nfunction reportBreakingChanges(changes) {\n const label = symbols.error;\n const sorted = sortChanges(changes);\n sorted.forEach((change) => {\n Logger.log(`${label} ${bolderize(change.message)}`);\n });\n}\nfunction reportDangerousChanges(changes) {\n const label = symbols.warning;\n const sorted = sortChanges(changes);\n sorted.forEach((change) => {\n Logger.log(`${label} ${bolderize(change.message)}`);\n });\n}\nfunction reportNonBreakingChanges(changes) {\n const label = symbols.success;\n const sorted = sortChanges(changes);\n sorted.forEach((change) => {\n Logger.log(`${label} ${bolderize(change.message)}`);\n });\n}\nfunction resolveRule(name) {\n const filepath = ensureAbsolute(name);\n if (existsSync(filepath)) {\n return require(filepath);\n }\n return DiffRule[name];\n}\nfunction resolveCompletionHandler(name) {\n const filepath = ensureAbsolute(name);\n try {\n require.resolve(filepath);\n }\n catch (error) {\n throw new Error(`CompletionHandler '${name}' does not exist!`);\n }\n const mod = require(filepath);\n return (mod === null || mod === void 0 ? void 0 : mod.default) || mod;\n}\nfunction failOnBreakingChanges({ breakingChanges }) {\n const breakingCount = breakingChanges.length;\n if (breakingCount) {\n Logger.error(`Detected ${breakingCount} breaking change${breakingCount > 1 ? 's' : ''}`);\n process.exit(1);\n }\n else {\n Logger.success('No breaking changes detected');\n }\n}\nfunction isString(val) {\n return typeof val === 'string';\n}\n//# sourceMappingURL=index.js.map"],"names":["createCommand","__awaiter","parseGlobalArgs","diffSchema","Logger","CriticalityLevel","symbols","bolderize","ensureAbsolute","existsSync","DiffRule"],"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,8BAA8B;AAC/C,QAAQ,QAAQ,EAAE,6BAA6B;AAC/C,QAAQ,OAA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AC,GAAG,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;AACjG,QAAQ,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACxB,KAAK;AACL,SAAS;AACT,QAAQA,aAAM,CAAC,OAAO,CAAC,8BAA8B,CAAC,CAAC;AACvD,KAAK;AACL,CAAC;AACD,SAAS,QAAQ,CAAC,GAAG,EAAE;AACvB,IAAI,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC;AACnC;;;;"}
package/index.esm.js DELETED
@@ -1,159 +0,0 @@
1
- import { __awaiter } from 'tslib';
2
- import { createCommand, parseGlobalArgs, ensureAbsolute } from '@graphql-inspector/commands';
3
- import { Logger, symbols, bolderize } from '@graphql-inspector/logger';
4
- import { diff, CriticalityLevel, DiffRule } from '@graphql-inspector/core';
5
- import { existsSync } from 'fs';
6
-
7
- const index = createCommand((api) => {
8
- const { loaders, interceptPositional, interceptOptions, } = api;
9
- return {
10
- command: 'diff <oldSchema> <newSchema>',
11
- describe: 'Compare two GraphQL Schemas',
12
- builder(yargs) {
13
- return yargs
14
- .positional('oldSchema', interceptPositional('oldSchema', {
15
- describe: 'Point to an old schema',
16
- type: 'string',
17
- demandOption: true,
18
- }))
19
- .positional('newSchema', interceptPositional('newSchema', {
20
- describe: 'Point to a new schema',
21
- type: 'string',
22
- demandOption: true,
23
- }))
24
- .options(interceptOptions({
25
- rule: {
26
- describe: 'Add rules',
27
- array: true,
28
- },
29
- onComplete: {
30
- describe: 'Handle Completion',
31
- type: 'string',
32
- },
33
- }));
34
- },
35
- handler(args) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- try {
38
- const oldSchemaPointer = args.oldSchema;
39
- const newSchemaPointer = args.newSchema;
40
- const { headers, token } = parseGlobalArgs(args);
41
- const oldSchema = yield loaders.loadSchema(oldSchemaPointer, {
42
- headers,
43
- token,
44
- });
45
- const newSchema = yield loaders.loadSchema(newSchemaPointer, {
46
- headers,
47
- token,
48
- });
49
- const onComplete = args.onComplete
50
- ? resolveCompletionHandler(args.onComplete)
51
- : failOnBreakingChanges;
52
- const rules = args.rule
53
- ? args.rule
54
- .filter(isString)
55
- .map((name) => {
56
- const rule = resolveRule(name);
57
- if (!rule) {
58
- throw new Error(`\Rule '${name}' does not exist!\n`);
59
- }
60
- return rule;
61
- })
62
- .filter((f) => f)
63
- : [];
64
- const changes = diff(oldSchema, newSchema, rules);
65
- if (changes.length === 0) {
66
- Logger.success('No changes detected');
67
- return;
68
- }
69
- Logger.log(`\nDetected the following changes (${changes.length}) between schemas:\n`);
70
- const breakingChanges = changes.filter((change) => change.criticality.level === CriticalityLevel.Breaking);
71
- const dangerousChanges = changes.filter((change) => change.criticality.level === CriticalityLevel.Dangerous);
72
- const nonBreakingChanges = changes.filter((change) => change.criticality.level === CriticalityLevel.NonBreaking);
73
- if (breakingChanges.length) {
74
- reportBreakingChanges(breakingChanges);
75
- }
76
- if (dangerousChanges.length) {
77
- reportDangerousChanges(dangerousChanges);
78
- }
79
- if (nonBreakingChanges.length) {
80
- reportNonBreakingChanges(nonBreakingChanges);
81
- }
82
- onComplete({ breakingChanges, dangerousChanges, nonBreakingChanges });
83
- }
84
- catch (error) {
85
- Logger.error(error);
86
- throw error;
87
- }
88
- });
89
- },
90
- };
91
- });
92
- function sortChanges(changes) {
93
- return changes.slice().sort((a, b) => {
94
- const aPath = a.path || '';
95
- const bPath = b.path || '';
96
- if (aPath > bPath) {
97
- return 1;
98
- }
99
- if (bPath > aPath) {
100
- return -1;
101
- }
102
- return 0;
103
- });
104
- }
105
- function reportBreakingChanges(changes) {
106
- const label = symbols.error;
107
- const sorted = sortChanges(changes);
108
- sorted.forEach((change) => {
109
- Logger.log(`${label} ${bolderize(change.message)}`);
110
- });
111
- }
112
- function reportDangerousChanges(changes) {
113
- const label = symbols.warning;
114
- const sorted = sortChanges(changes);
115
- sorted.forEach((change) => {
116
- Logger.log(`${label} ${bolderize(change.message)}`);
117
- });
118
- }
119
- function reportNonBreakingChanges(changes) {
120
- const label = symbols.success;
121
- const sorted = sortChanges(changes);
122
- sorted.forEach((change) => {
123
- Logger.log(`${label} ${bolderize(change.message)}`);
124
- });
125
- }
126
- function resolveRule(name) {
127
- const filepath = ensureAbsolute(name);
128
- if (existsSync(filepath)) {
129
- return require(filepath);
130
- }
131
- return DiffRule[name];
132
- }
133
- function resolveCompletionHandler(name) {
134
- const filepath = ensureAbsolute(name);
135
- try {
136
- require.resolve(filepath);
137
- }
138
- catch (error) {
139
- throw new Error(`CompletionHandler '${name}' does not exist!`);
140
- }
141
- const mod = require(filepath);
142
- return (mod === null || mod === void 0 ? void 0 : mod.default) || mod;
143
- }
144
- function failOnBreakingChanges({ breakingChanges }) {
145
- const breakingCount = breakingChanges.length;
146
- if (breakingCount) {
147
- Logger.error(`Detected ${breakingCount} breaking change${breakingCount > 1 ? 's' : ''}`);
148
- process.exit(1);
149
- }
150
- else {
151
- Logger.success('No breaking changes detected');
152
- }
153
- }
154
- function isString(val) {
155
- return typeof val === 'string';
156
- }
157
-
158
- export default index;
159
- //# sourceMappingURL=index.esm.js.map
package/index.esm.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.esm.js","sources":["../../dist/commands/diff/src/index.js"],"sourcesContent":["import { __awaiter } from \"tslib\";\nimport { createCommand, ensureAbsolute, parseGlobalArgs, } from '@graphql-inspector/commands';\nimport { symbols, Logger, bolderize } from '@graphql-inspector/logger';\nimport { diff as diffSchema, CriticalityLevel, DiffRule, } from '@graphql-inspector/core';\nimport { existsSync } from 'fs';\nexport default createCommand((api) => {\n const { loaders, interceptPositional, interceptOptions, } = api;\n return {\n command: 'diff <oldSchema> <newSchema>',\n describe: 'Compare two GraphQL Schemas',\n builder(yargs) {\n return yargs\n .positional('oldSchema', interceptPositional('oldSchema', {\n describe: 'Point to an old schema',\n type: 'string',\n demandOption: true,\n }))\n .positional('newSchema', interceptPositional('newSchema', {\n describe: 'Point to a new schema',\n type: 'string',\n demandOption: true,\n }))\n .options(interceptOptions({\n rule: {\n describe: 'Add rules',\n array: true,\n },\n onComplete: {\n describe: 'Handle Completion',\n type: 'string',\n },\n }));\n },\n handler(args) {\n return __awaiter(this, void 0, void 0, function* () {\n try {\n const oldSchemaPointer = args.oldSchema;\n const newSchemaPointer = args.newSchema;\n const { headers, token } = parseGlobalArgs(args);\n const oldSchema = yield loaders.loadSchema(oldSchemaPointer, {\n headers,\n token,\n });\n const newSchema = yield loaders.loadSchema(newSchemaPointer, {\n headers,\n token,\n });\n const onComplete = args.onComplete\n ? resolveCompletionHandler(args.onComplete)\n : failOnBreakingChanges;\n const rules = args.rule\n ? args.rule\n .filter(isString)\n .map((name) => {\n const rule = resolveRule(name);\n if (!rule) {\n throw new Error(`\\Rule '${name}' does not exist!\\n`);\n }\n return rule;\n })\n .filter((f) => f)\n : [];\n const changes = diffSchema(oldSchema, newSchema, rules);\n if (changes.length === 0) {\n Logger.success('No changes detected');\n return;\n }\n Logger.log(`\\nDetected the following changes (${changes.length}) between schemas:\\n`);\n const breakingChanges = changes.filter((change) => change.criticality.level === CriticalityLevel.Breaking);\n const dangerousChanges = changes.filter((change) => change.criticality.level === CriticalityLevel.Dangerous);\n const nonBreakingChanges = changes.filter((change) => change.criticality.level === CriticalityLevel.NonBreaking);\n if (breakingChanges.length) {\n reportBreakingChanges(breakingChanges);\n }\n if (dangerousChanges.length) {\n reportDangerousChanges(dangerousChanges);\n }\n if (nonBreakingChanges.length) {\n reportNonBreakingChanges(nonBreakingChanges);\n }\n onComplete({ breakingChanges, dangerousChanges, nonBreakingChanges });\n }\n catch (error) {\n Logger.error(error);\n throw error;\n }\n });\n },\n };\n});\nfunction sortChanges(changes) {\n return changes.slice().sort((a, b) => {\n const aPath = a.path || '';\n const bPath = b.path || '';\n if (aPath > bPath) {\n return 1;\n }\n if (bPath > aPath) {\n return -1;\n }\n return 0;\n });\n}\nfunction reportBreakingChanges(changes) {\n const label = symbols.error;\n const sorted = sortChanges(changes);\n sorted.forEach((change) => {\n Logger.log(`${label} ${bolderize(change.message)}`);\n });\n}\nfunction reportDangerousChanges(changes) {\n const label = symbols.warning;\n const sorted = sortChanges(changes);\n sorted.forEach((change) => {\n Logger.log(`${label} ${bolderize(change.message)}`);\n });\n}\nfunction reportNonBreakingChanges(changes) {\n const label = symbols.success;\n const sorted = sortChanges(changes);\n sorted.forEach((change) => {\n Logger.log(`${label} ${bolderize(change.message)}`);\n });\n}\nfunction resolveRule(name) {\n const filepath = ensureAbsolute(name);\n if (existsSync(filepath)) {\n return require(filepath);\n }\n return DiffRule[name];\n}\nfunction resolveCompletionHandler(name) {\n const filepath = ensureAbsolute(name);\n try {\n require.resolve(filepath);\n }\n catch (error) {\n throw new Error(`CompletionHandler '${name}' does not exist!`);\n }\n const mod = require(filepath);\n return (mod === null || mod === void 0 ? void 0 : mod.default) || mod;\n}\nfunction failOnBreakingChanges({ breakingChanges }) {\n const breakingCount = breakingChanges.length;\n if (breakingCount) {\n Logger.error(`Detected ${breakingCount} breaking change${breakingCount > 1 ? 's' : ''}`);\n process.exit(1);\n }\n else {\n Logger.success('No breaking changes detected');\n }\n}\nfunction isString(val) {\n return typeof val === 'string';\n}\n//# sourceMappingURL=index.js.map"],"names":["diffSchema"],"mappings":";;;;;;AAKA,cAAe,aAAa,CAAC,CAAC,GAAG,KAAK;AACtC,IAAI,MAAM,EAAE,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,GAAG,GAAG,GAAG,CAAC;AACpE,IAAI,OAAO;AACX,QAAQ,OAAO,EAAE,8BAA8B;AAC/C,QAAQ,QAAQ,EAAE,6BAA6B;AAC/C,QAAQ,OAAO,CAAC,KAAK,EAAE;AACvB,YAAY,OAAO,KAAK;AACxB,iBAAiB,UAAU,CAAC,WAAW,EAAE,mBAAmB,CAAC,WAAW,EAAE;AAC1E,gBAAgB,QAAQ,EAAE,wBAAwB;AAClD,gBAAgB,IAAI,EAAE,QAAQ;AAC9B,gBAAgB,YAAY,EAAE,IAAI;AAClC,aAAa,CAAC,CAAC;AACf,iBAAiB,UA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