@graphql-markdown/diff 1.1.10 → 1.1.12

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 CHANGED
@@ -1,13 +1,49 @@
1
+ /**
2
+ * Schema comparison module for GraphQL Markdown.
3
+ * Provides utilities to compare GraphQL schemas and detect changes.
4
+ * @module \@graphql-markdown/diff
5
+ */
1
6
  import { type Change } from "@graphql-inspector/core";
2
7
  import type { FunctionCheckSchemaChanges, GraphQLSchema } from "@graphql-markdown/types";
8
+ /** File name for storing schema hash */
3
9
  export declare const SCHEMA_HASH_FILE: ".schema";
10
+ /** File name for storing schema reference */
4
11
  export declare const SCHEMA_REF: "schema.graphql";
12
+ /**
13
+ * Comparison methods used to determine if a schema has changed.
14
+ */
5
15
  export declare enum CompareMethod {
16
+ /** Compare schemas by diffing the content */
6
17
  DIFF = "SCHEMA-DIFF",
18
+ /** Compare schemas by comparing hash values */
7
19
  HASH = "SCHEMA-HASH",
20
+ /** Force regeneration regardless of changes */
8
21
  FORCE = "FORCE",
22
+ /** Skip comparison and assume no changes */
9
23
  NONE = "NONE"
10
24
  }
25
+ /**
26
+ * Generates a SHA-256 hash for a GraphQL schema.
27
+ *
28
+ * @param schema - The GraphQL schema to generate a hash for
29
+ * @returns A SHA-256 hash string representing the schema
30
+ */
11
31
  export declare const getSchemaHash: (schema: GraphQLSchema) => string;
32
+ /**
33
+ * Compares a new schema against an existing schema file and returns the differences.
34
+ *
35
+ * @param schemaNew - The new GraphQL schema to compare
36
+ * @param schemaOldLocation - File path to the old schema
37
+ * @returns A promise resolving to an array of schema changes
38
+ */
12
39
  export declare const getDiff: (schemaNew: GraphQLSchema, schemaOldLocation: string) => Promise<Change[]>;
40
+ /**
41
+ * Checks if a schema has changed compared to a previous version.
42
+ * Uses either diff or hash-based comparison methods based on the method parameter.
43
+ *
44
+ * @param schema - The current GraphQL schema
45
+ * @param outputDir - Directory where schema or hash files will be saved
46
+ * @param method - Comparison method to use (defaults to DIFF)
47
+ * @returns A promise resolving to a boolean indicating whether the schema has changed
48
+ */
13
49
  export declare const checkSchemaChanges: FunctionCheckSchemaChanges;
package/dist/index.js CHANGED
@@ -1,4 +1,9 @@
1
1
  "use strict";
2
+ /**
3
+ * Schema comparison module for GraphQL Markdown.
4
+ * Provides utilities to compare GraphQL schemas and detect changes.
5
+ * @module \@graphql-markdown/diff
6
+ */
2
7
  Object.defineProperty(exports, "__esModule", { value: true });
3
8
  exports.checkSchemaChanges = exports.getDiff = exports.getSchemaHash = exports.CompareMethod = exports.SCHEMA_REF = exports.SCHEMA_HASH_FILE = void 0;
4
9
  const node_path_1 = require("node:path");
@@ -8,20 +13,42 @@ const core_1 = require("@graphql-inspector/core");
8
13
  const graphql_file_loader_1 = require("@graphql-tools/graphql-file-loader");
9
14
  const graphql_1 = require("@graphql-markdown/graphql");
10
15
  const utils_1 = require("@graphql-markdown/utils");
16
+ /** File name for storing schema hash */
11
17
  exports.SCHEMA_HASH_FILE = ".schema";
18
+ /** File name for storing schema reference */
12
19
  exports.SCHEMA_REF = "schema.graphql";
20
+ /**
21
+ * Comparison methods used to determine if a schema has changed.
22
+ */
13
23
  var CompareMethod;
14
24
  (function (CompareMethod) {
25
+ /** Compare schemas by diffing the content */
15
26
  CompareMethod["DIFF"] = "SCHEMA-DIFF";
27
+ /** Compare schemas by comparing hash values */
16
28
  CompareMethod["HASH"] = "SCHEMA-HASH";
29
+ /** Force regeneration regardless of changes */
17
30
  CompareMethod["FORCE"] = "FORCE";
31
+ /** Skip comparison and assume no changes */
18
32
  CompareMethod["NONE"] = "NONE";
19
33
  })(CompareMethod || (exports.CompareMethod = CompareMethod = {}));
34
+ /**
35
+ * Generates a SHA-256 hash for a GraphQL schema.
36
+ *
37
+ * @param schema - The GraphQL schema to generate a hash for
38
+ * @returns A SHA-256 hash string representing the schema
39
+ */
20
40
  const getSchemaHash = (schema) => {
21
41
  const printedSchema = (0, graphql_1.printSchema)(schema);
22
42
  return (0, node_crypto_1.createHash)("sha256").update(printedSchema).digest("hex");
23
43
  };
24
44
  exports.getSchemaHash = getSchemaHash;
45
+ /**
46
+ * Compares a new schema against an existing schema file and returns the differences.
47
+ *
48
+ * @param schemaNew - The new GraphQL schema to compare
49
+ * @param schemaOldLocation - File path to the old schema
50
+ * @returns A promise resolving to an array of schema changes
51
+ */
25
52
  const getDiff = async (schemaNew, schemaOldLocation) => {
26
53
  const schemaOld = await (0, load_1.loadSchema)(schemaOldLocation, {
27
54
  loaders: [new graphql_file_loader_1.GraphQLFileLoader()],
@@ -29,6 +56,15 @@ const getDiff = async (schemaNew, schemaOldLocation) => {
29
56
  return (0, core_1.diff)(schemaOld, schemaNew);
30
57
  };
31
58
  exports.getDiff = getDiff;
59
+ /**
60
+ * Checks if a schema has changed compared to a previous version.
61
+ * Uses either diff or hash-based comparison methods based on the method parameter.
62
+ *
63
+ * @param schema - The current GraphQL schema
64
+ * @param outputDir - Directory where schema or hash files will be saved
65
+ * @param method - Comparison method to use (defaults to DIFF)
66
+ * @returns A promise resolving to a boolean indicating whether the schema has changed
67
+ */
32
68
  const checkSchemaChanges = async (schema, outputDir, method = CompareMethod.DIFF) => {
33
69
  if (method.valueOf() === CompareMethod.DIFF.valueOf()) {
34
70
  const schemaRef = (0, node_path_1.join)(outputDir, exports.SCHEMA_REF);
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "bugs": {
6
6
  "url": "https://github.com/graphql-markdown/graphql-markdown/issues"
7
7
  },
8
- "version": "1.1.10",
8
+ "version": "1.1.12",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
@@ -57,13 +57,13 @@
57
57
  },
58
58
  "dependencies": {
59
59
  "@graphql-inspector/core": "^6.1.0",
60
- "@graphql-markdown/graphql": "^1.1.6",
61
- "@graphql-markdown/utils": "^1.8.0",
60
+ "@graphql-markdown/graphql": "^1.1.8",
61
+ "@graphql-markdown/utils": "^1.9.0",
62
62
  "@graphql-tools/graphql-file-loader": "^8.0.1",
63
63
  "@graphql-tools/load": "^8.0.2"
64
64
  },
65
65
  "devDependencies": {
66
- "@graphql-markdown/types": "^1.7.0"
66
+ "@graphql-markdown/types": "^1.8.0"
67
67
  },
68
68
  "resolutions": {
69
69
  "braces": "3.0.3"