@graphql-markdown/diff 1.1.0-next.0 → 1.1.1
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/dist/index.d.ts +13 -0
- package/dist/index.js +53 -0
- package/package.json +5 -5
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Change } from "@graphql-inspector/core";
|
|
2
|
+
import type { FunctionCheckSchemaChanges, GraphQLSchema } from "@graphql-markdown/types";
|
|
3
|
+
export declare const SCHEMA_HASH_FILE: ".schema";
|
|
4
|
+
export declare const SCHEMA_REF: "schema.graphql";
|
|
5
|
+
export declare enum CompareMethod {
|
|
6
|
+
DIFF = "SCHEMA-DIFF",
|
|
7
|
+
HASH = "SCHEMA-HASH",
|
|
8
|
+
FORCE = "FORCE",
|
|
9
|
+
NONE = "NONE"
|
|
10
|
+
}
|
|
11
|
+
export declare const getSchemaHash: (schema: GraphQLSchema) => string;
|
|
12
|
+
export declare const getDiff: (schemaNew: GraphQLSchema, schemaOldLocation: string) => Promise<Change[]>;
|
|
13
|
+
export declare const checkSchemaChanges: FunctionCheckSchemaChanges;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkSchemaChanges = exports.getDiff = exports.getSchemaHash = exports.CompareMethod = exports.SCHEMA_REF = exports.SCHEMA_HASH_FILE = void 0;
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
const node_crypto_1 = require("node:crypto");
|
|
6
|
+
const load_1 = require("@graphql-tools/load");
|
|
7
|
+
const core_1 = require("@graphql-inspector/core");
|
|
8
|
+
const graphql_file_loader_1 = require("@graphql-tools/graphql-file-loader");
|
|
9
|
+
const graphql_1 = require("@graphql-markdown/graphql");
|
|
10
|
+
const utils_1 = require("@graphql-markdown/utils");
|
|
11
|
+
exports.SCHEMA_HASH_FILE = ".schema";
|
|
12
|
+
exports.SCHEMA_REF = "schema.graphql";
|
|
13
|
+
var CompareMethod;
|
|
14
|
+
(function (CompareMethod) {
|
|
15
|
+
CompareMethod["DIFF"] = "SCHEMA-DIFF";
|
|
16
|
+
CompareMethod["HASH"] = "SCHEMA-HASH";
|
|
17
|
+
CompareMethod["FORCE"] = "FORCE";
|
|
18
|
+
CompareMethod["NONE"] = "NONE";
|
|
19
|
+
})(CompareMethod || (exports.CompareMethod = CompareMethod = {}));
|
|
20
|
+
const getSchemaHash = (schema) => {
|
|
21
|
+
const printedSchema = (0, graphql_1.printSchema)(schema);
|
|
22
|
+
return (0, node_crypto_1.createHash)("sha256").update(printedSchema).digest("hex");
|
|
23
|
+
};
|
|
24
|
+
exports.getSchemaHash = getSchemaHash;
|
|
25
|
+
const getDiff = async (schemaNew, schemaOldLocation) => {
|
|
26
|
+
const schemaOld = await (0, load_1.loadSchema)(schemaOldLocation, {
|
|
27
|
+
loaders: [new graphql_file_loader_1.GraphQLFileLoader()],
|
|
28
|
+
});
|
|
29
|
+
return (0, core_1.diff)(schemaOld, schemaNew);
|
|
30
|
+
};
|
|
31
|
+
exports.getDiff = getDiff;
|
|
32
|
+
const checkSchemaChanges = async (schema, outputDir, method = CompareMethod.DIFF) => {
|
|
33
|
+
if (method === CompareMethod.DIFF) {
|
|
34
|
+
const schemaRef = (0, node_path_1.join)(outputDir, exports.SCHEMA_REF);
|
|
35
|
+
if (await (0, utils_1.fileExists)(schemaRef)) {
|
|
36
|
+
const schemaDiff = await (0, exports.getDiff)(schema, schemaRef);
|
|
37
|
+
return schemaDiff.length > 0;
|
|
38
|
+
}
|
|
39
|
+
const schemaPrint = (0, graphql_1.printSchema)(schema);
|
|
40
|
+
await (0, utils_1.saveFile)(schemaRef, schemaPrint);
|
|
41
|
+
}
|
|
42
|
+
if (method === CompareMethod.HASH) {
|
|
43
|
+
const hashFile = (0, node_path_1.join)(outputDir, exports.SCHEMA_HASH_FILE);
|
|
44
|
+
const hashSchema = (0, exports.getSchemaHash)(schema);
|
|
45
|
+
if (await (0, utils_1.fileExists)(hashFile)) {
|
|
46
|
+
const hash = await (0, utils_1.readFile)(hashFile, { encoding: "utf8", flag: "r" });
|
|
47
|
+
return hashSchema !== hash;
|
|
48
|
+
}
|
|
49
|
+
await (0, utils_1.saveFile)(hashFile, hashSchema);
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
};
|
|
53
|
+
exports.checkSchemaChanges = checkSchemaChanges;
|
package/package.json
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/graphql-markdown/graphql-markdown/issues"
|
|
7
7
|
},
|
|
8
|
-
"version": "1.1.
|
|
8
|
+
"version": "1.1.1",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "graphql-markdown/graphql-markdown",
|
|
12
|
+
"url": "git+https://github.com/graphql-markdown/graphql-markdown.git",
|
|
13
13
|
"directory": "packages/diff"
|
|
14
14
|
},
|
|
15
15
|
"author": {
|
|
@@ -56,13 +56,13 @@
|
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@graphql-inspector/core": "^5.0.0",
|
|
59
|
-
"@graphql-markdown/graphql": "^1.0.
|
|
60
|
-
"@graphql-markdown/utils": "^1.6.
|
|
59
|
+
"@graphql-markdown/graphql": "^1.0.1",
|
|
60
|
+
"@graphql-markdown/utils": "^1.6.1",
|
|
61
61
|
"@graphql-tools/graphql-file-loader": "^8.0.0",
|
|
62
62
|
"@graphql-tools/load": "^8.0.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@graphql-markdown/types": "^1.0.0
|
|
65
|
+
"@graphql-markdown/types": "^1.0.0"
|
|
66
66
|
},
|
|
67
67
|
"directories": {
|
|
68
68
|
"test": "tests"
|