@graphql-markdown/printer-legacy 1.12.0 → 1.12.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/badge.d.ts +24 -0
- package/dist/badge.js +24 -0
- package/dist/code.d.ts +38 -0
- package/dist/code.js +38 -0
- package/dist/common.d.ts +39 -0
- package/dist/common.js +39 -0
- package/dist/directive.d.ts +37 -0
- package/dist/directive.js +37 -0
- package/dist/example.d.ts +26 -0
- package/dist/example.js +52 -0
- package/dist/frontmatter.d.ts +13 -0
- package/dist/frontmatter.js +8 -0
- package/dist/graphql/directive.d.ts +21 -0
- package/dist/graphql/directive.js +27 -0
- package/dist/graphql/enum.d.ts +18 -0
- package/dist/graphql/enum.js +18 -0
- package/dist/graphql/interface.d.ts +15 -0
- package/dist/graphql/interface.js +15 -0
- package/dist/graphql/object.d.ts +23 -0
- package/dist/graphql/object.js +29 -0
- package/dist/graphql/operation.d.ts +21 -0
- package/dist/graphql/operation.js +21 -0
- package/dist/graphql/scalar.d.ts +23 -0
- package/dist/graphql/scalar.js +19 -0
- package/dist/graphql/union.d.ts +16 -0
- package/dist/graphql/union.js +16 -0
- package/dist/group.d.ts +12 -0
- package/dist/group.js +8 -0
- package/dist/link.d.ts +92 -0
- package/dist/link.js +92 -0
- package/dist/mdx/index.d.ts +13 -0
- package/dist/mdx/index.js +128 -2
- package/dist/printer.d.ts +127 -0
- package/dist/printer.js +127 -0
- package/dist/relation.d.ts +39 -0
- package/dist/relation.js +39 -0
- package/dist/section.d.ts +45 -0
- package/dist/section.js +45 -0
- package/package.json +3 -3
package/dist/link.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Module for handling links and link-related operations in GraphQL Markdown printer.
|
|
4
|
+
* Provides utilities for creating, formatting, and managing links to GraphQL types and operations.
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
2
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
8
|
exports.printParentLink = exports.printLink = exports.printLinkAttributes = exports.getRelationLink = exports.toLink = exports.getLinkDeprecatedFolder = exports.getLinkApiGroupFolder = exports.hasOptionParentType = exports.hasOptionWithAttributes = exports.getLinkCategoryFolder = exports.getCategoryLocale = exports.hasPrintableDirective = exports.API_GROUPS = void 0;
|
|
4
9
|
const graphql_1 = require("@graphql-markdown/graphql");
|
|
@@ -10,6 +15,16 @@ exports.API_GROUPS = {
|
|
|
10
15
|
operations: "operations",
|
|
11
16
|
types: "types",
|
|
12
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Checks if a type has printable directives based on the provided options.
|
|
20
|
+
*
|
|
21
|
+
* @param type - The GraphQL type to check
|
|
22
|
+
* @param options - Configuration options for directive printing
|
|
23
|
+
* @param options.deprecated - How to handle deprecated types
|
|
24
|
+
* @param options.onlyDocDirectives - Only print types with specific directives
|
|
25
|
+
* @param options.skipDocDirectives - Skip types with specific directives
|
|
26
|
+
* @returns `true` if the type should be printed, `false` otherwise
|
|
27
|
+
*/
|
|
13
28
|
const hasPrintableDirective = (type, options) => {
|
|
14
29
|
if (!type) {
|
|
15
30
|
return false;
|
|
@@ -29,6 +44,12 @@ const hasPrintableDirective = (type, options) => {
|
|
|
29
44
|
return !(skipDirective || skipDeprecated) && onlyDirective;
|
|
30
45
|
};
|
|
31
46
|
exports.hasPrintableDirective = hasPrintableDirective;
|
|
47
|
+
/**
|
|
48
|
+
* Gets the locale category for a given GraphQL type.
|
|
49
|
+
*
|
|
50
|
+
* @param type - The GraphQL type to get the category for
|
|
51
|
+
* @returns The locale category for the type, or `undefined` if not found
|
|
52
|
+
*/
|
|
32
53
|
const getCategoryLocale = (type) => {
|
|
33
54
|
switch (true) {
|
|
34
55
|
case (0, graphql_1.isDirectiveType)(type):
|
|
@@ -51,6 +72,13 @@ const getCategoryLocale = (type) => {
|
|
|
51
72
|
return undefined;
|
|
52
73
|
};
|
|
53
74
|
exports.getCategoryLocale = getCategoryLocale;
|
|
75
|
+
/**
|
|
76
|
+
* Gets the folder name for a link category based on the GraphQL type and operation locale.
|
|
77
|
+
*
|
|
78
|
+
* @param type - The GraphQL type to get the folder name for
|
|
79
|
+
* @param operationLocale - The locale of the operation
|
|
80
|
+
* @returns The folder name for the link category, or `undefined` if not found
|
|
81
|
+
*/
|
|
54
82
|
const getLinkCategoryFolder = (type, operationLocale) => {
|
|
55
83
|
const categoryLocale = (0, exports.getCategoryLocale)(type);
|
|
56
84
|
if (!categoryLocale) {
|
|
@@ -70,10 +98,22 @@ const getLinkCategoryFolder = (type, operationLocale) => {
|
|
|
70
98
|
: categoryLocale;
|
|
71
99
|
};
|
|
72
100
|
exports.getLinkCategoryFolder = getLinkCategoryFolder;
|
|
101
|
+
/**
|
|
102
|
+
* Checks if the options include the `withAttributes` attribute.
|
|
103
|
+
*
|
|
104
|
+
* @param options - The options to check
|
|
105
|
+
* @returns `true` if the options include `withAttributes`, `false` otherwise
|
|
106
|
+
*/
|
|
73
107
|
const hasOptionWithAttributes = (options) => {
|
|
74
108
|
return "withAttributes" in options && options.withAttributes === true;
|
|
75
109
|
};
|
|
76
110
|
exports.hasOptionWithAttributes = hasOptionWithAttributes;
|
|
111
|
+
/**
|
|
112
|
+
* Checks if the options include the `parentTypePrefix` attribute.
|
|
113
|
+
*
|
|
114
|
+
* @param options - The options to check
|
|
115
|
+
* @returns `true` if the options include `parentTypePrefix`, `false` otherwise
|
|
116
|
+
*/
|
|
77
117
|
const hasOptionParentType = (options) => {
|
|
78
118
|
return ("parentTypePrefix" in options &&
|
|
79
119
|
options.parentTypePrefix === true &&
|
|
@@ -81,6 +121,13 @@ const hasOptionParentType = (options) => {
|
|
|
81
121
|
typeof options.parentType !== "undefined");
|
|
82
122
|
};
|
|
83
123
|
exports.hasOptionParentType = hasOptionParentType;
|
|
124
|
+
/**
|
|
125
|
+
* Gets the folder name for an API group based on the GraphQL type and group options.
|
|
126
|
+
*
|
|
127
|
+
* @param type - The GraphQL type to get the folder name for
|
|
128
|
+
* @param groups - The group options
|
|
129
|
+
* @returns The folder name for the API group
|
|
130
|
+
*/
|
|
84
131
|
const getLinkApiGroupFolder = (type, groups) => {
|
|
85
132
|
let folderNames = exports.API_GROUPS;
|
|
86
133
|
if (groups && typeof groups === "object") {
|
|
@@ -89,6 +136,13 @@ const getLinkApiGroupFolder = (type, groups) => {
|
|
|
89
136
|
return (0, graphql_1.isApiType)(type) ? folderNames.operations : folderNames.types;
|
|
90
137
|
};
|
|
91
138
|
exports.getLinkApiGroupFolder = getLinkApiGroupFolder;
|
|
139
|
+
/**
|
|
140
|
+
* Gets the folder name for deprecated types based on the GraphQL type and deprecation option.
|
|
141
|
+
*
|
|
142
|
+
* @param type - The GraphQL type to get the folder name for
|
|
143
|
+
* @param option - The deprecation option
|
|
144
|
+
* @returns The folder name for deprecated types
|
|
145
|
+
*/
|
|
92
146
|
const getLinkDeprecatedFolder = (type, option) => {
|
|
93
147
|
return option === "group" && (0, graphql_1.isDeprecated)(type) ? strings_1.DEPRECATED : "";
|
|
94
148
|
};
|
|
@@ -96,6 +150,15 @@ exports.getLinkDeprecatedFolder = getLinkDeprecatedFolder;
|
|
|
96
150
|
const isHierarchy = (options, hierarchy) => {
|
|
97
151
|
return (options?.hierarchy?.[hierarchy] && true);
|
|
98
152
|
};
|
|
153
|
+
/**
|
|
154
|
+
* Converts a GraphQL type to a link object.
|
|
155
|
+
*
|
|
156
|
+
* @param type - The GraphQL type to convert
|
|
157
|
+
* @param name - The name of the type
|
|
158
|
+
* @param operation - The locale of the operation
|
|
159
|
+
* @param options - Configuration options for link generation
|
|
160
|
+
* @returns The link object for the type
|
|
161
|
+
*/
|
|
99
162
|
const toLink = (type, name, operation, options) => {
|
|
100
163
|
const fallback = {
|
|
101
164
|
text: name,
|
|
@@ -140,6 +203,14 @@ const toLink = (type, name, operation, options) => {
|
|
|
140
203
|
return link;
|
|
141
204
|
};
|
|
142
205
|
exports.toLink = toLink;
|
|
206
|
+
/**
|
|
207
|
+
* Gets the link for a relation based on the category, type, and options.
|
|
208
|
+
*
|
|
209
|
+
* @param category - The locale category of the relation
|
|
210
|
+
* @param type - The GraphQL type of the relation
|
|
211
|
+
* @param options - Configuration options for link generation
|
|
212
|
+
* @returns The link object for the relation, or `undefined` if not found
|
|
213
|
+
*/
|
|
143
214
|
const getRelationLink = (category, type, options) => {
|
|
144
215
|
if (!category ||
|
|
145
216
|
typeof type !== "object" ||
|
|
@@ -150,6 +221,13 @@ const getRelationLink = (category, type, options) => {
|
|
|
150
221
|
return (0, exports.toLink)(type, type.name, category, options);
|
|
151
222
|
};
|
|
152
223
|
exports.getRelationLink = getRelationLink;
|
|
224
|
+
/**
|
|
225
|
+
* Prints the attributes of a link based on the GraphQL type.
|
|
226
|
+
*
|
|
227
|
+
* @param type - The GraphQL type to print attributes for
|
|
228
|
+
* @param text - The text to append attributes to
|
|
229
|
+
* @returns The text with appended attributes
|
|
230
|
+
*/
|
|
153
231
|
const printLinkAttributes = (type, text = "") => {
|
|
154
232
|
if (typeof type !== "object" || type === null) {
|
|
155
233
|
return text ?? "";
|
|
@@ -168,6 +246,13 @@ const printLinkAttributes = (type, text = "") => {
|
|
|
168
246
|
return text ?? "";
|
|
169
247
|
};
|
|
170
248
|
exports.printLinkAttributes = printLinkAttributes;
|
|
249
|
+
/**
|
|
250
|
+
* Prints a link for a GraphQL type based on the provided options.
|
|
251
|
+
*
|
|
252
|
+
* @param type - The GraphQL type to print a link for
|
|
253
|
+
* @param options - Configuration options for link generation
|
|
254
|
+
* @returns The formatted link as a string
|
|
255
|
+
*/
|
|
171
256
|
const printLink = (type, options) => {
|
|
172
257
|
if (typeof type !== "object" || type === null) {
|
|
173
258
|
return "";
|
|
@@ -181,6 +266,13 @@ const printLink = (type, options) => {
|
|
|
181
266
|
return `[${options.formatMDXNameEntity(text)}](${link.url})`;
|
|
182
267
|
};
|
|
183
268
|
exports.printLink = printLink;
|
|
269
|
+
/**
|
|
270
|
+
* Prints a parent link for a GraphQL type based on the provided options.
|
|
271
|
+
*
|
|
272
|
+
* @param type - The GraphQL type to print a parent link for
|
|
273
|
+
* @param options - Configuration options for link generation
|
|
274
|
+
* @returns The formatted parent link as a string or MDX string
|
|
275
|
+
*/
|
|
184
276
|
const printParentLink = (type, options) => {
|
|
185
277
|
if (typeof type !== "object" || type === null || !("type" in type)) {
|
|
186
278
|
return "";
|
package/dist/mdx/index.d.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MDX formatting module for GraphQL-Markdown.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a set of utility functions for formatting various MDX components
|
|
5
|
+
* used in the documentation generation process. It handles the formatting of badges,
|
|
6
|
+
* admonitions, bullet points, collapsible sections, and other MDX-specific elements.
|
|
7
|
+
*
|
|
8
|
+
* The module can be used with default formatters or customized with user-provided
|
|
9
|
+
* MDX formatting functions through the mdxModule factory function.
|
|
10
|
+
*
|
|
11
|
+
* @module mdx
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
1
14
|
import type { MDXSupportType } from "@graphql-markdown/types";
|
|
2
15
|
export declare const mdxDeclaration = "";
|
|
3
16
|
declare const defaultModule: MDXSupportType;
|
package/dist/mdx/index.js
CHANGED
|
@@ -1,31 +1,158 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MDX formatting module for GraphQL-Markdown.
|
|
4
|
+
*
|
|
5
|
+
* This module provides a set of utility functions for formatting various MDX components
|
|
6
|
+
* used in the documentation generation process. It handles the formatting of badges,
|
|
7
|
+
* admonitions, bullet points, collapsible sections, and other MDX-specific elements.
|
|
8
|
+
*
|
|
9
|
+
* The module can be used with default formatters or customized with user-provided
|
|
10
|
+
* MDX formatting functions through the mdxModule factory function.
|
|
11
|
+
*
|
|
12
|
+
* @module mdx
|
|
13
|
+
* @packageDocumentation
|
|
14
|
+
*/
|
|
2
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
16
|
exports.mdxModule = exports.mdxDeclaration = void 0;
|
|
4
17
|
const strings_1 = require("../const/strings");
|
|
18
|
+
/**
|
|
19
|
+
* Formats a badge into an MDX string.
|
|
20
|
+
*
|
|
21
|
+
* @param badge - The badge object containing text to display.
|
|
22
|
+
* @returns An MDX string representing the badge.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const badge = { text: "Beta" };
|
|
27
|
+
* formatMDXBadge(badge);
|
|
28
|
+
* // '<mark class="gqlmd-mdx-badge">Beta</mark>'
|
|
29
|
+
* ```
|
|
30
|
+
* @see {@link mdxModule.formatMDXBadge} for the equivalent function in the MDX module.
|
|
31
|
+
* @see {@link printer.formatBadge} for usage in the printer module.
|
|
32
|
+
*/
|
|
5
33
|
const formatMDXBadge = (badge) => {
|
|
6
34
|
return `<mark class="gqlmd-mdx-badge">${badge.text}</mark>`;
|
|
7
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* Formats an admonition into an MDX string.
|
|
38
|
+
*
|
|
39
|
+
* @param admonition - The admonition object containing text, title, type, and optional icon.
|
|
40
|
+
* @param _meta - Optional metadata for the admonition.
|
|
41
|
+
* @returns An MDX string representing the admonition.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const admonition = { text: "Be careful!", title: "Warning", type: "warning", icon: "⚠️" };
|
|
46
|
+
* formatMDXAdmonition(admonition, null);
|
|
47
|
+
* // '<fieldset class="gqlmd-mdx-admonition-fieldset">...</fieldset>'
|
|
48
|
+
* ```
|
|
49
|
+
* @see {@link mdxModule.formatMDXAdmonition} for the equivalent function in the MDX module.
|
|
50
|
+
* @see {@link printer.formatAdmonition} for usage in the printer module.
|
|
51
|
+
*/
|
|
8
52
|
const formatMDXAdmonition = ({ text, title, type, icon }, _meta) => {
|
|
9
53
|
return `${strings_1.MARKDOWN_EOP}<fieldset class="gqlmd-mdx-admonition-fieldset">${strings_1.MARKDOWN_EOL}<legend class="gqlmd-mdx-admonition-legend"><span class="gqlmd-mdx-admonition-legend-type gqlmd-mdx-admonition-legend-type-${type.toLocaleLowerCase()}">${icon ?? type.toUpperCase()} ${title}</span></legend>${strings_1.MARKDOWN_EOL}<span>${text}</span>${strings_1.MARKDOWN_EOL}</fieldset>`;
|
|
10
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* Formats a bullet point into an MDX string.
|
|
57
|
+
*
|
|
58
|
+
* @param text - The text to display next to the bullet. Defaults to an empty string.
|
|
59
|
+
* @returns An MDX string representing the bullet point.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* formatMDXBullet("Item 1");
|
|
64
|
+
* // '<span class="gqlmd-mdx-bullet"> ● </span>Item 1'
|
|
65
|
+
* ```
|
|
66
|
+
* @see {@link mdxModule.formatMDXBullet} for the equivalent function in the MDX module.
|
|
67
|
+
* @see {@link printer.formatBullet} for usage in the printer module.
|
|
68
|
+
*/
|
|
11
69
|
const formatMDXBullet = (text = "") => {
|
|
12
70
|
return `<span class="gqlmd-mdx-bullet"> ● </span>${text}`;
|
|
13
71
|
};
|
|
72
|
+
/**
|
|
73
|
+
* Formats a collapsible details section into an MDX string.
|
|
74
|
+
*
|
|
75
|
+
* @param options - The collapsible options containing the `dataOpen` text.
|
|
76
|
+
* @returns An MDX string representing the collapsible details section.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const options = { dataOpen: "More Info" };
|
|
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'
|
|
83
|
+
* ```
|
|
84
|
+
* @see {@link mdxModule.formatMDXDetails} for the equivalent function in the MDX module.
|
|
85
|
+
* @see {@link printer.formatDetails} for usage in the printer module.
|
|
86
|
+
*/
|
|
14
87
|
const formatMDXDetails = ({ dataOpen }) => {
|
|
15
|
-
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.
|
|
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}`;
|
|
16
89
|
};
|
|
90
|
+
/**
|
|
91
|
+
* Formats a "Specified By" link into an MDX string.
|
|
92
|
+
*
|
|
93
|
+
* @param url - The URL of the specification.
|
|
94
|
+
* @returns An MDX string representing the "Specified By" link.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* formatMDXSpecifiedByLink("https://example.com");
|
|
99
|
+
* // '<span class="gqlmd-mdx-specifiedby">Specification<a class="gqlmd-mdx-specifiedby-link" target="_blank" href="https://example.com" title="Specified by https://example.com">⎘</a></span>'
|
|
100
|
+
* ```
|
|
101
|
+
* @see {@link mdxModule.formatMDXSpecifiedByLink} for the equivalent function in the MDX module.
|
|
102
|
+
* @see {@link printer.formatSpecifiedByLink} for usage in the printer module.
|
|
103
|
+
*/
|
|
17
104
|
const formatMDXSpecifiedByLink = (url) => {
|
|
18
105
|
return `<span class="gqlmd-mdx-specifiedby">Specification<a class="gqlmd-mdx-specifiedby-link" target="_blank" href="${url}" title="Specified by ${url}">⎘</a></span>`;
|
|
19
106
|
};
|
|
107
|
+
/**
|
|
108
|
+
* Formats an entity name into an MDX string.
|
|
109
|
+
*
|
|
110
|
+
* @param name - The name of the entity.
|
|
111
|
+
* @param parentType - Optional parent type of the entity.
|
|
112
|
+
* @returns An MDX string representing the entity name.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* formatMDXNameEntity("User", "Query");
|
|
117
|
+
* // '<span class="gqlmd-mdx-entity"><code class="gqlmd-mdx-entity-parent">Query</code>.<code class="gqlmd-mdx-entity-name">User</code></span>'
|
|
118
|
+
* ```
|
|
119
|
+
* @see {@link mdxModule.formatMDXNameEntity} for the equivalent function in the MDX module.
|
|
120
|
+
* @see {@link printer.formatNameEntity} for usage in the printer module.
|
|
121
|
+
*/
|
|
20
122
|
const formatMDXNameEntity = (name, parentType) => {
|
|
21
123
|
const parentName = parentType
|
|
22
124
|
? `<code class="gqlmd-mdx-entity-parent">${parentType}</code>.`
|
|
23
125
|
: "";
|
|
24
126
|
return `<span class="gqlmd-mdx-entity">${parentName}<code class="gqlmd-mdx-entity-name">${name}</code></span>`;
|
|
25
127
|
};
|
|
128
|
+
/**
|
|
129
|
+
* Formats a TypeLink object for MDX format.
|
|
130
|
+
*
|
|
131
|
+
* Currently, this function returns the link as is without modification.
|
|
132
|
+
* This may serve as a placeholder for future formatting logic.
|
|
133
|
+
*
|
|
134
|
+
* @param link - The TypeLink object to format
|
|
135
|
+
* @returns The formatted TypeLink object
|
|
136
|
+
*/
|
|
26
137
|
const formatMDXLink = (link) => {
|
|
27
138
|
return link;
|
|
28
139
|
};
|
|
140
|
+
/**
|
|
141
|
+
* Formats a front matter section into an MDX string.
|
|
142
|
+
*
|
|
143
|
+
* @param _props - The front matter options.
|
|
144
|
+
* @param formatted - The formatted front matter as an array of strings.
|
|
145
|
+
* @returns An MDX string representing the front matter.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* const formatted = ["title: My Title", "tags: [tag1, tag2]"];
|
|
150
|
+
* formatMDXFrontmatter(null, formatted);
|
|
151
|
+
* // '---\ntitle: My Title\ntags: [tag1, tag2]\n---'
|
|
152
|
+
* ```
|
|
153
|
+
* @see {@link mdxModule.formatMDXFrontmatter} for the equivalent function in the MDX module.
|
|
154
|
+
* @see {@link printer.formatFrontmatter} for usage in the printer module.
|
|
155
|
+
*/
|
|
29
156
|
const formatMDXFrontmatter = (_props, formatted) => {
|
|
30
157
|
return formatted
|
|
31
158
|
? [strings_1.FRONT_MATTER_DELIMITER, ...formatted, strings_1.FRONT_MATTER_DELIMITER].join(strings_1.MARKDOWN_EOL)
|
|
@@ -38,7 +165,6 @@ const defaultModule = {
|
|
|
38
165
|
formatMDXBullet,
|
|
39
166
|
formatMDXDetails,
|
|
40
167
|
formatMDXFrontmatter,
|
|
41
|
-
formatMDXLink,
|
|
42
168
|
formatMDXNameEntity,
|
|
43
169
|
formatMDXSpecifiedByLink,
|
|
44
170
|
mdxDeclaration: exports.mdxDeclaration,
|
package/dist/printer.d.ts
CHANGED
|
@@ -1,10 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GraphQL Schema Printer Module
|
|
3
|
+
*
|
|
4
|
+
* This module provides functionality for printing GraphQL schema types into Markdown documentation.
|
|
5
|
+
* It includes utilities for handling various GraphQL types, custom directives, and formatting options.
|
|
6
|
+
*
|
|
7
|
+
* @module printer
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
1
10
|
import type { CustomDirectiveMap, GraphQLDirective, GraphQLSchema, IPrinter, MDXString, MDXSupportType, Maybe, MetaOptions, PrintTypeOptions, PrinterConfigPrintTypeOptions, SchemaEntitiesGroupMap, TypeDeprecatedOption } from "@graphql-markdown/types";
|
|
11
|
+
/**
|
|
12
|
+
* The Printer class implements the core functionality for generating Markdown documentation
|
|
13
|
+
* from GraphQL schema types.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* This class provides static methods for rendering different components of the documentation:
|
|
17
|
+
* - Headers and frontmatter
|
|
18
|
+
* - Type descriptions and code blocks
|
|
19
|
+
* - Custom directives and metadata
|
|
20
|
+
* - Examples and relations
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const printer = new Printer();
|
|
25
|
+
* await printer.init(schema, '/docs', 'graphql', options);
|
|
26
|
+
* const docs = printer.printType('Query', queryType);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
2
29
|
export declare class Printer implements IPrinter {
|
|
30
|
+
/**
|
|
31
|
+
* Global printer configuration options
|
|
32
|
+
* @static
|
|
33
|
+
*/
|
|
3
34
|
static options: Readonly<Maybe<PrintTypeOptions>>;
|
|
35
|
+
/**
|
|
36
|
+
* Prints type descriptions
|
|
37
|
+
* @static
|
|
38
|
+
*/
|
|
4
39
|
static readonly printDescription: (type: unknown, options: PrintTypeOptions, noText?: string) => MDXString | string;
|
|
40
|
+
/**
|
|
41
|
+
* Prints custom directives
|
|
42
|
+
* @static
|
|
43
|
+
*/
|
|
5
44
|
static readonly printCustomDirectives: (type: unknown, options: PrintTypeOptions) => string;
|
|
45
|
+
/**
|
|
46
|
+
* Prints custom tags
|
|
47
|
+
* @static
|
|
48
|
+
*/
|
|
6
49
|
static readonly printCustomTags: (type: unknown, options: PrintTypeOptions) => MDXString | string;
|
|
50
|
+
/**
|
|
51
|
+
* MDX module configuration
|
|
52
|
+
* @static
|
|
53
|
+
*/
|
|
7
54
|
static printMDXModule: Readonly<MDXSupportType>;
|
|
55
|
+
/**
|
|
56
|
+
* Initializes the printer with the given schema and configuration.
|
|
57
|
+
*
|
|
58
|
+
* @param schema - GraphQL schema to generate documentation for
|
|
59
|
+
* @param baseURL - Base URL path for documentation, e.g. '/docs'
|
|
60
|
+
* @param linkRoot - Root path for generating links between types
|
|
61
|
+
* @param options - Configuration options for the printer
|
|
62
|
+
* @param mdxParser - Optional MDX parser module for MDX output support
|
|
63
|
+
*/
|
|
8
64
|
static init(schema: Maybe<GraphQLSchema>, baseURL?: Maybe<string>, linkRoot?: Maybe<string>, { customDirectives, groups, meta, metatags, onlyDocDirectives, printTypeOptions, skipDocDirectives, }?: {
|
|
9
65
|
customDirectives?: CustomDirectiveMap;
|
|
10
66
|
deprecated?: TypeDeprecatedOption;
|
|
@@ -15,11 +71,82 @@ export declare class Printer implements IPrinter {
|
|
|
15
71
|
printTypeOptions?: PrinterConfigPrintTypeOptions;
|
|
16
72
|
skipDocDirectives?: GraphQLDirective[];
|
|
17
73
|
}, mdxParser?: Record<string, unknown>): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Prints the header section of a type documentation
|
|
76
|
+
*
|
|
77
|
+
* @param id - Unique identifier for the type
|
|
78
|
+
* @param title - Display title for the type
|
|
79
|
+
* @param options - Printer configuration options
|
|
80
|
+
* @returns Formatted header string with optional frontmatter
|
|
81
|
+
*/
|
|
18
82
|
static readonly printHeader: (id: string, title: string, options: PrintTypeOptions) => string;
|
|
83
|
+
/**
|
|
84
|
+
* Prints the GraphQL type definition as code block
|
|
85
|
+
*
|
|
86
|
+
* @param type - GraphQL type to print
|
|
87
|
+
* @param options - Printer configuration options
|
|
88
|
+
* @returns Formatted code block string with type definition
|
|
89
|
+
*/
|
|
19
90
|
static readonly printCode: (type: unknown, options: PrintTypeOptions) => string;
|
|
91
|
+
/**
|
|
92
|
+
* Prints example usage of the type if available
|
|
93
|
+
*
|
|
94
|
+
* @param type - GraphQL type to generate example for
|
|
95
|
+
* @param options - Printer configuration options
|
|
96
|
+
* @returns Formatted example section string or empty string if no example
|
|
97
|
+
*/
|
|
20
98
|
static readonly printExample: (type: unknown, options: PrintTypeOptions) => string;
|
|
99
|
+
/**
|
|
100
|
+
* Prints metadata information for a GraphQL type
|
|
101
|
+
*
|
|
102
|
+
* @param type - GraphQL type to print metadata for
|
|
103
|
+
* @param options - Printer configuration options
|
|
104
|
+
* @returns Formatted metadata string as MDX or plain string
|
|
105
|
+
* @throws {Error} When type is not supported
|
|
106
|
+
*/
|
|
21
107
|
static readonly printTypeMetadata: (type: unknown, options: PrintTypeOptions) => MDXString | string;
|
|
108
|
+
/**
|
|
109
|
+
* Prints related type information
|
|
110
|
+
*
|
|
111
|
+
* @param type - GraphQL type to find relations for
|
|
112
|
+
* @param options - Printer configuration options
|
|
113
|
+
* @returns Formatted relations section as MDX or plain string
|
|
114
|
+
*/
|
|
22
115
|
static readonly printRelations: (type: unknown, options: PrintTypeOptions) => MDXString | string;
|
|
116
|
+
/**
|
|
117
|
+
* Prints HTML meta tags for the documentation
|
|
118
|
+
*
|
|
119
|
+
* @param _type - GraphQL type (unused)
|
|
120
|
+
* @param options - Printer configuration options containing metatags
|
|
121
|
+
* @returns Formatted HTML meta tags string
|
|
122
|
+
*/
|
|
23
123
|
static readonly printMetaTags: (_type: unknown, { metatags }: PrintTypeOptions) => MDXString | string;
|
|
124
|
+
/**
|
|
125
|
+
* Main method to print complete documentation for a GraphQL type
|
|
126
|
+
*
|
|
127
|
+
* @param name - Name identifier for the type
|
|
128
|
+
* @param type - GraphQL type to generate documentation for
|
|
129
|
+
* @param options - Optional printer configuration options
|
|
130
|
+
* @returns Complete documentation as MDX string or undefined if type should be skipped
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* const doc = Printer.printType('User', UserType, {
|
|
135
|
+
* frontMatter: true,
|
|
136
|
+
* codeSection: true
|
|
137
|
+
* });
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @remarks
|
|
141
|
+
* The method combines multiple sections:
|
|
142
|
+
* - Header with frontmatter
|
|
143
|
+
* - Meta tags
|
|
144
|
+
* - Description
|
|
145
|
+
* - Code definition
|
|
146
|
+
* - Custom directives
|
|
147
|
+
* - Type metadata
|
|
148
|
+
* - Example usage
|
|
149
|
+
* - Related types
|
|
150
|
+
*/
|
|
24
151
|
static readonly printType: (name: Maybe<string>, type: unknown, options?: Maybe<Partial<PrintTypeOptions>>) => Maybe<MDXString>;
|
|
25
152
|
}
|