@graphql-inspector/core 4.0.2 → 4.0.3
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/cjs/ast/document.js +40 -0
- package/cjs/coverage/index.js +128 -0
- package/cjs/coverage/output/json.js +7 -0
- package/cjs/diff/argument.js +25 -0
- package/cjs/diff/changes/argument.js +48 -0
- package/cjs/diff/changes/change.js +75 -0
- package/cjs/diff/changes/directive.js +124 -0
- package/cjs/diff/changes/enum.js +75 -0
- package/cjs/diff/changes/field.js +166 -0
- package/cjs/diff/changes/input.js +98 -0
- package/cjs/diff/changes/object.js +28 -0
- package/cjs/diff/changes/schema.js +40 -0
- package/cjs/diff/changes/type.js +72 -0
- package/cjs/diff/changes/union.js +28 -0
- package/cjs/diff/directive.js +41 -0
- package/cjs/diff/enum.js +34 -0
- package/cjs/diff/field.js +54 -0
- package/cjs/diff/index.js +22 -0
- package/cjs/diff/input.js +47 -0
- package/cjs/diff/interface.js +20 -0
- package/cjs/diff/object.js +33 -0
- package/cjs/diff/onComplete/types.js +0 -0
- package/cjs/diff/rules/config.js +0 -0
- package/cjs/diff/rules/consider-usage.js +39 -0
- package/cjs/diff/rules/dangerous-breaking.js +13 -0
- package/cjs/diff/rules/ignore-description-changes.js +21 -0
- package/cjs/diff/rules/index.js +8 -0
- package/cjs/diff/rules/safe-unreachable.js +19 -0
- package/cjs/diff/rules/suppress-removal-of-deprecated-field.js +58 -0
- package/cjs/diff/rules/types.js +0 -0
- package/cjs/diff/schema.js +107 -0
- package/cjs/diff/union.js +18 -0
- package/cjs/index.js +27 -0
- package/cjs/package.json +1 -0
- package/cjs/similar/index.js +57 -0
- package/cjs/utils/apollo.js +21 -0
- package/cjs/utils/compare.js +91 -0
- package/cjs/utils/graphql.js +194 -0
- package/cjs/utils/is-deprecated.js +17 -0
- package/cjs/utils/path.js +7 -0
- package/cjs/utils/string.js +70 -0
- package/cjs/validate/alias-count.js +37 -0
- package/cjs/validate/complexity.js +39 -0
- package/cjs/validate/directive-count.js +37 -0
- package/cjs/validate/index.js +143 -0
- package/cjs/validate/query-depth.js +103 -0
- package/cjs/validate/token-count.js +55 -0
- package/esm/ast/document.js +36 -0
- package/esm/coverage/index.js +124 -0
- package/esm/coverage/output/json.js +3 -0
- package/esm/diff/argument.js +21 -0
- package/esm/diff/changes/argument.js +42 -0
- package/esm/diff/changes/change.js +72 -0
- package/esm/diff/changes/directive.js +111 -0
- package/esm/diff/changes/enum.js +66 -0
- package/esm/diff/changes/field.js +150 -0
- package/esm/diff/changes/input.js +88 -0
- package/esm/diff/changes/object.js +23 -0
- package/esm/diff/changes/schema.js +34 -0
- package/esm/diff/changes/type.js +63 -0
- package/esm/diff/changes/union.js +23 -0
- package/esm/diff/directive.js +37 -0
- package/esm/diff/enum.js +30 -0
- package/esm/diff/field.js +50 -0
- package/esm/diff/index.js +18 -0
- package/esm/diff/input.js +43 -0
- package/esm/diff/interface.js +16 -0
- package/esm/diff/object.js +29 -0
- package/esm/diff/onComplete/types.js +0 -0
- package/esm/diff/rules/config.js +0 -0
- package/esm/diff/rules/consider-usage.js +35 -0
- package/esm/diff/rules/dangerous-breaking.js +9 -0
- package/esm/diff/rules/ignore-description-changes.js +17 -0
- package/esm/diff/rules/index.js +5 -0
- package/esm/diff/rules/safe-unreachable.js +15 -0
- package/esm/diff/rules/suppress-removal-of-deprecated-field.js +54 -0
- package/esm/diff/rules/types.js +0 -0
- package/esm/diff/schema.js +103 -0
- package/esm/diff/union.js +14 -0
- package/esm/index.js +11 -0
- package/esm/similar/index.js +53 -0
- package/esm/utils/apollo.js +16 -0
- package/esm/utils/compare.js +82 -0
- package/esm/utils/graphql.js +181 -0
- package/esm/utils/is-deprecated.js +13 -0
- package/esm/utils/path.js +3 -0
- package/esm/utils/string.js +64 -0
- package/esm/validate/alias-count.js +32 -0
- package/esm/validate/complexity.js +34 -0
- package/esm/validate/directive-count.js +32 -0
- package/esm/validate/index.js +139 -0
- package/esm/validate/query-depth.js +97 -0
- package/esm/validate/token-count.js +50 -0
- package/package.json +30 -9
- package/typings/ast/document.d.ts +15 -0
- package/typings/coverage/index.d.ts +51 -0
- package/typings/coverage/output/json.d.cts +2 -0
- package/{coverage → typings/coverage}/output/json.d.ts +1 -1
- package/typings/diff/argument.d.cts +3 -0
- package/{diff → typings/diff}/argument.d.ts +1 -1
- package/typings/diff/changes/argument.d.cts +5 -0
- package/{diff → typings/diff}/changes/argument.d.ts +1 -1
- package/typings/diff/changes/change.d.ts +69 -0
- package/typings/diff/changes/directive.d.cts +12 -0
- package/{diff → typings/diff}/changes/directive.d.ts +1 -1
- package/typings/diff/changes/enum.d.cts +8 -0
- package/{diff → typings/diff}/changes/enum.d.ts +1 -1
- package/typings/diff/changes/field.d.cts +15 -0
- package/{diff → typings/diff}/changes/field.d.ts +1 -1
- package/typings/diff/changes/input.d.cts +9 -0
- package/{diff → typings/diff}/changes/input.d.ts +1 -1
- package/typings/diff/changes/object.d.cts +4 -0
- package/{diff → typings/diff}/changes/object.d.ts +1 -1
- package/typings/diff/changes/schema.d.cts +5 -0
- package/{diff → typings/diff}/changes/schema.d.ts +1 -1
- package/typings/diff/changes/type.d.cts +8 -0
- package/{diff → typings/diff}/changes/type.d.ts +1 -1
- package/typings/diff/changes/union.d.cts +4 -0
- package/{diff → typings/diff}/changes/union.d.ts +1 -1
- package/typings/diff/directive.d.cts +3 -0
- package/{diff → typings/diff}/directive.d.ts +1 -1
- package/typings/diff/enum.d.cts +3 -0
- package/{diff → typings/diff}/enum.d.ts +1 -1
- package/typings/diff/field.d.cts +3 -0
- package/{diff → typings/diff}/field.d.ts +1 -1
- package/typings/diff/index.d.cts +9 -0
- package/typings/diff/index.d.ts +9 -0
- package/typings/diff/input.d.cts +3 -0
- package/{diff → typings/diff}/input.d.ts +1 -1
- package/typings/diff/interface.d.cts +3 -0
- package/{diff → typings/diff}/interface.d.ts +1 -1
- package/typings/diff/object.d.cts +3 -0
- package/{diff → typings/diff}/object.d.ts +1 -1
- package/typings/diff/onComplete/types.d.cts +7 -0
- package/typings/diff/onComplete/types.d.ts +7 -0
- package/typings/diff/rules/config.d.cts +2 -0
- package/typings/diff/rules/config.d.ts +2 -0
- package/typings/diff/rules/consider-usage.d.cts +29 -0
- package/{diff → typings/diff}/rules/consider-usage.d.ts +2 -2
- package/typings/diff/rules/dangerous-breaking.d.cts +2 -0
- package/{diff → typings/diff}/rules/dangerous-breaking.d.ts +1 -1
- package/typings/diff/rules/ignore-description-changes.d.cts +2 -0
- package/{diff → typings/diff}/rules/ignore-description-changes.d.ts +1 -1
- package/typings/diff/rules/index.d.cts +5 -0
- package/typings/diff/rules/index.d.ts +5 -0
- package/typings/diff/rules/safe-unreachable.d.cts +2 -0
- package/{diff → typings/diff}/rules/safe-unreachable.d.ts +1 -1
- package/typings/diff/rules/suppress-removal-of-deprecated-field.d.cts +2 -0
- package/{diff → typings/diff}/rules/suppress-removal-of-deprecated-field.d.ts +1 -1
- package/typings/diff/rules/types.d.cts +8 -0
- package/{diff → typings/diff}/rules/types.d.ts +2 -2
- package/typings/diff/schema.d.cts +4 -0
- package/{diff → typings/diff}/schema.d.ts +2 -2
- package/typings/diff/union.d.cts +3 -0
- package/{diff → typings/diff}/union.d.ts +1 -1
- package/typings/index.d.cts +12 -0
- package/typings/index.d.ts +12 -0
- package/typings/similar/index.d.cts +6 -0
- package/{similar → typings/similar}/index.d.ts +1 -1
- package/typings/utils/apollo.d.ts +5 -0
- package/typings/utils/compare.d.ts +22 -0
- package/typings/utils/graphql.d.ts +11 -0
- package/typings/utils/is-deprecated.d.cts +2 -0
- package/{utils → typings/utils}/is-deprecated.d.ts +1 -1
- package/typings/utils/path.d.ts +1 -0
- package/typings/utils/string.d.ts +14 -0
- package/typings/validate/alias-count.d.ts +10 -0
- package/typings/validate/complexity.d.cts +16 -0
- package/{validate → typings/validate}/complexity.d.ts +1 -1
- package/typings/validate/directive-count.d.ts +10 -0
- package/typings/validate/index.d.ts +49 -0
- package/typings/validate/query-depth.d.ts +15 -0
- package/typings/validate/token-count.d.ts +12 -0
- package/diff/index.d.ts +0 -9
- package/diff/onComplete/types.d.ts +0 -7
- package/diff/rules/config.d.ts +0 -2
- package/diff/rules/index.d.ts +0 -5
- package/index.d.ts +0 -12
- package/index.js +0 -2075
- package/index.mjs +0 -2061
- /package/{ast/document.d.ts → typings/ast/document.d.cts} +0 -0
- /package/{coverage/index.d.ts → typings/coverage/index.d.cts} +0 -0
- /package/{diff/changes/change.d.ts → typings/diff/changes/change.d.cts} +0 -0
- /package/{utils/apollo.d.ts → typings/utils/apollo.d.cts} +0 -0
- /package/{utils/compare.d.ts → typings/utils/compare.d.cts} +0 -0
- /package/{utils/graphql.d.ts → typings/utils/graphql.d.cts} +0 -0
- /package/{utils/path.d.ts → typings/utils/path.d.cts} +0 -0
- /package/{utils/string.d.ts → typings/utils/string.d.cts} +0 -0
- /package/{validate/alias-count.d.ts → typings/validate/alias-count.d.cts} +0 -0
- /package/{validate/directive-count.d.ts → typings/validate/directive-count.d.cts} +0 -0
- /package/{validate/index.d.ts → typings/validate/index.d.cts} +0 -0
- /package/{validate/query-depth.d.ts → typings/validate/query-depth.d.cts} +0 -0
- /package/{validate/token-count.d.ts → typings/validate/token-count.d.cts} +0 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.changesInObject = void 0;
|
|
4
|
+
const compare_js_1 = require("../utils/compare.js");
|
|
5
|
+
const field_js_1 = require("./changes/field.js");
|
|
6
|
+
const object_js_1 = require("./changes/object.js");
|
|
7
|
+
const field_js_2 = require("./field.js");
|
|
8
|
+
function changesInObject(oldType, newType, addChange) {
|
|
9
|
+
const oldInterfaces = oldType.getInterfaces();
|
|
10
|
+
const newInterfaces = newType.getInterfaces();
|
|
11
|
+
const oldFields = oldType.getFields();
|
|
12
|
+
const newFields = newType.getFields();
|
|
13
|
+
(0, compare_js_1.compareLists)(oldInterfaces, newInterfaces, {
|
|
14
|
+
onAdded(i) {
|
|
15
|
+
addChange((0, object_js_1.objectTypeInterfaceAdded)(i, newType));
|
|
16
|
+
},
|
|
17
|
+
onRemoved(i) {
|
|
18
|
+
addChange((0, object_js_1.objectTypeInterfaceRemoved)(i, oldType));
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
(0, compare_js_1.compareLists)(Object.values(oldFields), Object.values(newFields), {
|
|
22
|
+
onAdded(f) {
|
|
23
|
+
addChange((0, field_js_1.fieldAdded)(newType, f));
|
|
24
|
+
},
|
|
25
|
+
onRemoved(f) {
|
|
26
|
+
addChange((0, field_js_1.fieldRemoved)(oldType, f));
|
|
27
|
+
},
|
|
28
|
+
onMutual(f) {
|
|
29
|
+
(0, field_js_2.changesInField)(oldType, f.oldVersion, f.newVersion, addChange);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
exports.changesInObject = changesInObject;
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.considerUsage = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const path_js_1 = require("../../utils/path.js");
|
|
6
|
+
const change_js_1 = require("./../changes/change.js");
|
|
7
|
+
const considerUsage = ({ changes, config }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
8
|
+
if (!config) {
|
|
9
|
+
throw new Error(`considerUsage rule is missing config`);
|
|
10
|
+
}
|
|
11
|
+
const collectedBreakingField = [];
|
|
12
|
+
changes.forEach(change => {
|
|
13
|
+
if (change.criticality.level === change_js_1.CriticalityLevel.Breaking && change.path) {
|
|
14
|
+
const [typeName, fieldName, argumentName] = (0, path_js_1.parsePath)(change.path);
|
|
15
|
+
collectedBreakingField.push({
|
|
16
|
+
type: typeName,
|
|
17
|
+
field: fieldName,
|
|
18
|
+
argument: argumentName,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
// True if safe to break, false otherwise
|
|
23
|
+
const usageList = yield config.checkUsage(collectedBreakingField);
|
|
24
|
+
// turns an array of booleans into an array of `Type.Field` strings
|
|
25
|
+
// includes only those that are safe to break the api
|
|
26
|
+
const suppressedPaths = collectedBreakingField
|
|
27
|
+
.filter((_, i) => usageList[i] === true)
|
|
28
|
+
.map(({ type, field, argument }) => [type, field, argument].filter(Boolean).join('.'));
|
|
29
|
+
return changes.map(change => {
|
|
30
|
+
// Turns those "safe to break" changes into "dangerous"
|
|
31
|
+
if (change.criticality.level === change_js_1.CriticalityLevel.Breaking &&
|
|
32
|
+
change.path &&
|
|
33
|
+
suppressedPaths.some(p => change.path.startsWith(p))) {
|
|
34
|
+
return Object.assign(Object.assign({}, change), { criticality: Object.assign(Object.assign({}, change.criticality), { level: change_js_1.CriticalityLevel.Dangerous }), message: `${change.message} (non-breaking based on usage)` });
|
|
35
|
+
}
|
|
36
|
+
return change;
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
exports.considerUsage = considerUsage;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dangerousBreaking = void 0;
|
|
4
|
+
const change_js_1 = require("./../changes/change.js");
|
|
5
|
+
const dangerousBreaking = ({ changes }) => {
|
|
6
|
+
return changes.map(change => {
|
|
7
|
+
if (change.criticality.level === change_js_1.CriticalityLevel.Dangerous) {
|
|
8
|
+
return Object.assign(Object.assign({}, change), { criticality: Object.assign(Object.assign({}, change.criticality), { level: change_js_1.CriticalityLevel.Breaking }) });
|
|
9
|
+
}
|
|
10
|
+
return change;
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
exports.dangerousBreaking = dangerousBreaking;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ignoreDescriptionChanges = void 0;
|
|
4
|
+
const change_js_1 = require("../changes/change.js");
|
|
5
|
+
const descriptionChangeTypes = [
|
|
6
|
+
change_js_1.ChangeType.FieldArgumentDescriptionChanged,
|
|
7
|
+
change_js_1.ChangeType.DirectiveDescriptionChanged,
|
|
8
|
+
change_js_1.ChangeType.DirectiveArgumentDescriptionChanged,
|
|
9
|
+
change_js_1.ChangeType.EnumValueDescriptionChanged,
|
|
10
|
+
change_js_1.ChangeType.FieldDescriptionChanged,
|
|
11
|
+
change_js_1.ChangeType.FieldDescriptionAdded,
|
|
12
|
+
change_js_1.ChangeType.FieldDescriptionRemoved,
|
|
13
|
+
change_js_1.ChangeType.InputFieldDescriptionAdded,
|
|
14
|
+
change_js_1.ChangeType.InputFieldDescriptionRemoved,
|
|
15
|
+
change_js_1.ChangeType.InputFieldDescriptionChanged,
|
|
16
|
+
change_js_1.ChangeType.TypeDescriptionChanged,
|
|
17
|
+
];
|
|
18
|
+
const ignoreDescriptionChanges = ({ changes }) => {
|
|
19
|
+
return changes.filter(change => !descriptionChangeTypes.includes(change.type));
|
|
20
|
+
};
|
|
21
|
+
exports.ignoreDescriptionChanges = ignoreDescriptionChanges;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./consider-usage.js"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./dangerous-breaking.js"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./ignore-description-changes.js"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./safe-unreachable.js"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./suppress-removal-of-deprecated-field.js"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.safeUnreachable = void 0;
|
|
4
|
+
const graphql_js_1 = require("../../utils/graphql.js");
|
|
5
|
+
const path_js_1 = require("../../utils/path.js");
|
|
6
|
+
const change_js_1 = require("./../changes/change.js");
|
|
7
|
+
const safeUnreachable = ({ changes, oldSchema }) => {
|
|
8
|
+
const reachable = (0, graphql_js_1.getReachableTypes)(oldSchema);
|
|
9
|
+
return changes.map(change => {
|
|
10
|
+
if (change.criticality.level === change_js_1.CriticalityLevel.Breaking && change.path) {
|
|
11
|
+
const [typeName] = (0, path_js_1.parsePath)(change.path);
|
|
12
|
+
if (!reachable.has(typeName)) {
|
|
13
|
+
return Object.assign(Object.assign({}, change), { criticality: Object.assign(Object.assign({}, change.criticality), { level: change_js_1.CriticalityLevel.NonBreaking }), message: 'Unreachable from root' });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return change;
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
exports.safeUnreachable = safeUnreachable;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.suppressRemovalOfDeprecatedField = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const is_deprecated_js_1 = require("../../utils/is-deprecated.js");
|
|
6
|
+
const path_js_1 = require("../../utils/path.js");
|
|
7
|
+
const change_js_1 = require("./../changes/change.js");
|
|
8
|
+
const suppressRemovalOfDeprecatedField = ({ changes, oldSchema, newSchema }) => {
|
|
9
|
+
return changes.map(change => {
|
|
10
|
+
if (change.type === change_js_1.ChangeType.FieldRemoved &&
|
|
11
|
+
change.criticality.level === change_js_1.CriticalityLevel.Breaking &&
|
|
12
|
+
change.path) {
|
|
13
|
+
const [typeName, fieldName] = (0, path_js_1.parsePath)(change.path);
|
|
14
|
+
const type = oldSchema.getType(typeName);
|
|
15
|
+
if ((0, graphql_1.isObjectType)(type) || (0, graphql_1.isInterfaceType)(type)) {
|
|
16
|
+
const field = type.getFields()[fieldName];
|
|
17
|
+
if ((0, is_deprecated_js_1.isDeprecated)(field)) {
|
|
18
|
+
return Object.assign(Object.assign({}, change), { criticality: Object.assign(Object.assign({}, change.criticality), { level: change_js_1.CriticalityLevel.Dangerous }) });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (change.type === change_js_1.ChangeType.EnumValueRemoved &&
|
|
23
|
+
change.criticality.level === change_js_1.CriticalityLevel.Breaking &&
|
|
24
|
+
change.path) {
|
|
25
|
+
const [enumName, enumItem] = (0, path_js_1.parsePath)(change.path);
|
|
26
|
+
const type = oldSchema.getType(enumName);
|
|
27
|
+
if ((0, graphql_1.isEnumType)(type)) {
|
|
28
|
+
const item = type.getValue(enumItem);
|
|
29
|
+
if (item && (0, is_deprecated_js_1.isDeprecated)(item)) {
|
|
30
|
+
return Object.assign(Object.assign({}, change), { criticality: Object.assign(Object.assign({}, change.criticality), { level: change_js_1.CriticalityLevel.Dangerous }) });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (change.type === change_js_1.ChangeType.InputFieldRemoved &&
|
|
35
|
+
change.criticality.level === change_js_1.CriticalityLevel.Breaking &&
|
|
36
|
+
change.path) {
|
|
37
|
+
const [inputName, inputItem] = (0, path_js_1.parsePath)(change.path);
|
|
38
|
+
const type = oldSchema.getType(inputName);
|
|
39
|
+
if ((0, graphql_1.isInputObjectType)(type)) {
|
|
40
|
+
const item = type.getFields()[inputItem];
|
|
41
|
+
if (item && (0, is_deprecated_js_1.isDeprecated)(item)) {
|
|
42
|
+
return Object.assign(Object.assign({}, change), { criticality: Object.assign(Object.assign({}, change.criticality), { level: change_js_1.CriticalityLevel.Dangerous }) });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (change.type === change_js_1.ChangeType.TypeRemoved &&
|
|
47
|
+
change.criticality.level === change_js_1.CriticalityLevel.Breaking &&
|
|
48
|
+
change.path) {
|
|
49
|
+
const [typeName] = (0, path_js_1.parsePath)(change.path);
|
|
50
|
+
const type = newSchema.getType(typeName);
|
|
51
|
+
if (!type) {
|
|
52
|
+
return Object.assign(Object.assign({}, change), { criticality: Object.assign(Object.assign({}, change.criticality), { level: change_js_1.CriticalityLevel.Dangerous }) });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return change;
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
exports.suppressRemovalOfDeprecatedField = suppressRemovalOfDeprecatedField;
|
|
File without changes
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.diffSchema = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const compare_js_1 = require("../utils/compare.js");
|
|
6
|
+
const graphql_js_1 = require("../utils/graphql.js");
|
|
7
|
+
const directive_js_1 = require("./changes/directive.js");
|
|
8
|
+
const schema_js_1 = require("./changes/schema.js");
|
|
9
|
+
const type_js_1 = require("./changes/type.js");
|
|
10
|
+
const directive_js_2 = require("./directive.js");
|
|
11
|
+
const enum_js_1 = require("./enum.js");
|
|
12
|
+
const input_js_1 = require("./input.js");
|
|
13
|
+
const interface_js_1 = require("./interface.js");
|
|
14
|
+
const object_js_1 = require("./object.js");
|
|
15
|
+
const union_js_1 = require("./union.js");
|
|
16
|
+
function diffSchema(oldSchema, newSchema) {
|
|
17
|
+
const changes = [];
|
|
18
|
+
function addChange(change) {
|
|
19
|
+
changes.push(change);
|
|
20
|
+
}
|
|
21
|
+
changesInSchema(oldSchema, newSchema, addChange);
|
|
22
|
+
(0, compare_js_1.compareLists)(Object.values(oldSchema.getTypeMap()).filter(t => !(0, graphql_js_1.isPrimitive)(t)), Object.values(newSchema.getTypeMap()).filter(t => !(0, graphql_js_1.isPrimitive)(t)), {
|
|
23
|
+
onAdded(type) {
|
|
24
|
+
addChange((0, type_js_1.typeAdded)(type));
|
|
25
|
+
},
|
|
26
|
+
onRemoved(type) {
|
|
27
|
+
addChange((0, type_js_1.typeRemoved)(type));
|
|
28
|
+
},
|
|
29
|
+
onMutual(type) {
|
|
30
|
+
changesInType(type.oldVersion, type.newVersion, addChange);
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
(0, compare_js_1.compareLists)(oldSchema.getDirectives(), newSchema.getDirectives(), {
|
|
34
|
+
onAdded(directive) {
|
|
35
|
+
addChange((0, directive_js_1.directiveAdded)(directive));
|
|
36
|
+
},
|
|
37
|
+
onRemoved(directive) {
|
|
38
|
+
addChange((0, directive_js_1.directiveRemoved)(directive));
|
|
39
|
+
},
|
|
40
|
+
onMutual(directive) {
|
|
41
|
+
(0, directive_js_2.changesInDirective)(directive.oldVersion, directive.newVersion, addChange);
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
return changes;
|
|
45
|
+
}
|
|
46
|
+
exports.diffSchema = diffSchema;
|
|
47
|
+
function changesInSchema(oldSchema, newSchema, addChange) {
|
|
48
|
+
var _a, _b, _c, _d, _e, _f;
|
|
49
|
+
const defaultNames = {
|
|
50
|
+
query: 'Query',
|
|
51
|
+
mutation: 'Mutation',
|
|
52
|
+
subscription: 'Subscription',
|
|
53
|
+
};
|
|
54
|
+
const oldRoot = {
|
|
55
|
+
query: (_a = (oldSchema.getQueryType() || {}).name) !== null && _a !== void 0 ? _a : defaultNames.query,
|
|
56
|
+
mutation: (_b = (oldSchema.getMutationType() || {}).name) !== null && _b !== void 0 ? _b : defaultNames.mutation,
|
|
57
|
+
subscription: (_c = (oldSchema.getSubscriptionType() || {}).name) !== null && _c !== void 0 ? _c : defaultNames.subscription,
|
|
58
|
+
};
|
|
59
|
+
const newRoot = {
|
|
60
|
+
query: (_d = (newSchema.getQueryType() || {}).name) !== null && _d !== void 0 ? _d : defaultNames.query,
|
|
61
|
+
mutation: (_e = (newSchema.getMutationType() || {}).name) !== null && _e !== void 0 ? _e : defaultNames.mutation,
|
|
62
|
+
subscription: (_f = (newSchema.getSubscriptionType() || {}).name) !== null && _f !== void 0 ? _f : defaultNames.subscription,
|
|
63
|
+
};
|
|
64
|
+
if ((0, compare_js_1.isNotEqual)(oldRoot.query, newRoot.query)) {
|
|
65
|
+
addChange((0, schema_js_1.schemaQueryTypeChanged)(oldSchema, newSchema));
|
|
66
|
+
}
|
|
67
|
+
if ((0, compare_js_1.isNotEqual)(oldRoot.mutation, newRoot.mutation)) {
|
|
68
|
+
addChange((0, schema_js_1.schemaMutationTypeChanged)(oldSchema, newSchema));
|
|
69
|
+
}
|
|
70
|
+
if ((0, compare_js_1.isNotEqual)(oldRoot.subscription, newRoot.subscription)) {
|
|
71
|
+
addChange((0, schema_js_1.schemaSubscriptionTypeChanged)(oldSchema, newSchema));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function changesInType(oldType, newType, addChange) {
|
|
75
|
+
if ((0, graphql_1.isEnumType)(oldType) && (0, graphql_1.isEnumType)(newType)) {
|
|
76
|
+
(0, enum_js_1.changesInEnum)(oldType, newType, addChange);
|
|
77
|
+
}
|
|
78
|
+
else if ((0, graphql_1.isUnionType)(oldType) && (0, graphql_1.isUnionType)(newType)) {
|
|
79
|
+
(0, union_js_1.changesInUnion)(oldType, newType, addChange);
|
|
80
|
+
}
|
|
81
|
+
else if ((0, graphql_1.isInputObjectType)(oldType) && (0, graphql_1.isInputObjectType)(newType)) {
|
|
82
|
+
(0, input_js_1.changesInInputObject)(oldType, newType, addChange);
|
|
83
|
+
}
|
|
84
|
+
else if ((0, graphql_1.isObjectType)(oldType) && (0, graphql_1.isObjectType)(newType)) {
|
|
85
|
+
(0, object_js_1.changesInObject)(oldType, newType, addChange);
|
|
86
|
+
}
|
|
87
|
+
else if ((0, graphql_1.isInterfaceType)(oldType) && (0, graphql_1.isInterfaceType)(newType)) {
|
|
88
|
+
(0, interface_js_1.changesInInterface)(oldType, newType, addChange);
|
|
89
|
+
}
|
|
90
|
+
else if ((0, graphql_1.isScalarType)(oldType) && (0, graphql_1.isScalarType)(newType)) {
|
|
91
|
+
// what to do with scalar types?
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
addChange((0, type_js_1.typeKindChanged)(oldType, newType));
|
|
95
|
+
}
|
|
96
|
+
if ((0, compare_js_1.isNotEqual)(oldType.description, newType.description)) {
|
|
97
|
+
if ((0, compare_js_1.isVoid)(oldType.description)) {
|
|
98
|
+
addChange((0, type_js_1.typeDescriptionAdded)(newType));
|
|
99
|
+
}
|
|
100
|
+
else if ((0, compare_js_1.isVoid)(newType.description)) {
|
|
101
|
+
addChange((0, type_js_1.typeDescriptionRemoved)(oldType));
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
addChange((0, type_js_1.typeDescriptionChanged)(oldType, newType));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.changesInUnion = void 0;
|
|
4
|
+
const compare_js_1 = require("../utils/compare.js");
|
|
5
|
+
const union_js_1 = require("./changes/union.js");
|
|
6
|
+
function changesInUnion(oldUnion, newUnion, addChange) {
|
|
7
|
+
const oldTypes = oldUnion.getTypes();
|
|
8
|
+
const newTypes = newUnion.getTypes();
|
|
9
|
+
(0, compare_js_1.compareLists)(oldTypes, newTypes, {
|
|
10
|
+
onAdded(t) {
|
|
11
|
+
addChange((0, union_js_1.unionMemberAdded)(newUnion, t));
|
|
12
|
+
},
|
|
13
|
+
onRemoved(t) {
|
|
14
|
+
addChange((0, union_js_1.unionMemberRemoved)(oldUnion, t));
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
exports.changesInUnion = changesInUnion;
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateTokenCount = exports.countDepth = exports.countDirectives = exports.calculateOperationComplexity = exports.countAliases = exports.validate = exports.getTypePrefix = exports.similar = exports.CriticalityLevel = exports.ChangeType = exports.DiffRule = exports.diff = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
tslib_1.__exportStar(require("./coverage/index.js"), exports);
|
|
6
|
+
var index_js_1 = require("./diff/index.js");
|
|
7
|
+
Object.defineProperty(exports, "diff", { enumerable: true, get: function () { return index_js_1.diff; } });
|
|
8
|
+
Object.defineProperty(exports, "DiffRule", { enumerable: true, get: function () { return index_js_1.DiffRule; } });
|
|
9
|
+
var change_js_1 = require("./diff/changes/change.js");
|
|
10
|
+
Object.defineProperty(exports, "ChangeType", { enumerable: true, get: function () { return change_js_1.ChangeType; } });
|
|
11
|
+
Object.defineProperty(exports, "CriticalityLevel", { enumerable: true, get: function () { return change_js_1.CriticalityLevel; } });
|
|
12
|
+
var index_js_2 = require("./similar/index.js");
|
|
13
|
+
Object.defineProperty(exports, "similar", { enumerable: true, get: function () { return index_js_2.similar; } });
|
|
14
|
+
var graphql_js_1 = require("./utils/graphql.js");
|
|
15
|
+
Object.defineProperty(exports, "getTypePrefix", { enumerable: true, get: function () { return graphql_js_1.getTypePrefix; } });
|
|
16
|
+
var index_js_3 = require("./validate/index.js");
|
|
17
|
+
Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return index_js_3.validate; } });
|
|
18
|
+
var alias_count_js_1 = require("./validate/alias-count.js");
|
|
19
|
+
Object.defineProperty(exports, "countAliases", { enumerable: true, get: function () { return alias_count_js_1.countAliases; } });
|
|
20
|
+
var complexity_js_1 = require("./validate/complexity.js");
|
|
21
|
+
Object.defineProperty(exports, "calculateOperationComplexity", { enumerable: true, get: function () { return complexity_js_1.calculateOperationComplexity; } });
|
|
22
|
+
var directive_count_js_1 = require("./validate/directive-count.js");
|
|
23
|
+
Object.defineProperty(exports, "countDirectives", { enumerable: true, get: function () { return directive_count_js_1.countDirectives; } });
|
|
24
|
+
var query_depth_js_1 = require("./validate/query-depth.js");
|
|
25
|
+
Object.defineProperty(exports, "countDepth", { enumerable: true, get: function () { return query_depth_js_1.countDepth; } });
|
|
26
|
+
var token_count_js_1 = require("./validate/token-count.js");
|
|
27
|
+
Object.defineProperty(exports, "calculateTokenCount", { enumerable: true, get: function () { return token_count_js_1.calculateTokenCount; } });
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.similar = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const graphql_js_1 = require("../utils/graphql.js");
|
|
6
|
+
const string_js_1 = require("../utils/string.js");
|
|
7
|
+
function similar(schema, typeName, threshold = 0.4) {
|
|
8
|
+
const typeMap = schema.getTypeMap();
|
|
9
|
+
const targets = Object.keys(schema.getTypeMap())
|
|
10
|
+
.filter(name => !(0, graphql_js_1.isPrimitive)(name) && !(0, graphql_js_1.isForIntrospection)(name))
|
|
11
|
+
.map(name => ({
|
|
12
|
+
typeId: name,
|
|
13
|
+
value: stripType(typeMap[name]),
|
|
14
|
+
}));
|
|
15
|
+
const results = {};
|
|
16
|
+
if (typeof typeName !== 'undefined' && !targets.some(t => t.typeId === typeName)) {
|
|
17
|
+
throw new Error(`Type '${typeName}' doesn't exist`);
|
|
18
|
+
}
|
|
19
|
+
(typeName ? [{ typeId: typeName, value: '' }] : targets).forEach(source => {
|
|
20
|
+
const sourceType = schema.getType(source.typeId);
|
|
21
|
+
const matchWith = targets.filter(target => schema.getType(target.typeId).astNode.kind === sourceType.astNode.kind &&
|
|
22
|
+
target.typeId !== source.typeId);
|
|
23
|
+
if (matchWith.length > 0) {
|
|
24
|
+
const found = similarTo(sourceType, matchWith, threshold);
|
|
25
|
+
if (found) {
|
|
26
|
+
results[source.typeId] = found;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return results;
|
|
31
|
+
}
|
|
32
|
+
exports.similar = similar;
|
|
33
|
+
function similarTo(type, targets, threshold) {
|
|
34
|
+
const types = targets.filter(target => target.typeId !== type.name);
|
|
35
|
+
const result = (0, string_js_1.findBestMatch)(stripType(type), types);
|
|
36
|
+
if (result.bestMatch.rating < threshold) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
bestMatch: result.bestMatch,
|
|
41
|
+
ratings: result.ratings
|
|
42
|
+
.filter(r => r.rating >= threshold && r.target !== result.bestMatch.target)
|
|
43
|
+
.sort((a, b) => a.rating - b.rating)
|
|
44
|
+
.reverse(),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function stripType(type) {
|
|
48
|
+
return (0, graphql_1.printType)(type)
|
|
49
|
+
.trim()
|
|
50
|
+
.replace(/^[a-z]+ [^{]+\{/g, '')
|
|
51
|
+
.replace(/\}$/g, '')
|
|
52
|
+
.trim()
|
|
53
|
+
.split('\n')
|
|
54
|
+
.map(s => s.trim())
|
|
55
|
+
.sort((a, b) => a.localeCompare(b))
|
|
56
|
+
.join(' ');
|
|
57
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformSchemaWithApollo = exports.transformDocumentWithApollo = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const graphql_js_1 = require("./graphql.js");
|
|
6
|
+
function transformDocumentWithApollo(doc, { keepClientFields }) {
|
|
7
|
+
return (0, graphql_1.visit)(doc, {
|
|
8
|
+
Field(node) {
|
|
9
|
+
return keepClientFields
|
|
10
|
+
? (0, graphql_js_1.removeDirectives)(node, ['client'])
|
|
11
|
+
: (0, graphql_js_1.removeFieldIfDirectives)(node, ['client']);
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
exports.transformDocumentWithApollo = transformDocumentWithApollo;
|
|
16
|
+
function transformSchemaWithApollo(schema) {
|
|
17
|
+
return (0, graphql_1.extendSchema)(schema, (0, graphql_1.parse)(/* GraphQL */ `
|
|
18
|
+
directive @connection(key: String!, filter: [String]) on FIELD
|
|
19
|
+
`));
|
|
20
|
+
}
|
|
21
|
+
exports.transformSchemaWithApollo = transformSchemaWithApollo;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compareLists = exports.diffArrays = exports.isVoid = exports.isNotEqual = exports.isEqual = exports.keyMap = void 0;
|
|
4
|
+
function keyMap(list, keyFn) {
|
|
5
|
+
return list.reduce((map, item) => {
|
|
6
|
+
map[keyFn(item)] = item;
|
|
7
|
+
return map;
|
|
8
|
+
}, Object.create(null));
|
|
9
|
+
}
|
|
10
|
+
exports.keyMap = keyMap;
|
|
11
|
+
function isEqual(a, b) {
|
|
12
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
13
|
+
if (a.length !== b.length)
|
|
14
|
+
return false;
|
|
15
|
+
for (let index = 0; index < a.length; index++) {
|
|
16
|
+
if (!isEqual(a[index], b[index])) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
if (a && b && typeof a === 'object' && typeof b === 'object') {
|
|
23
|
+
const aRecord = a;
|
|
24
|
+
const bRecord = b;
|
|
25
|
+
const aKeys = Object.keys(aRecord);
|
|
26
|
+
const bKeys = Object.keys(bRecord);
|
|
27
|
+
if (aKeys.length !== bKeys.length)
|
|
28
|
+
return false;
|
|
29
|
+
for (const key of aKeys) {
|
|
30
|
+
if (!isEqual(aRecord[key], bRecord[key])) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return a === b || (!a && !b);
|
|
37
|
+
}
|
|
38
|
+
exports.isEqual = isEqual;
|
|
39
|
+
function isNotEqual(a, b) {
|
|
40
|
+
return !isEqual(a, b);
|
|
41
|
+
}
|
|
42
|
+
exports.isNotEqual = isNotEqual;
|
|
43
|
+
function isVoid(a) {
|
|
44
|
+
return typeof a === 'undefined' || a === null;
|
|
45
|
+
}
|
|
46
|
+
exports.isVoid = isVoid;
|
|
47
|
+
function diffArrays(a, b) {
|
|
48
|
+
return a.filter(c => !b.some(d => isEqual(d, c)));
|
|
49
|
+
}
|
|
50
|
+
exports.diffArrays = diffArrays;
|
|
51
|
+
function compareLists(oldList, newList, callbacks) {
|
|
52
|
+
const oldMap = keyMap(oldList, ({ name }) => name);
|
|
53
|
+
const newMap = keyMap(newList, ({ name }) => name);
|
|
54
|
+
const added = [];
|
|
55
|
+
const removed = [];
|
|
56
|
+
const mutual = [];
|
|
57
|
+
for (const oldItem of oldList) {
|
|
58
|
+
const newItem = newMap[oldItem.name];
|
|
59
|
+
if (newItem === undefined) {
|
|
60
|
+
removed.push(oldItem);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
mutual.push({
|
|
64
|
+
newVersion: newItem,
|
|
65
|
+
oldVersion: oldItem,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
for (const newItem of newList) {
|
|
70
|
+
if (oldMap[newItem.name] === undefined) {
|
|
71
|
+
added.push(newItem);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (callbacks) {
|
|
75
|
+
if (callbacks.onAdded) {
|
|
76
|
+
added.forEach(callbacks.onAdded);
|
|
77
|
+
}
|
|
78
|
+
if (callbacks.onRemoved) {
|
|
79
|
+
removed.forEach(callbacks.onRemoved);
|
|
80
|
+
}
|
|
81
|
+
if (callbacks.onMutual) {
|
|
82
|
+
mutual.forEach(callbacks.onMutual);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
added,
|
|
87
|
+
removed,
|
|
88
|
+
mutual,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
exports.compareLists = compareLists;
|