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