@graphql-markdown/printer-legacy 1.13.1 → 1.15.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.
Files changed (55) hide show
  1. package/dist/const/options.d.ts +15 -2
  2. package/dist/const/options.d.ts.map +1 -1
  3. package/dist/const/options.js +20 -6
  4. package/dist/const/strings.d.ts +15 -0
  5. package/dist/const/strings.d.ts.map +1 -1
  6. package/dist/const/strings.js +9 -0
  7. package/dist/directive.d.ts +3 -3
  8. package/dist/directive.d.ts.map +1 -1
  9. package/dist/directive.js +8 -4
  10. package/dist/events.d.ts +77 -0
  11. package/dist/events.d.ts.map +1 -0
  12. package/dist/events.js +85 -0
  13. package/dist/example.d.ts.map +1 -1
  14. package/dist/example.js +12 -7
  15. package/dist/format-helpers.d.ts +9 -0
  16. package/dist/format-helpers.d.ts.map +1 -1
  17. package/dist/format-helpers.js +10 -1
  18. package/dist/formatter.js +1 -1
  19. package/dist/graphql/directive.d.ts +3 -3
  20. package/dist/graphql/directive.d.ts.map +1 -1
  21. package/dist/graphql/directive.js +3 -3
  22. package/dist/graphql/enum.d.ts +3 -3
  23. package/dist/graphql/enum.d.ts.map +1 -1
  24. package/dist/graphql/enum.js +2 -2
  25. package/dist/graphql/input.d.ts +13 -0
  26. package/dist/graphql/input.d.ts.map +1 -1
  27. package/dist/graphql/input.js +8 -0
  28. package/dist/graphql/object.d.ts +3 -3
  29. package/dist/graphql/object.d.ts.map +1 -1
  30. package/dist/graphql/object.js +4 -4
  31. package/dist/graphql/operation.d.ts +6 -7
  32. package/dist/graphql/operation.d.ts.map +1 -1
  33. package/dist/graphql/operation.js +41 -8
  34. package/dist/graphql/scalar.d.ts +5 -5
  35. package/dist/graphql/scalar.d.ts.map +1 -1
  36. package/dist/graphql/scalar.js +7 -7
  37. package/dist/graphql/union.d.ts +3 -3
  38. package/dist/graphql/union.d.ts.map +1 -1
  39. package/dist/graphql/union.js +2 -2
  40. package/dist/group.d.ts.map +1 -1
  41. package/dist/group.js +7 -6
  42. package/dist/index.d.ts +2 -0
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +5 -1
  45. package/dist/link.d.ts +2 -2
  46. package/dist/link.d.ts.map +1 -1
  47. package/dist/link.js +54 -13
  48. package/dist/mdx/index.js +2 -2
  49. package/dist/printer.d.ts +67 -22
  50. package/dist/printer.d.ts.map +1 -1
  51. package/dist/printer.js +270 -117
  52. package/dist/section.d.ts +3 -3
  53. package/dist/section.d.ts.map +1 -1
  54. package/dist/section.js +34 -13
  55. package/package.json +19 -10
@@ -1 +1 @@
1
- {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/graphql/object.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AA8BhE;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,sDAa/B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,sEAgCzB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,sDAK3B,CAAC"}
1
+ {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/graphql/object.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,KAAK,EACL,WAAW,EACX,gBAAgB,EACjB,MAAM,yBAAyB,CAAC;AA8BjC;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,oEAa/B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,sEAgCzB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,sDAK3B,CAAC"}
@@ -13,14 +13,14 @@ const strings_1 = require("../const/strings");
13
13
  * Prints the metadata section for interfaces implemented by a GraphQL type
14
14
  * @param type - The GraphQL type object to process
15
15
  * @param options - Printing options
16
- * @returns Markdown formatted string of implemented interfaces
16
+ * @returns An "Interfaces" PageSection, or undefined when the type has no interfaces
17
17
  */
18
18
  const printImplementedInterfaceMetadata = (type, options) => {
19
19
  if (typeof type !== "object" ||
20
20
  type === null ||
21
21
  !("getInterfaces" in type) ||
22
22
  typeof type.getInterfaces !== "function") {
23
- return "";
23
+ return undefined;
24
24
  }
25
25
  return (0, section_1.printSection)(type.getInterfaces(), "Interfaces", options);
26
26
  };
@@ -28,12 +28,12 @@ const printImplementedInterfaceMetadata = (type, options) => {
28
28
  * Prints the complete metadata section for a GraphQL object type
29
29
  * @param type - The GraphQL type object to process
30
30
  * @param options - Printing options
31
- * @returns Markdown formatted string containing fields and interfaces metadata
31
+ * @returns Ordered metadata sections for fields and interfaces
32
32
  */
33
33
  const printObjectMetadata = (type, options) => {
34
34
  const interfaceMeta = printImplementedInterfaceMetadata(type, options);
35
35
  const metadata = (0, section_1.printMetadataSection)(type, (0, graphql_1.getFields)(type), "Fields", options);
36
- return `${metadata}${interfaceMeta}`;
36
+ return [metadata, interfaceMeta].filter(Boolean);
37
37
  };
38
38
  exports.printObjectMetadata = printObjectMetadata;
39
39
  /**
@@ -3,24 +3,23 @@
3
3
  * Provides utilities to print operation types, metadata, and code representations.
4
4
  * @module
5
5
  */
6
- import type { PrintTypeOptions, MDXString } from "@graphql-markdown/types";
6
+ import type { PrintTypeOptions, MDXString, Maybe, PageSection } from "@graphql-markdown/types";
7
7
  /**
8
8
  * Prints the operation type information.
9
9
  * @param type - The operation type to print
10
10
  * @param options - Print type options for customizing output
11
- * @returns Formatted string representation of the operation type or empty string if invalid
11
+ * @returns A "Type" PageSection, or undefined when `type` is not an operation
12
12
  */
13
- export declare const printOperationType: (type: unknown, options: PrintTypeOptions) => string | MDXString;
13
+ export declare const printOperationType: (type: unknown, options: PrintTypeOptions) => Maybe<PageSection>;
14
14
  /**
15
15
  * Prints the operation metadata including arguments and type information.
16
16
  * @param type - The operation type to print metadata for
17
17
  * @param options - Print type options for customizing output
18
- * @returns Formatted string containing operation metadata or empty string if invalid
18
+ * @returns Ordered operation metadata sections, or undefined when `type` is not an operation
19
19
  */
20
- export declare const printOperationMetadata: (type: unknown, options: PrintTypeOptions) => string | MDXString;
20
+ export declare const printOperationMetadata: (type: unknown, options: PrintTypeOptions) => Maybe<PageSection[]>;
21
21
  /**
22
22
  * Prints the code representation of an operation.
23
- * @see printCodeField
24
23
  */
25
- export { printCodeField as printCodeOperation } from "../code";
24
+ export declare const printCodeOperation: (type: unknown, options?: PrintTypeOptions | undefined) => string | MDXString;
26
25
  //# sourceMappingURL=operation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/graphql/operation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAI3E;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,kEAa9B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,kEAYlC,CAAC;AAEF;;;GAGG;AACH,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/graphql/operation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,SAAS,EACT,KAAK,EACL,WAAW,EACZ,MAAM,yBAAyB,CAAC;AAMjC;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,kEAa9B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,oEAYlC,CAAC;AAkCF;;GAEG;AACH,eAAO,MAAM,kBAAkB,+EAc9B,CAAC"}
@@ -7,16 +7,18 @@
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.printCodeOperation = exports.printOperationMetadata = exports.printOperationType = void 0;
9
9
  const graphql_1 = require("@graphql-markdown/graphql");
10
+ const strings_1 = require("../const/strings");
11
+ const code_1 = require("../code");
10
12
  const section_1 = require("../section");
11
13
  /**
12
14
  * Prints the operation type information.
13
15
  * @param type - The operation type to print
14
16
  * @param options - Print type options for customizing output
15
- * @returns Formatted string representation of the operation type or empty string if invalid
17
+ * @returns A "Type" PageSection, or undefined when `type` is not an operation
16
18
  */
17
19
  const printOperationType = (type, options) => {
18
20
  if (!(0, graphql_1.isOperation)(type)) {
19
- return "";
21
+ return undefined;
20
22
  }
21
23
  const queryType = (0, graphql_1.getTypeName)(type.type).replaceAll(/[![\]]*/g, "");
22
24
  return (0, section_1.printSection)([options.schema.getType(queryType)], "Type", {
@@ -29,20 +31,51 @@ exports.printOperationType = printOperationType;
29
31
  * Prints the operation metadata including arguments and type information.
30
32
  * @param type - The operation type to print metadata for
31
33
  * @param options - Print type options for customizing output
32
- * @returns Formatted string containing operation metadata or empty string if invalid
34
+ * @returns Ordered operation metadata sections, or undefined when `type` is not an operation
33
35
  */
34
36
  const printOperationMetadata = (type, options) => {
35
37
  if (!(0, graphql_1.isOperation)(type)) {
36
- return "";
38
+ return undefined;
37
39
  }
38
40
  const response = (0, exports.printOperationType)(type, options);
39
41
  const metadata = (0, section_1.printMetadataSection)(type, type.args, "Arguments", options);
40
- return `${metadata}${response}`;
42
+ return [metadata, response].filter(Boolean);
41
43
  };
42
44
  exports.printOperationMetadata = printOperationMetadata;
45
+ /**
46
+ * Wraps a GraphQL operation snippet in one or more namespace blocks.
47
+ */
48
+ const wrapOperationCodeWithNamespaces = (operationCode, operationNamespaceParts) => {
49
+ if (operationNamespaceParts.length === 0 || operationCode.trim() === "") {
50
+ return operationCode;
51
+ }
52
+ let lines = operationCode
53
+ .trimEnd()
54
+ .split(strings_1.MARKDOWN_EOL)
55
+ .filter((line) => {
56
+ return line.length > 0;
57
+ });
58
+ for (let i = operationNamespaceParts.length - 1; i >= 0; i -= 1) {
59
+ const namespace = operationNamespaceParts[i];
60
+ lines = [
61
+ `${namespace} {`,
62
+ ...lines.map((line) => {
63
+ return `${strings_1.MARKDOWN_CODE_INDENTATION}${line}`;
64
+ }),
65
+ `}`,
66
+ ];
67
+ }
68
+ return `${lines.join(strings_1.MARKDOWN_EOL)}${strings_1.MARKDOWN_EOL}`;
69
+ };
43
70
  /**
44
71
  * Prints the code representation of an operation.
45
- * @see printCodeField
46
72
  */
47
- const code_1 = require("../code");
48
- Object.defineProperty(exports, "printCodeOperation", { enumerable: true, get: function () { return code_1.printCodeField; } });
73
+ const printCodeOperation = (type, options) => {
74
+ const code = (0, code_1.printCodeField)(type, options);
75
+ if (!Array.isArray(options?.operationNamespaceParts) ||
76
+ options.operationNamespaceParts.length === 0) {
77
+ return code;
78
+ }
79
+ return wrapOperationCodeWithNamespaces(code, options.operationNamespaceParts);
80
+ };
81
+ exports.printCodeOperation = printCodeOperation;
@@ -2,22 +2,22 @@
2
2
  * Provides utility functions for handling GraphQL scalar types in markdown generation.
3
3
  * @module
4
4
  */
5
- import type { PrintTypeOptions, MDXString } from "@graphql-markdown/types";
5
+ import type { PrintTypeOptions, PageSection, Maybe } from "@graphql-markdown/types";
6
6
  /**
7
7
  * Generates markdown documentation for a scalar type's specification URL.
8
8
  * @param type - The GraphQL scalar type object
9
9
  * @param options - Options for printing type information
10
- * @returns Markdown string containing the specification link, or empty string if no URL exists
10
+ * @returns A specification PageSection, or undefined when no URL exists
11
11
  */
12
- export declare const printSpecification: (type: unknown, options: PrintTypeOptions) => string | MDXString;
12
+ export declare const printSpecification: (type: unknown, options: PrintTypeOptions) => Maybe<PageSection>;
13
13
  /**
14
14
  * Prints metadata information for a scalar type.
15
15
  * Currently only includes the specification URL if available.
16
16
  * @param type - The GraphQL scalar type object
17
17
  * @param options - Options for printing type information
18
- * @returns Markdown string containing the scalar metadata
18
+ * @returns A scalar metadata PageSection, or undefined when not available
19
19
  */
20
- export declare const printScalarMetadata: (type: unknown, options: PrintTypeOptions) => string | MDXString;
20
+ export declare const printScalarMetadata: (type: unknown, options: PrintTypeOptions) => Maybe<PageSection>;
21
21
  /**
22
22
  * Generates the GraphQL SDL representation of a scalar type.
23
23
  * @param type - The GraphQL scalar type object
@@ -1 +1 @@
1
- {"version":3,"file":"scalar.d.ts","sourceRoot":"","sources":["../../src/graphql/scalar.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAO3E;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,kEAiB9B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,kEAK/B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,mEAK3B,CAAC"}
1
+ {"version":3,"file":"scalar.d.ts","sourceRoot":"","sources":["../../src/graphql/scalar.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,KAAK,EACN,MAAM,yBAAyB,CAAC;AAIjC;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,kEAmB9B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,kEAK/B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,mEAK3B,CAAC"}
@@ -2,24 +2,24 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.printCodeScalar = exports.printScalarMetadata = exports.printSpecification = void 0;
4
4
  const graphql_1 = require("@graphql-markdown/graphql");
5
- const strings_1 = require("../const/strings");
6
- const options_1 = require("../const/options");
7
5
  /**
8
6
  * Generates markdown documentation for a scalar type's specification URL.
9
7
  * @param type - The GraphQL scalar type object
10
8
  * @param options - Options for printing type information
11
- * @returns Markdown string containing the specification link, or empty string if no URL exists
9
+ * @returns A specification PageSection, or undefined when no URL exists
12
10
  */
13
11
  const printSpecification = (type, options) => {
14
12
  if (typeof type !== "object" ||
15
13
  type === null ||
16
14
  !("specifiedByURL" in type) ||
17
15
  typeof type.specifiedByURL !== "string") {
18
- return "";
16
+ return undefined;
19
17
  }
20
18
  const url = type.specifiedByURL;
21
- // Needs newline between "export const specifiedByLinkCss" and markdown header to prevent compilation error in docusaurus
22
- return `${options_1.SectionLevels.LEVEL.repeat(3)} ${options.formatMDXSpecifiedByLink(url)}${strings_1.MARKDOWN_EOP}`;
19
+ return {
20
+ title: options.formatMDXSpecifiedByLink(url),
21
+ level: 3,
22
+ };
23
23
  };
24
24
  exports.printSpecification = printSpecification;
25
25
  /**
@@ -27,7 +27,7 @@ exports.printSpecification = printSpecification;
27
27
  * Currently only includes the specification URL if available.
28
28
  * @param type - The GraphQL scalar type object
29
29
  * @param options - Options for printing type information
30
- * @returns Markdown string containing the scalar metadata
30
+ * @returns A scalar metadata PageSection, or undefined when not available
31
31
  */
32
32
  const printScalarMetadata = (type, options) => {
33
33
  return (0, exports.printSpecification)(type, options);
@@ -2,14 +2,14 @@
2
2
  * Module for handling GraphQL Union type printing operations.
3
3
  * @module
4
4
  */
5
- import type { PrintTypeOptions, MDXString } from "@graphql-markdown/types";
5
+ import type { PrintTypeOptions, PageSection, Maybe } from "@graphql-markdown/types";
6
6
  /**
7
7
  * Generates metadata documentation for a GraphQL Union type.
8
8
  * @param type - The GraphQL type to process
9
9
  * @param options - Configuration options for printing
10
- * @returns Formatted MDX string containing the union type's possible types
10
+ * @returns A "Possible types" PageSection, or undefined when `type` is not a union
11
11
  */
12
- export declare const printUnionMetadata: (type: unknown, options: PrintTypeOptions) => string | MDXString;
12
+ export declare const printUnionMetadata: (type: unknown, options: PrintTypeOptions) => Maybe<PageSection>;
13
13
  /**
14
14
  * Generates GraphQL SDL code representation of a Union type.
15
15
  * @param type - The GraphQL type to process
@@ -1 +1 @@
1
- {"version":3,"file":"union.d.ts","sourceRoot":"","sources":["../../src/graphql/union.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,SAAS,EAEV,MAAM,yBAAyB,CAAC;AAMjC;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,kEAY9B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,mEAiB1B,CAAC"}
1
+ {"version":3,"file":"union.d.ts","sourceRoot":"","sources":["../../src/graphql/union.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAEhB,WAAW,EACX,KAAK,EACN,MAAM,yBAAyB,CAAC;AAMjC;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,kEAY9B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,mEAiB1B,CAAC"}
@@ -11,11 +11,11 @@ const section_1 = require("../section");
11
11
  * Generates metadata documentation for a GraphQL Union type.
12
12
  * @param type - The GraphQL type to process
13
13
  * @param options - Configuration options for printing
14
- * @returns Formatted MDX string containing the union type's possible types
14
+ * @returns A "Possible types" PageSection, or undefined when `type` is not a union
15
15
  */
16
16
  const printUnionMetadata = (type, options) => {
17
17
  if (!(0, graphql_1.isUnionType)(type)) {
18
- return "";
18
+ return undefined;
19
19
  }
20
20
  return (0, section_1.printSection)(type.getTypes(), "Possible types", {
21
21
  ...options,
@@ -1 +1 @@
1
- {"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAEV,YAAY,EAEZ,KAAK,EACN,MAAM,yBAAyB,CAAC;AAMjC;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,2IA+BpB,CAAC"}
1
+ {"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAEV,YAAY,EAEZ,KAAK,EACN,MAAM,yBAAyB,CAAC;AAMjC;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,2IA6BpB,CAAC"}
package/dist/group.js CHANGED
@@ -20,15 +20,16 @@ const getGroup = (type, groups, typeCategory) => {
20
20
  return "";
21
21
  }
22
22
  const graphQLNamedType = (0, graphql_1.getNamedType)(type);
23
- if (!graphQLNamedType) {
23
+ const typeName = (0, utils_1.hasStringProperty)(graphQLNamedType, "name")
24
+ ? graphQLNamedType.name
25
+ : "";
26
+ if (!typeName) {
24
27
  return "";
25
28
  }
26
- const typeName = "name" in graphQLNamedType
27
- ? graphQLNamedType.name
28
- : String(graphQLNamedType);
29
- if (!(typeCategory in groups && typeName in groups[typeCategory])) {
29
+ const categoryGroups = groups[typeCategory];
30
+ if (!categoryGroups || !(typeName in categoryGroups)) {
30
31
  return "";
31
32
  }
32
- return (0, utils_1.slugify)(groups[typeCategory][typeName]);
33
+ return (0, utils_1.slugify)(categoryGroups[typeName]);
33
34
  };
34
35
  exports.getGroup = getGroup;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export { Printer } from "./printer";
2
+ export { PrintCodeEvent, PrintTypeEvent, BeforeComposePageTypeEvent, } from "./events";
3
+ export type { PageSection, PageSections, PrintCodeEventData, PrintTypeEventData, ComposePageTypeEventData, } from "./events";
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,cAAc,EACd,cAAc,EACd,0BAA0B,GAC3B,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Printer = void 0;
3
+ exports.BeforeComposePageTypeEvent = exports.PrintTypeEvent = exports.PrintCodeEvent = exports.Printer = void 0;
4
4
  const printer_1 = require("./printer");
5
5
  Object.defineProperty(exports, "Printer", { enumerable: true, get: function () { return printer_1.Printer; } });
6
+ const events_1 = require("./events");
7
+ Object.defineProperty(exports, "PrintCodeEvent", { enumerable: true, get: function () { return events_1.PrintCodeEvent; } });
8
+ Object.defineProperty(exports, "PrintTypeEvent", { enumerable: true, get: function () { return events_1.PrintTypeEvent; } });
9
+ Object.defineProperty(exports, "BeforeComposePageTypeEvent", { enumerable: true, get: function () { return events_1.BeforeComposePageTypeEvent; } });
package/dist/link.d.ts CHANGED
@@ -88,11 +88,11 @@ export declare const printLinkAttributes: (type: unknown, text?: Maybe<string>)
88
88
  /**
89
89
  * Prints a link for a GraphQL type based on the provided options.
90
90
  *
91
- * @param type - The GraphQL type to print a link for
91
+ * @param arg - The GraphQL type or link object to print a link for
92
92
  * @param options - Configuration options for link generation
93
93
  * @returns The formatted link as a string
94
94
  */
95
- export declare const printLink: (type: unknown, options: PrintLinkOptions) => string;
95
+ export declare const printLink: <T>(arg: T | Maybe<TypeLink>, options: PrintLinkOptions) => string;
96
96
  /**
97
97
  * Prints a parent link for a GraphQL type based on the provided options.
98
98
  *
@@ -1 +1 @@
1
- {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../src/link.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,oBAAoB,EAGpB,SAAS,EACT,KAAK,EACL,gBAAgB,EAChB,gBAAgB,EAEhB,oBAAoB,EAGpB,QAAQ,EACR,UAAU,EACX,MAAM,yBAAyB,CAAC;AA2BjC,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,oBAAoB,CAG5C,CAAC;AAEX;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,oIA+BjC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,sCAoB7B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,uEAuBjC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,wCAEnC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,wCAO/B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,2EASjC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,gEAKnC,CAAC;AASF;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM,oGAsElB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,4FAc3B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,iDAqB/B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,sDAuBrB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,kEAc3B,CAAC"}
1
+ {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../src/link.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,oBAAoB,EAEpB,SAAS,EACT,KAAK,EACL,gBAAgB,EAChB,gBAAgB,EAEhB,oBAAoB,EAGpB,QAAQ,EACR,UAAU,EACX,MAAM,yBAAyB,CAAC;AAgCjC,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,oBAAoB,CAG5C,CAAC;AAEX;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,oIA+BjC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,sCAoB7B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,uEAuBjC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,wCAEnC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,wCAO/B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,2EASjC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,gEAKnC,CAAC;AASF;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM,oGAuFlB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,4FAc3B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,iDAqB/B,CAAC;AAoBF;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,gEAmC1B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,kEAc3B,CAAC"}
package/dist/link.js CHANGED
@@ -38,7 +38,7 @@ const hasPrintableDirective = (type, options) => {
38
38
  const onlyDirective = "onlyDocDirectives" in options && options.onlyDocDirectives
39
39
  ? (0, graphql_1.hasDirective)(type, options.onlyDocDirectives, true)
40
40
  : true;
41
- return !(skipDirective || skipDeprecated) && onlyDirective;
41
+ return !skipDirective && !skipDeprecated && onlyDirective;
42
42
  };
43
43
  exports.hasPrintableDirective = hasPrintableDirective;
44
44
  /**
@@ -157,17 +157,20 @@ const isHierarchy = (options, hierarchy) => {
157
157
  * @returns The link object for the type
158
158
  */
159
159
  const toLink = (type, name, operation, options) => {
160
+ const qualifiedName = typeof options.parentType === "string" && options.parentType.includes(".")
161
+ ? `${options.parentType}.${name}`
162
+ : name;
160
163
  const fallback = {
161
164
  text: name,
162
165
  url: "#",
166
+ id: (0, utils_1.slugify)(qualifiedName),
163
167
  };
164
168
  if (typeof type !== "object" || !(0, exports.hasPrintableDirective)(type, options)) {
165
169
  return fallback;
166
170
  }
171
+ // GraphQL overload resolution can include a void branch in this monorepo; runtime value is a named type here.
172
+ // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
167
173
  const graphQLNamedType = (0, graphql_1.getNamedType)(type);
168
- if (!graphQLNamedType) {
169
- return fallback;
170
- }
171
174
  let category = "";
172
175
  let deprecatedFolder = "";
173
176
  let groupFolder = "";
@@ -187,13 +190,22 @@ const toLink = (type, name, operation, options) => {
187
190
  ? (0, exports.getLinkApiGroupFolder)(type)
188
191
  : "";
189
192
  }
190
- const text = graphQLNamedType.name || graphQLNamedType.toString();
193
+ const text = (0, utils_1.hasStringProperty)(graphQLNamedType, "name")
194
+ ? graphQLNamedType.name
195
+ : (0, utils_1.toString)(graphQLNamedType);
191
196
  const formatFolder = (folder) => {
192
197
  return folder && options.formatCategoryFolderName
193
198
  ? options.formatCategoryFolderName(folder)
194
199
  : folder;
195
200
  };
196
- const url = utils_1.pathUrl.join(options.basePath, formatFolder(deprecatedFolder), formatFolder(groupFolder), formatFolder(apiGroupFolder), formatFolder(category), `${(0, utils_1.slugify)(text)}`);
201
+ const operationNameParts = (0, graphql_1.isOperation)(type) && name.includes(".")
202
+ ? name.split(".").filter(Boolean)
203
+ : [];
204
+ const operationNamespaceFolders = operationNameParts.slice(0, -1);
205
+ const operationLeafName = operationNameParts.at(-1) ?? text;
206
+ const url = utils_1.pathUrl.join(options.basePath, formatFolder(deprecatedFolder), formatFolder(groupFolder), formatFolder(apiGroupFolder), formatFolder(category), ...operationNamespaceFolders.map((folder) => {
207
+ return (0, utils_1.slugify)(folder);
208
+ }), `${(0, utils_1.slugify)(operationLeafName)}`);
197
209
  const link = {
198
210
  text,
199
211
  url,
@@ -245,24 +257,53 @@ const printLinkAttributes = (type, text = "") => {
245
257
  return text ?? "";
246
258
  };
247
259
  exports.printLinkAttributes = printLinkAttributes;
260
+ /**
261
+ * Determines whether the provided argument is a valid {@link TypeLink} object.
262
+ *
263
+ * Checks that the argument is a non-null object containing both `text` and `url` properties,
264
+ * and that both properties are strings.
265
+ *
266
+ * @param arg - The value to check.
267
+ * @returns `true` if the argument is a {@link TypeLink}, otherwise `false`.
268
+ */
269
+ const isLinkType = (arg) => {
270
+ return (typeof arg === "object" &&
271
+ arg !== null &&
272
+ (0, utils_1.hasStringProperty)(arg, "text") &&
273
+ (0, utils_1.hasStringProperty)(arg, "url"));
274
+ };
248
275
  /**
249
276
  * Prints a link for a GraphQL type based on the provided options.
250
277
  *
251
- * @param type - The GraphQL type to print a link for
278
+ * @param arg - The GraphQL type or link object to print a link for
252
279
  * @param options - Configuration options for link generation
253
280
  * @returns The formatted link as a string
254
281
  */
255
- const printLink = (type, options) => {
256
- if (typeof type !== "object" || type === null) {
282
+ const printLink = (arg, options) => {
283
+ if (typeof arg !== "object" || arg === null) {
257
284
  return "";
258
285
  }
259
- const link = (0, exports.toLink)(type, (0, graphql_1.getTypeName)(type, (0, utils_1.toString)(type)), undefined, options);
286
+ let link;
287
+ if (isLinkType(arg)) {
288
+ link = arg;
289
+ }
290
+ else {
291
+ link = (0, exports.toLink)(arg, (0, graphql_1.getTypeName)(arg, (0, utils_1.toString)(arg)), undefined, options);
292
+ }
293
+ const printFormattedLink = (text, link) => {
294
+ // create a permalink if url is not provided or is just a hash
295
+ if ((!link.url || link.url === "#") && typeof link.id === "string") {
296
+ const linkUrl = options.sectionHeaderId ? link.id : "";
297
+ return `[${text}](#${linkUrl})`;
298
+ }
299
+ return `[${text}](${link.url})`;
300
+ };
260
301
  if (!(0, exports.hasOptionWithAttributes)(options)) {
261
302
  const textWithAttribute = options.formatMDXNameEntity(link.text, options.parentType);
262
- return `[${textWithAttribute}](${link.url})`;
303
+ return printFormattedLink(textWithAttribute, link);
263
304
  }
264
- const text = (0, exports.printLinkAttributes)(type, link.text);
265
- return `[${options.formatMDXNameEntity(text)}](${link.url})`;
305
+ const text = (0, exports.printLinkAttributes)(arg, link.text);
306
+ return printFormattedLink(options.formatMDXNameEntity(text), link);
266
307
  };
267
308
  exports.printLink = printLink;
268
309
  /**
package/dist/mdx/index.js CHANGED
@@ -79,13 +79,13 @@ const formatMDXBullet = (text = "") => {
79
79
  * ```typescript
80
80
  * const options = { dataOpen: "More Info" };
81
81
  * formatMDXDetails(options);
82
- * // '\n\n<details class="gqlmd-mdx-details">\n<summary class="gqlmd-mdx-details-summary"><span className="gqlmd-mdx-details-summary-open">MORE INFO</span></summary>\n</details>\n\n'
82
+ * // '\n\n<details class="gqlmd-mdx-details">\n<summary class="gqlmd-mdx-details-summary"><span className="gqlmd-mdx-details-summary-open">MORE INFO</span></summary>\n\r\n</details>\n\n'
83
83
  * ```
84
84
  * @see {@link mdxModule.formatMDXDetails} for the equivalent function in the MDX module.
85
85
  * @see {@link printer.formatDetails} for usage in the printer module.
86
86
  */
87
87
  const formatMDXDetails = ({ dataOpen }) => {
88
- return `${strings_1.MARKDOWN_EOP}<details class="gqlmd-mdx-details">${strings_1.MARKDOWN_EOL}<summary class="gqlmd-mdx-details-summary"><span className="gqlmd-mdx-details-summary-open">${dataOpen.toUpperCase()}</span></summary>${strings_1.MARKDOWN_EOL}</details>${strings_1.MARKDOWN_EOP}`;
88
+ return `${strings_1.MARKDOWN_EOP}<details class="gqlmd-mdx-details">${strings_1.MARKDOWN_EOL}<summary class="gqlmd-mdx-details-summary"><span className="gqlmd-mdx-details-summary-open">${dataOpen.toUpperCase()}</span></summary>${strings_1.MARKDOWN_EOL}\r${strings_1.MARKDOWN_EOL}</details>${strings_1.MARKDOWN_EOP}`;
89
89
  };
90
90
  /**
91
91
  * Formats a "Specified By" link into an MDX string.