@graphql-markdown/diff 1.0.13 → 1.1.0-next.0
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/package.json +51 -7
- package/src/index.js +0 -67
package/package.json
CHANGED
|
@@ -5,28 +5,65 @@
|
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/graphql-markdown/graphql-markdown/issues"
|
|
7
7
|
},
|
|
8
|
-
"version": "1.0.
|
|
8
|
+
"version": "1.1.0-next.0",
|
|
9
9
|
"license": "MIT",
|
|
10
|
-
"main": "src/index.js",
|
|
11
10
|
"repository": {
|
|
12
11
|
"type": "git",
|
|
13
|
-
"url": "
|
|
12
|
+
"url": "graphql-markdown/graphql-markdown",
|
|
13
|
+
"directory": "packages/diff"
|
|
14
14
|
},
|
|
15
15
|
"author": {
|
|
16
16
|
"name": "Gregory Heitz"
|
|
17
17
|
},
|
|
18
|
+
"main": "dist/index.js",
|
|
19
|
+
"types": "dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"require": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"import": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"default": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"default": "./dist/index.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"./*": {
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"default": "./dist/index.js"
|
|
39
|
+
},
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./dist/index.d.ts",
|
|
42
|
+
"default": "./dist/index.js"
|
|
43
|
+
},
|
|
44
|
+
"default": {
|
|
45
|
+
"types": "./dist/index.d.ts",
|
|
46
|
+
"default": "./dist/index.js"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"./package.json": "./package.json"
|
|
50
|
+
},
|
|
18
51
|
"scripts": {
|
|
19
52
|
"prepack": "pinst --disable",
|
|
20
53
|
"postpack": "pinst --enable",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
54
|
+
"stryker": "stryker run",
|
|
55
|
+
"clean": "rm -rf ./dist"
|
|
23
56
|
},
|
|
24
57
|
"dependencies": {
|
|
25
58
|
"@graphql-inspector/core": "^5.0.0",
|
|
26
|
-
"@graphql-markdown/
|
|
59
|
+
"@graphql-markdown/graphql": "^1.0.0-next.0",
|
|
60
|
+
"@graphql-markdown/utils": "^1.6.0-next.0",
|
|
27
61
|
"@graphql-tools/graphql-file-loader": "^8.0.0",
|
|
28
62
|
"@graphql-tools/load": "^8.0.0"
|
|
29
63
|
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@graphql-markdown/types": "^1.0.0-next.0"
|
|
66
|
+
},
|
|
30
67
|
"directories": {
|
|
31
68
|
"test": "tests"
|
|
32
69
|
},
|
|
@@ -34,6 +71,13 @@
|
|
|
34
71
|
"node": ">=16.14"
|
|
35
72
|
},
|
|
36
73
|
"publishConfig": {
|
|
74
|
+
"directory": "dist",
|
|
37
75
|
"access": "public"
|
|
38
|
-
}
|
|
76
|
+
},
|
|
77
|
+
"typescript": {
|
|
78
|
+
"definition": "dist/index.d.ts"
|
|
79
|
+
},
|
|
80
|
+
"files": [
|
|
81
|
+
"dist"
|
|
82
|
+
]
|
|
39
83
|
}
|
package/src/index.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
const path = require("path");
|
|
2
|
-
const crypto = require("crypto");
|
|
3
|
-
|
|
4
|
-
const { loadSchema } = require("@graphql-tools/load");
|
|
5
|
-
const { diff } = require("@graphql-inspector/core");
|
|
6
|
-
const { GraphQLFileLoader } = require("@graphql-tools/graphql-file-loader");
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
fs: { fileExists, readFile, saveFile },
|
|
10
|
-
graphql: { printSchema },
|
|
11
|
-
} = require("@graphql-markdown/utils");
|
|
12
|
-
|
|
13
|
-
const SCHEMA_HASH_FILE = ".schema";
|
|
14
|
-
const SCHEMA_REF = "schema.graphql";
|
|
15
|
-
const COMPARE_METHOD = {
|
|
16
|
-
DIFF: "SCHEMA-DIFF",
|
|
17
|
-
HASH: "SCHEMA-HASH",
|
|
18
|
-
FORCE: "FORCE",
|
|
19
|
-
NONE: "NONE",
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
function getSchemaHash(schema) {
|
|
23
|
-
const printedSchema = printSchema(schema, { commentDescriptions: true });
|
|
24
|
-
return crypto.createHash("sha256").update(printedSchema).digest("hex");
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async function getDiff(schemaNew, schemaOldLocation) {
|
|
28
|
-
const schemaOld = await loadSchema(schemaOldLocation, {
|
|
29
|
-
loaders: [new GraphQLFileLoader()],
|
|
30
|
-
});
|
|
31
|
-
return diff(schemaOld, schemaNew);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async function checkSchemaChanges(
|
|
35
|
-
schema,
|
|
36
|
-
outputDir,
|
|
37
|
-
method = COMPARE_METHOD.DIFF,
|
|
38
|
-
) {
|
|
39
|
-
if (method === COMPARE_METHOD.DIFF) {
|
|
40
|
-
const schemaRef = path.join(outputDir, SCHEMA_REF);
|
|
41
|
-
if (await fileExists(schemaRef)) {
|
|
42
|
-
const schemaDiff = await getDiff(schema, schemaRef);
|
|
43
|
-
return schemaDiff.length > 0;
|
|
44
|
-
}
|
|
45
|
-
const schemaPrint = printSchema(schema);
|
|
46
|
-
await saveFile(schemaRef, schemaPrint);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (method === COMPARE_METHOD.HASH) {
|
|
50
|
-
const hashFile = path.join(outputDir, SCHEMA_HASH_FILE);
|
|
51
|
-
const hashSchema = getSchemaHash(schema);
|
|
52
|
-
if (await fileExists(hashFile)) {
|
|
53
|
-
const hash = await readFile(hashFile, { encoding: "utf8", flag: "r" });
|
|
54
|
-
return hashSchema !== hash;
|
|
55
|
-
}
|
|
56
|
-
await saveFile(hashFile, hashSchema);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
module.exports = {
|
|
63
|
-
checkSchemaChanges,
|
|
64
|
-
COMPARE_METHOD,
|
|
65
|
-
SCHEMA_HASH_FILE,
|
|
66
|
-
SCHEMA_REF,
|
|
67
|
-
};
|