@graphql-inspector/diff-command 4.0.0-alpha-20230111103803-d92ecd8f → 4.0.0-alpha-20230604111127-91c05ec4
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/LICENSE +21 -0
- package/{index.js → cjs/index.js} +41 -45
- package/cjs/package.json +1 -0
- package/{index.mjs → esm/index.js} +15 -19
- package/package.json +38 -16
- package/typings/index.d.cts +18 -0
- package/{index.d.ts → typings/index.d.ts} +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Kamil Kisiela
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const logger = require('@graphql-inspector/logger');
|
|
10
|
-
|
|
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 commands_1 = require("@graphql-inspector/commands");
|
|
7
|
+
const core_1 = require("@graphql-inspector/core");
|
|
8
|
+
const logger_1 = require("@graphql-inspector/logger");
|
|
11
9
|
function handler(input) {
|
|
12
|
-
return
|
|
10
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
13
11
|
const onComplete = input.onComplete
|
|
14
12
|
? resolveCompletionHandler(input.onComplete)
|
|
15
13
|
: failOnBreakingChanges;
|
|
@@ -25,17 +23,17 @@ function handler(input) {
|
|
|
25
23
|
})
|
|
26
24
|
.filter(f => f)
|
|
27
25
|
: [];
|
|
28
|
-
const changes = yield
|
|
26
|
+
const changes = yield (0, core_1.diff)(input.oldSchema, input.newSchema, rules, {
|
|
29
27
|
checkUsage: input.onUsage ? resolveUsageHandler(input.onUsage) : undefined,
|
|
30
28
|
});
|
|
31
29
|
if (changes.length === 0) {
|
|
32
|
-
|
|
30
|
+
logger_1.Logger.success('No changes detected');
|
|
33
31
|
return;
|
|
34
32
|
}
|
|
35
|
-
|
|
36
|
-
const breakingChanges = changes.filter(change => change.criticality.level ===
|
|
37
|
-
const dangerousChanges = changes.filter(change => change.criticality.level ===
|
|
38
|
-
const nonBreakingChanges = changes.filter(change => change.criticality.level ===
|
|
33
|
+
logger_1.Logger.log(`\nDetected the following changes (${changes.length}) between schemas:\n`);
|
|
34
|
+
const breakingChanges = changes.filter(change => change.criticality.level === core_1.CriticalityLevel.Breaking);
|
|
35
|
+
const dangerousChanges = changes.filter(change => change.criticality.level === core_1.CriticalityLevel.Dangerous);
|
|
36
|
+
const nonBreakingChanges = changes.filter(change => change.criticality.level === core_1.CriticalityLevel.NonBreaking);
|
|
39
37
|
if (breakingChanges.length) {
|
|
40
38
|
reportBreakingChanges(breakingChanges);
|
|
41
39
|
}
|
|
@@ -48,7 +46,8 @@ function handler(input) {
|
|
|
48
46
|
onComplete({ breakingChanges, dangerousChanges, nonBreakingChanges });
|
|
49
47
|
});
|
|
50
48
|
}
|
|
51
|
-
|
|
49
|
+
exports.handler = handler;
|
|
50
|
+
exports.default = (0, commands_1.createCommand)(api => {
|
|
52
51
|
const { loaders } = api;
|
|
53
52
|
return {
|
|
54
53
|
command: 'diff <oldSchema> <newSchema>',
|
|
@@ -82,16 +81,16 @@ const index = commands.createCommand(api => {
|
|
|
82
81
|
},
|
|
83
82
|
handler(args) {
|
|
84
83
|
var _a;
|
|
85
|
-
return
|
|
84
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
86
85
|
try {
|
|
87
86
|
const oldSchemaPointer = args.oldSchema;
|
|
88
87
|
const newSchemaPointer = args.newSchema;
|
|
89
88
|
const apolloFederation = args.federation || false;
|
|
90
89
|
const aws = args.aws || false;
|
|
91
90
|
const method = ((_a = args.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'POST';
|
|
92
|
-
const { headers, leftHeaders, rightHeaders, token } =
|
|
93
|
-
const oldSchemaHeaders = Object.assign(Object.assign({},
|
|
94
|
-
const newSchemaHeaders = Object.assign(Object.assign({},
|
|
91
|
+
const { headers, leftHeaders, rightHeaders, token } = (0, commands_1.parseGlobalArgs)(args);
|
|
92
|
+
const oldSchemaHeaders = Object.assign(Object.assign({}, headers), leftHeaders);
|
|
93
|
+
const newSchemaHeaders = Object.assign(Object.assign({}, headers), rightHeaders);
|
|
95
94
|
const oldSchema = yield loaders.loadSchema(oldSchemaPointer, {
|
|
96
95
|
headers: oldSchemaHeaders,
|
|
97
96
|
token,
|
|
@@ -111,7 +110,7 @@ const index = commands.createCommand(api => {
|
|
|
111
110
|
});
|
|
112
111
|
}
|
|
113
112
|
catch (error) {
|
|
114
|
-
|
|
113
|
+
logger_1.Logger.error(error);
|
|
115
114
|
throw error;
|
|
116
115
|
}
|
|
117
116
|
});
|
|
@@ -132,35 +131,35 @@ function sortChanges(changes) {
|
|
|
132
131
|
});
|
|
133
132
|
}
|
|
134
133
|
function reportBreakingChanges(changes) {
|
|
135
|
-
const label =
|
|
134
|
+
const label = logger_1.symbols.error;
|
|
136
135
|
const sorted = sortChanges(changes);
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
136
|
+
for (const change of sorted) {
|
|
137
|
+
logger_1.Logger.log(`${label} ${(0, logger_1.bolderize)(change.message)}`);
|
|
138
|
+
}
|
|
140
139
|
}
|
|
141
140
|
function reportDangerousChanges(changes) {
|
|
142
|
-
const label =
|
|
141
|
+
const label = logger_1.symbols.warning;
|
|
143
142
|
const sorted = sortChanges(changes);
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
143
|
+
for (const change of sorted) {
|
|
144
|
+
logger_1.Logger.log(`${label} ${(0, logger_1.bolderize)(change.message)}`);
|
|
145
|
+
}
|
|
147
146
|
}
|
|
148
147
|
function reportNonBreakingChanges(changes) {
|
|
149
|
-
const label =
|
|
148
|
+
const label = logger_1.symbols.success;
|
|
150
149
|
const sorted = sortChanges(changes);
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
150
|
+
for (const change of sorted) {
|
|
151
|
+
logger_1.Logger.log(`${label} ${(0, logger_1.bolderize)(change.message)}`);
|
|
152
|
+
}
|
|
154
153
|
}
|
|
155
154
|
function resolveRule(name) {
|
|
156
|
-
const filepath =
|
|
157
|
-
if (
|
|
155
|
+
const filepath = (0, commands_1.ensureAbsolute)(name);
|
|
156
|
+
if ((0, fs_1.existsSync)(filepath)) {
|
|
158
157
|
return require(filepath);
|
|
159
158
|
}
|
|
160
|
-
return
|
|
159
|
+
return core_1.DiffRule[name];
|
|
161
160
|
}
|
|
162
161
|
function resolveCompletionHandler(name) {
|
|
163
|
-
const filepath =
|
|
162
|
+
const filepath = (0, commands_1.ensureAbsolute)(name);
|
|
164
163
|
try {
|
|
165
164
|
require.resolve(filepath);
|
|
166
165
|
}
|
|
@@ -171,7 +170,7 @@ function resolveCompletionHandler(name) {
|
|
|
171
170
|
return (mod === null || mod === void 0 ? void 0 : mod.default) || mod;
|
|
172
171
|
}
|
|
173
172
|
function resolveUsageHandler(name) {
|
|
174
|
-
const filepath =
|
|
173
|
+
const filepath = (0, commands_1.ensureAbsolute)(name);
|
|
175
174
|
try {
|
|
176
175
|
require.resolve(filepath);
|
|
177
176
|
}
|
|
@@ -184,16 +183,13 @@ function resolveUsageHandler(name) {
|
|
|
184
183
|
function failOnBreakingChanges({ breakingChanges }) {
|
|
185
184
|
const breakingCount = breakingChanges.length;
|
|
186
185
|
if (breakingCount) {
|
|
187
|
-
|
|
186
|
+
logger_1.Logger.error(`Detected ${breakingCount} breaking change${breakingCount > 1 ? 's' : ''}`);
|
|
188
187
|
process.exit(1);
|
|
189
188
|
}
|
|
190
189
|
else {
|
|
191
|
-
|
|
190
|
+
logger_1.Logger.success('No breaking changes detected');
|
|
192
191
|
}
|
|
193
192
|
}
|
|
194
193
|
function isString(val) {
|
|
195
194
|
return typeof val === 'string';
|
|
196
195
|
}
|
|
197
|
-
|
|
198
|
-
exports.default = index;
|
|
199
|
-
exports.handler = handler;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { __awaiter } from
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
2
|
import { existsSync } from 'fs';
|
|
3
|
-
import { createCommand, parseGlobalArgs,
|
|
4
|
-
import {
|
|
5
|
-
import { Logger, symbols
|
|
6
|
-
|
|
7
|
-
function handler(input) {
|
|
3
|
+
import { createCommand, ensureAbsolute, parseGlobalArgs, } from '@graphql-inspector/commands';
|
|
4
|
+
import { CriticalityLevel, DiffRule, diff as diffSchema, } from '@graphql-inspector/core';
|
|
5
|
+
import { bolderize, Logger, symbols } from '@graphql-inspector/logger';
|
|
6
|
+
export function handler(input) {
|
|
8
7
|
return __awaiter(this, void 0, void 0, function* () {
|
|
9
8
|
const onComplete = input.onComplete
|
|
10
9
|
? resolveCompletionHandler(input.onComplete)
|
|
@@ -21,7 +20,7 @@ function handler(input) {
|
|
|
21
20
|
})
|
|
22
21
|
.filter(f => f)
|
|
23
22
|
: [];
|
|
24
|
-
const changes = yield
|
|
23
|
+
const changes = yield diffSchema(input.oldSchema, input.newSchema, rules, {
|
|
25
24
|
checkUsage: input.onUsage ? resolveUsageHandler(input.onUsage) : undefined,
|
|
26
25
|
});
|
|
27
26
|
if (changes.length === 0) {
|
|
@@ -44,7 +43,7 @@ function handler(input) {
|
|
|
44
43
|
onComplete({ breakingChanges, dangerousChanges, nonBreakingChanges });
|
|
45
44
|
});
|
|
46
45
|
}
|
|
47
|
-
|
|
46
|
+
export default createCommand(api => {
|
|
48
47
|
const { loaders } = api;
|
|
49
48
|
return {
|
|
50
49
|
command: 'diff <oldSchema> <newSchema>',
|
|
@@ -86,8 +85,8 @@ const index = createCommand(api => {
|
|
|
86
85
|
const aws = args.aws || false;
|
|
87
86
|
const method = ((_a = args.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'POST';
|
|
88
87
|
const { headers, leftHeaders, rightHeaders, token } = parseGlobalArgs(args);
|
|
89
|
-
const oldSchemaHeaders = Object.assign(Object.assign({},
|
|
90
|
-
const newSchemaHeaders = Object.assign(Object.assign({},
|
|
88
|
+
const oldSchemaHeaders = Object.assign(Object.assign({}, headers), leftHeaders);
|
|
89
|
+
const newSchemaHeaders = Object.assign(Object.assign({}, headers), rightHeaders);
|
|
91
90
|
const oldSchema = yield loaders.loadSchema(oldSchemaPointer, {
|
|
92
91
|
headers: oldSchemaHeaders,
|
|
93
92
|
token,
|
|
@@ -130,23 +129,23 @@ function sortChanges(changes) {
|
|
|
130
129
|
function reportBreakingChanges(changes) {
|
|
131
130
|
const label = symbols.error;
|
|
132
131
|
const sorted = sortChanges(changes);
|
|
133
|
-
|
|
132
|
+
for (const change of sorted) {
|
|
134
133
|
Logger.log(`${label} ${bolderize(change.message)}`);
|
|
135
|
-
}
|
|
134
|
+
}
|
|
136
135
|
}
|
|
137
136
|
function reportDangerousChanges(changes) {
|
|
138
137
|
const label = symbols.warning;
|
|
139
138
|
const sorted = sortChanges(changes);
|
|
140
|
-
|
|
139
|
+
for (const change of sorted) {
|
|
141
140
|
Logger.log(`${label} ${bolderize(change.message)}`);
|
|
142
|
-
}
|
|
141
|
+
}
|
|
143
142
|
}
|
|
144
143
|
function reportNonBreakingChanges(changes) {
|
|
145
144
|
const label = symbols.success;
|
|
146
145
|
const sorted = sortChanges(changes);
|
|
147
|
-
|
|
146
|
+
for (const change of sorted) {
|
|
148
147
|
Logger.log(`${label} ${bolderize(change.message)}`);
|
|
149
|
-
}
|
|
148
|
+
}
|
|
150
149
|
}
|
|
151
150
|
function resolveRule(name) {
|
|
152
151
|
const filepath = ensureAbsolute(name);
|
|
@@ -190,6 +189,3 @@ function failOnBreakingChanges({ breakingChanges }) {
|
|
|
190
189
|
function isString(val) {
|
|
191
190
|
return typeof val === 'string';
|
|
192
191
|
}
|
|
193
|
-
|
|
194
|
-
export default index;
|
|
195
|
-
export { handler };
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-inspector/diff-command",
|
|
3
|
-
"version": "4.0.0-alpha-
|
|
3
|
+
"version": "4.0.0-alpha-20230604111127-91c05ec4",
|
|
4
4
|
"description": "Compare GraphQL Schemas",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
|
-
"graphql": "^
|
|
7
|
+
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"
|
|
11
|
-
"@graphql-inspector/
|
|
12
|
-
"@graphql-inspector/
|
|
13
|
-
"
|
|
10
|
+
"tslib": "2.5.3",
|
|
11
|
+
"@graphql-inspector/commands": "4.0.0-alpha-20230604111127-91c05ec4",
|
|
12
|
+
"@graphql-inspector/core": "5.0.0-alpha-20230604111127-91c05ec4",
|
|
13
|
+
"@graphql-inspector/logger": "4.0.0-alpha-20230604111127-91c05ec4"
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
@@ -29,20 +29,42 @@
|
|
|
29
29
|
"url": "https://github.com/kamilkisiela"
|
|
30
30
|
},
|
|
31
31
|
"license": "MIT",
|
|
32
|
-
"main": "index.js",
|
|
33
|
-
"module": "index.
|
|
34
|
-
"typings": "index.d.ts",
|
|
32
|
+
"main": "cjs/index.js",
|
|
33
|
+
"module": "esm/index.js",
|
|
34
|
+
"typings": "typings/index.d.ts",
|
|
35
35
|
"typescript": {
|
|
36
|
-
"definition": "index.d.ts"
|
|
36
|
+
"definition": "typings/index.d.ts"
|
|
37
37
|
},
|
|
38
|
+
"type": "module",
|
|
38
39
|
"exports": {
|
|
39
40
|
".": {
|
|
40
|
-
"require":
|
|
41
|
-
|
|
41
|
+
"require": {
|
|
42
|
+
"types": "./typings/index.d.cts",
|
|
43
|
+
"default": "./cjs/index.js"
|
|
44
|
+
},
|
|
45
|
+
"import": {
|
|
46
|
+
"types": "./typings/index.d.ts",
|
|
47
|
+
"default": "./esm/index.js"
|
|
48
|
+
},
|
|
49
|
+
"default": {
|
|
50
|
+
"types": "./typings/index.d.ts",
|
|
51
|
+
"default": "./esm/index.js"
|
|
52
|
+
}
|
|
42
53
|
},
|
|
43
54
|
"./*": {
|
|
44
|
-
"require":
|
|
45
|
-
|
|
46
|
-
|
|
55
|
+
"require": {
|
|
56
|
+
"types": "./typings/*.d.cts",
|
|
57
|
+
"default": "./cjs/*.js"
|
|
58
|
+
},
|
|
59
|
+
"import": {
|
|
60
|
+
"types": "./typings/*.d.ts",
|
|
61
|
+
"default": "./esm/*.js"
|
|
62
|
+
},
|
|
63
|
+
"default": {
|
|
64
|
+
"types": "./typings/*.d.ts",
|
|
65
|
+
"default": "./esm/*.js"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"./package.json": "./package.json"
|
|
47
69
|
}
|
|
48
|
-
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { CommandFactory, GlobalArgs } from '@graphql-inspector/commands';
|
|
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<{}, {
|
|
12
|
+
oldSchema: string;
|
|
13
|
+
newSchema: string;
|
|
14
|
+
rule?: (string | number)[] | undefined;
|
|
15
|
+
onComplete?: string | undefined;
|
|
16
|
+
onUsage?: string | undefined;
|
|
17
|
+
} & GlobalArgs>;
|
|
18
|
+
export default _default;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CommandFactory, GlobalArgs } from '@graphql-inspector/commands';
|
|
2
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { CommandFactory, GlobalArgs } from '@graphql-inspector/commands';
|
|
3
3
|
export { CommandFactory };
|
|
4
4
|
export declare function handler(input: {
|
|
5
5
|
oldSchema: GraphQLSchema;
|