@graphql-markdown/printer-legacy 1.11.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 +29 -1
- package/dist/badge.js +42 -10
- 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/const/options.d.ts +1 -4
- package/dist/const/options.js +1 -3
- package/dist/const/strings.d.ts +1 -0
- package/dist/const/strings.js +2 -1
- package/dist/directive.d.ts +37 -0
- package/dist/directive.js +39 -2
- package/dist/example.d.ts +26 -0
- package/dist/example.js +52 -0
- package/dist/frontmatter.d.ts +15 -3
- package/dist/frontmatter.js +14 -59
- 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 +20 -1
- 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 +15 -2
- package/dist/mdx/index.js +151 -60
- package/dist/printer.d.ts +129 -2
- package/dist/printer.js +134 -5
- package/dist/relation.d.ts +39 -0
- package/dist/relation.js +41 -2
- package/dist/section.d.ts +46 -2
- package/dist/section.js +54 -23
- package/package.json +4 -5
package/dist/printer.d.ts
CHANGED
|
@@ -1,10 +1,66 @@
|
|
|
1
|
-
|
|
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
|
+
*/
|
|
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;
|
|
@@ -14,12 +70,83 @@ export declare class Printer implements IPrinter {
|
|
|
14
70
|
onlyDocDirectives?: GraphQLDirective[];
|
|
15
71
|
printTypeOptions?: PrinterConfigPrintTypeOptions;
|
|
16
72
|
skipDocDirectives?: GraphQLDirective[];
|
|
17
|
-
}, mdxParser?:
|
|
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
|
}
|
package/dist/printer.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* GraphQL Schema Printer Module
|
|
4
|
+
*
|
|
5
|
+
* This module provides functionality for printing GraphQL schema types into Markdown documentation.
|
|
6
|
+
* It includes utilities for handling various GraphQL types, custom directives, and formatting options.
|
|
7
|
+
*
|
|
8
|
+
* @module printer
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.Printer = void 0;
|
|
4
13
|
const graphql_1 = require("@graphql-markdown/graphql");
|
|
@@ -13,12 +22,59 @@ const strings_1 = require("./const/strings");
|
|
|
13
22
|
const mdx_1 = require("./mdx");
|
|
14
23
|
const options_1 = require("./const/options");
|
|
15
24
|
const example_1 = require("./example");
|
|
25
|
+
/**
|
|
26
|
+
* The Printer class implements the core functionality for generating Markdown documentation
|
|
27
|
+
* from GraphQL schema types.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* This class provides static methods for rendering different components of the documentation:
|
|
31
|
+
* - Headers and frontmatter
|
|
32
|
+
* - Type descriptions and code blocks
|
|
33
|
+
* - Custom directives and metadata
|
|
34
|
+
* - Examples and relations
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const printer = new Printer();
|
|
39
|
+
* await printer.init(schema, '/docs', 'graphql', options);
|
|
40
|
+
* const docs = printer.printType('Query', queryType);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
16
43
|
class Printer {
|
|
44
|
+
/**
|
|
45
|
+
* Global printer configuration options
|
|
46
|
+
* @static
|
|
47
|
+
*/
|
|
17
48
|
static options;
|
|
49
|
+
/**
|
|
50
|
+
* Prints type descriptions
|
|
51
|
+
* @static
|
|
52
|
+
*/
|
|
18
53
|
static printDescription = common_1.printDescription;
|
|
54
|
+
/**
|
|
55
|
+
* Prints custom directives
|
|
56
|
+
* @static
|
|
57
|
+
*/
|
|
19
58
|
static printCustomDirectives = directive_1.printCustomDirectives;
|
|
59
|
+
/**
|
|
60
|
+
* Prints custom tags
|
|
61
|
+
* @static
|
|
62
|
+
*/
|
|
20
63
|
static printCustomTags = directive_1.printCustomTags;
|
|
64
|
+
/**
|
|
65
|
+
* MDX module configuration
|
|
66
|
+
* @static
|
|
67
|
+
*/
|
|
21
68
|
static printMDXModule;
|
|
69
|
+
/**
|
|
70
|
+
* Initializes the printer with the given schema and configuration.
|
|
71
|
+
*
|
|
72
|
+
* @param schema - GraphQL schema to generate documentation for
|
|
73
|
+
* @param baseURL - Base URL path for documentation, e.g. '/docs'
|
|
74
|
+
* @param linkRoot - Root path for generating links between types
|
|
75
|
+
* @param options - Configuration options for the printer
|
|
76
|
+
* @param mdxParser - Optional MDX parser module for MDX output support
|
|
77
|
+
*/
|
|
22
78
|
static async init(schema, baseURL = "schema", linkRoot = "/", { customDirectives, groups, meta, metatags, onlyDocDirectives, printTypeOptions, skipDocDirectives, } = {
|
|
23
79
|
customDirectives: undefined,
|
|
24
80
|
groups: undefined,
|
|
@@ -49,13 +105,28 @@ class Printer {
|
|
|
49
105
|
};
|
|
50
106
|
Printer.printMDXModule = await (0, mdx_1.mdxModule)(mdxParser);
|
|
51
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Prints the header section of a type documentation
|
|
110
|
+
*
|
|
111
|
+
* @param id - Unique identifier for the type
|
|
112
|
+
* @param title - Display title for the type
|
|
113
|
+
* @param options - Printer configuration options
|
|
114
|
+
* @returns Formatted header string with optional frontmatter
|
|
115
|
+
*/
|
|
52
116
|
static printHeader = (id, title, options) => {
|
|
53
|
-
if (
|
|
54
|
-
return
|
|
117
|
+
if (options.frontMatter === false) {
|
|
118
|
+
return `# ${title}${strings_1.MARKDOWN_EOP}`;
|
|
55
119
|
}
|
|
56
120
|
const fmOptions = options.frontMatter ?? options_1.DEFAULT_OPTIONS.frontMatter;
|
|
57
|
-
return (0, frontmatter_1.printFrontMatter)(
|
|
121
|
+
return (0, frontmatter_1.printFrontMatter)(title, { ...fmOptions, id }, options);
|
|
58
122
|
};
|
|
123
|
+
/**
|
|
124
|
+
* Prints the GraphQL type definition as code block
|
|
125
|
+
*
|
|
126
|
+
* @param type - GraphQL type to print
|
|
127
|
+
* @param options - Printer configuration options
|
|
128
|
+
* @returns Formatted code block string with type definition
|
|
129
|
+
*/
|
|
59
130
|
static printCode = (type, options) => {
|
|
60
131
|
let code = "";
|
|
61
132
|
if (typeof options.codeSection === "undefined" ||
|
|
@@ -92,6 +163,13 @@ class Printer {
|
|
|
92
163
|
}
|
|
93
164
|
return strings_1.MARKDOWN_SOC + code.trim() + strings_1.MARKDOWN_EOC;
|
|
94
165
|
};
|
|
166
|
+
/**
|
|
167
|
+
* Prints example usage of the type if available
|
|
168
|
+
*
|
|
169
|
+
* @param type - GraphQL type to generate example for
|
|
170
|
+
* @param options - Printer configuration options
|
|
171
|
+
* @returns Formatted example section string or empty string if no example
|
|
172
|
+
*/
|
|
95
173
|
static printExample = (type, options) => {
|
|
96
174
|
if (typeof options.exampleSection === "undefined" ||
|
|
97
175
|
options.exampleSection === null ||
|
|
@@ -102,8 +180,16 @@ class Printer {
|
|
|
102
180
|
if (!example) {
|
|
103
181
|
return "";
|
|
104
182
|
}
|
|
105
|
-
return `${options_1.SectionLevels.
|
|
183
|
+
return `${options_1.SectionLevels.LEVEL.repeat(3)} Example${strings_1.MARKDOWN_EOP}${strings_1.MARKDOWN_SOC}${example}${strings_1.MARKDOWN_EOC}${strings_1.MARKDOWN_EOP}`;
|
|
106
184
|
};
|
|
185
|
+
/**
|
|
186
|
+
* Prints metadata information for a GraphQL type
|
|
187
|
+
*
|
|
188
|
+
* @param type - GraphQL type to print metadata for
|
|
189
|
+
* @param options - Printer configuration options
|
|
190
|
+
* @returns Formatted metadata string as MDX or plain string
|
|
191
|
+
* @throws {Error} When type is not supported
|
|
192
|
+
*/
|
|
107
193
|
static printTypeMetadata = (type, options) => {
|
|
108
194
|
switch (true) {
|
|
109
195
|
case (0, graphql_1.isScalarType)(type):
|
|
@@ -126,12 +212,26 @@ class Printer {
|
|
|
126
212
|
return "";
|
|
127
213
|
}
|
|
128
214
|
};
|
|
215
|
+
/**
|
|
216
|
+
* Prints related type information
|
|
217
|
+
*
|
|
218
|
+
* @param type - GraphQL type to find relations for
|
|
219
|
+
* @param options - Printer configuration options
|
|
220
|
+
* @returns Formatted relations section as MDX or plain string
|
|
221
|
+
*/
|
|
129
222
|
static printRelations = (type, options) => {
|
|
130
223
|
if (options.relatedTypeSection !== true) {
|
|
131
224
|
return "";
|
|
132
225
|
}
|
|
133
226
|
return (0, relation_1.printRelations)(type, options);
|
|
134
227
|
};
|
|
228
|
+
/**
|
|
229
|
+
* Prints HTML meta tags for the documentation
|
|
230
|
+
*
|
|
231
|
+
* @param _type - GraphQL type (unused)
|
|
232
|
+
* @param options - Printer configuration options containing metatags
|
|
233
|
+
* @returns Formatted HTML meta tags string
|
|
234
|
+
*/
|
|
135
235
|
static printMetaTags = (_type, { metatags }) => {
|
|
136
236
|
if (!metatags || metatags.length < 1) {
|
|
137
237
|
return "";
|
|
@@ -144,6 +244,33 @@ class Printer {
|
|
|
144
244
|
});
|
|
145
245
|
return ["<head>", ...meta, "</head>"].join(strings_1.MARKDOWN_EOL);
|
|
146
246
|
};
|
|
247
|
+
/**
|
|
248
|
+
* Main method to print complete documentation for a GraphQL type
|
|
249
|
+
*
|
|
250
|
+
* @param name - Name identifier for the type
|
|
251
|
+
* @param type - GraphQL type to generate documentation for
|
|
252
|
+
* @param options - Optional printer configuration options
|
|
253
|
+
* @returns Complete documentation as MDX string or undefined if type should be skipped
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```typescript
|
|
257
|
+
* const doc = Printer.printType('User', UserType, {
|
|
258
|
+
* frontMatter: true,
|
|
259
|
+
* codeSection: true
|
|
260
|
+
* });
|
|
261
|
+
* ```
|
|
262
|
+
*
|
|
263
|
+
* @remarks
|
|
264
|
+
* The method combines multiple sections:
|
|
265
|
+
* - Header with frontmatter
|
|
266
|
+
* - Meta tags
|
|
267
|
+
* - Description
|
|
268
|
+
* - Code definition
|
|
269
|
+
* - Custom directives
|
|
270
|
+
* - Type metadata
|
|
271
|
+
* - Example usage
|
|
272
|
+
* - Related types
|
|
273
|
+
*/
|
|
147
274
|
static printType = (name, type, options) => {
|
|
148
275
|
const printTypeOptions = {
|
|
149
276
|
...options_1.DEFAULT_OPTIONS,
|
|
@@ -174,7 +301,9 @@ class Printer {
|
|
|
174
301
|
metadata,
|
|
175
302
|
example,
|
|
176
303
|
relations,
|
|
177
|
-
]
|
|
304
|
+
]
|
|
305
|
+
.join(strings_1.MARKDOWN_EOP)
|
|
306
|
+
.trim();
|
|
178
307
|
};
|
|
179
308
|
}
|
|
180
309
|
exports.Printer = Printer;
|
package/dist/relation.d.ts
CHANGED
|
@@ -1,4 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module provides functionality to print relationships between GraphQL types,
|
|
3
|
+
* including return types, member fields, and implementations, in a formatted MDX string output.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
1
6
|
import type { IGetRelation, MDXString, Maybe, PrintTypeOptions, TypeLocale } from "@graphql-markdown/types";
|
|
7
|
+
/**
|
|
8
|
+
* Converts a string representation of a root type to its corresponding TypeLocale
|
|
9
|
+
* @param text - The string to convert to a TypeLocale
|
|
10
|
+
* @returns The matching TypeLocale if found, undefined otherwise
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const locale = getRootTypeLocaleFromString('Query');
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
2
16
|
export declare const getRootTypeLocaleFromString: (text: string) => Maybe<TypeLocale>;
|
|
17
|
+
/**
|
|
18
|
+
* Prints the relation section for a specific type and relation category
|
|
19
|
+
* @template T - Type of the relation
|
|
20
|
+
* @param type - The GraphQL type to get relations for
|
|
21
|
+
* @param section - The section title for the relation
|
|
22
|
+
* @param getRelation - Function to retrieve relations of type T
|
|
23
|
+
* @param options - Printing options for type formatting
|
|
24
|
+
* @returns {MDXString | string} Formatted MDX string containing the relations or empty string if no relations found
|
|
25
|
+
* @throws {Error} If the schema is not provided in options
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const mdx = printRelationOf(type, "Member Of", getRelationOfField, options);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
3
31
|
export declare const printRelationOf: <T>(type: unknown, section: unknown, getRelation: Maybe<IGetRelation<T>>, options: PrintTypeOptions) => MDXString | string;
|
|
32
|
+
/**
|
|
33
|
+
* Prints all relations (return types, member fields, and implementations) for a given type
|
|
34
|
+
* @param type - The GraphQL type to get all relations for
|
|
35
|
+
* @param options - Printing options for type formatting
|
|
36
|
+
* @returns Formatted MDX string containing all relations or empty string if no relations found
|
|
37
|
+
* @throws If the schema is not provided in options
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const relations = printRelations(myType, { schema, formatMDXBullet: () => "* " });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
4
43
|
export declare const printRelations: (type: unknown, options: PrintTypeOptions) => MDXString | string;
|
package/dist/relation.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This module provides functionality to print relationships between GraphQL types,
|
|
4
|
+
* including return types, member fields, and implementations, in a formatted MDX string output.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
2
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
8
|
exports.printRelations = exports.printRelationOf = exports.getRootTypeLocaleFromString = void 0;
|
|
4
9
|
const graphql_1 = require("@graphql-markdown/graphql");
|
|
@@ -6,6 +11,15 @@ const link_1 = require("./link");
|
|
|
6
11
|
const badge_1 = require("./badge");
|
|
7
12
|
const strings_1 = require("./const/strings");
|
|
8
13
|
const options_1 = require("./const/options");
|
|
14
|
+
/**
|
|
15
|
+
* Converts a string representation of a root type to its corresponding TypeLocale
|
|
16
|
+
* @param text - The string to convert to a TypeLocale
|
|
17
|
+
* @returns The matching TypeLocale if found, undefined otherwise
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const locale = getRootTypeLocaleFromString('Query');
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
9
23
|
const getRootTypeLocaleFromString = (text) => {
|
|
10
24
|
for (const [type, props] of Object.entries(strings_1.ROOT_TYPE_LOCALE)) {
|
|
11
25
|
if (Object.values(props).includes(text)) {
|
|
@@ -15,6 +29,20 @@ const getRootTypeLocaleFromString = (text) => {
|
|
|
15
29
|
return undefined;
|
|
16
30
|
};
|
|
17
31
|
exports.getRootTypeLocaleFromString = getRootTypeLocaleFromString;
|
|
32
|
+
/**
|
|
33
|
+
* Prints the relation section for a specific type and relation category
|
|
34
|
+
* @template T - Type of the relation
|
|
35
|
+
* @param type - The GraphQL type to get relations for
|
|
36
|
+
* @param section - The section title for the relation
|
|
37
|
+
* @param getRelation - Function to retrieve relations of type T
|
|
38
|
+
* @param options - Printing options for type formatting
|
|
39
|
+
* @returns {MDXString | string} Formatted MDX string containing the relations or empty string if no relations found
|
|
40
|
+
* @throws {Error} If the schema is not provided in options
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* const mdx = printRelationOf(type, "Member Of", getRelationOfField, options);
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
18
46
|
const printRelationOf = (type, section, getRelation, options) => {
|
|
19
47
|
if (!(0, graphql_1.isNamedType)(type) ||
|
|
20
48
|
(0, graphql_1.isOperation)(type) ||
|
|
@@ -35,7 +63,7 @@ const printRelationOf = (type, section, getRelation, options) => {
|
|
|
35
63
|
const category = (0, exports.getRootTypeLocaleFromString)(relation);
|
|
36
64
|
const badge = (0, badge_1.printBadge)({
|
|
37
65
|
text: category,
|
|
38
|
-
classname: badge_1.
|
|
66
|
+
classname: badge_1.CSS_BADGE_CLASSNAME.RELATION,
|
|
39
67
|
}, options);
|
|
40
68
|
data = data.concat(types.map((t) => {
|
|
41
69
|
const link = (0, link_1.getRelationLink)(category, t, options);
|
|
@@ -50,9 +78,20 @@ const printRelationOf = (type, section, getRelation, options) => {
|
|
|
50
78
|
return a.localeCompare(b);
|
|
51
79
|
})
|
|
52
80
|
.join(options.formatMDXBullet());
|
|
53
|
-
return `${options_1.SectionLevels.
|
|
81
|
+
return `${options_1.SectionLevels.LEVEL.repeat(3)} ${section}${strings_1.MARKDOWN_EOP}${content}${strings_1.MARKDOWN_EOP}`;
|
|
54
82
|
};
|
|
55
83
|
exports.printRelationOf = printRelationOf;
|
|
84
|
+
/**
|
|
85
|
+
* Prints all relations (return types, member fields, and implementations) for a given type
|
|
86
|
+
* @param type - The GraphQL type to get all relations for
|
|
87
|
+
* @param options - Printing options for type formatting
|
|
88
|
+
* @returns Formatted MDX string containing all relations or empty string if no relations found
|
|
89
|
+
* @throws If the schema is not provided in options
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* const relations = printRelations(myType, { schema, formatMDXBullet: () => "* " });
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
56
95
|
const printRelations = (type, options) => {
|
|
57
96
|
const relations = {
|
|
58
97
|
returnedBy: { section: "Returned By", getRelation: graphql_1.getRelationOfReturn },
|
package/dist/section.d.ts
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Module responsible for generating Markdown sections for GraphQL schema documentation.
|
|
3
|
+
* Handles the printing of section items, metadata, and structured documentation content.
|
|
4
|
+
* @module section
|
|
5
|
+
*/
|
|
6
|
+
import type { MDXString, PrintTypeOptions } from "@graphql-markdown/types";
|
|
7
|
+
/**
|
|
8
|
+
* Prints a single section item with its associated metadata.
|
|
9
|
+
*
|
|
10
|
+
* @param type - The GraphQL type or field to print
|
|
11
|
+
* @param options - Configuration options for printing
|
|
12
|
+
* @returns Formatted MDX string containing the section item
|
|
13
|
+
*
|
|
14
|
+
* @template T - Type of the GraphQL element being printed
|
|
15
|
+
*/
|
|
3
16
|
export declare const printSectionItem: <T>(type: T, options: PrintTypeOptions) => MDXString | string;
|
|
17
|
+
/**
|
|
18
|
+
* Prints an array of section items with consistent formatting.
|
|
19
|
+
*
|
|
20
|
+
* @param values - Single value or array of values to print as section items
|
|
21
|
+
* @param options - Configuration options for printing
|
|
22
|
+
* @returns Formatted MDX string containing all section items
|
|
23
|
+
*
|
|
24
|
+
* @template V - Type of the values being printed
|
|
25
|
+
*/
|
|
4
26
|
export declare const printSectionItems: <V>(values: V | V[], options: PrintTypeOptions) => MDXString | string;
|
|
27
|
+
/**
|
|
28
|
+
* Prints a complete section with title and content.
|
|
29
|
+
*
|
|
30
|
+
* @param values - Array of values to include in the section
|
|
31
|
+
* @param section - Section title/header
|
|
32
|
+
* @param options - Configuration options for printing
|
|
33
|
+
* @returns Formatted MDX string containing the complete section
|
|
34
|
+
*
|
|
35
|
+
* @template V - Type of the values being printed
|
|
36
|
+
*/
|
|
5
37
|
export declare const printSection: <V>(values: V[] | readonly V[], section: string, options: PrintTypeOptions) => MDXString | string;
|
|
38
|
+
/**
|
|
39
|
+
* Prints a metadata section with special handling for deprecated items.
|
|
40
|
+
*
|
|
41
|
+
* @param type - The parent type containing the metadata
|
|
42
|
+
* @param values - Values to include in the metadata section
|
|
43
|
+
* @param section - Section title/header
|
|
44
|
+
* @param options - Configuration options for printing
|
|
45
|
+
* @returns Formatted MDX string containing the metadata section
|
|
46
|
+
*
|
|
47
|
+
* @template T - Type of the parent element
|
|
48
|
+
* @template V - Type of the values being printed
|
|
49
|
+
*/
|
|
6
50
|
export declare const printMetadataSection: <T, V>(type: T, values: V | V[] | readonly V[], section: string, options: PrintTypeOptions) => MDXString | string;
|
package/dist/section.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Module responsible for generating Markdown sections for GraphQL schema documentation.
|
|
4
|
+
* Handles the printing of section items, metadata, and structured documentation content.
|
|
5
|
+
* @module section
|
|
6
|
+
*/
|
|
2
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.printMetadataSection = exports.printSection = exports.printSectionItems = exports.printSectionItem =
|
|
8
|
+
exports.printMetadataSection = exports.printSection = exports.printSectionItems = exports.printSectionItem = void 0;
|
|
4
9
|
const graphql_1 = require("@graphql-markdown/graphql");
|
|
5
10
|
const common_1 = require("./common");
|
|
6
11
|
const badge_1 = require("./badge");
|
|
@@ -8,15 +13,17 @@ const link_1 = require("./link");
|
|
|
8
13
|
const directive_1 = require("./directive");
|
|
9
14
|
const strings_1 = require("./const/strings");
|
|
10
15
|
const options_1 = require("./const/options");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Prints a single section item with its associated metadata.
|
|
18
|
+
*
|
|
19
|
+
* @param type - The GraphQL type or field to print
|
|
20
|
+
* @param options - Configuration options for printing
|
|
21
|
+
* @returns Formatted MDX string containing the section item
|
|
22
|
+
*
|
|
23
|
+
* @template T - Type of the GraphQL element being printed
|
|
24
|
+
*/
|
|
16
25
|
const printSectionItem = (type, options) => {
|
|
17
|
-
const level = "level" in options && typeof options.level === "
|
|
18
|
-
? options.level
|
|
19
|
-
: options_1.SectionLevels.LEVEL_4;
|
|
26
|
+
const level = "level" in options && typeof options.level === "number" ? options.level : 4;
|
|
20
27
|
if (!(0, link_1.hasPrintableDirective)(type, options)) {
|
|
21
28
|
return "";
|
|
22
29
|
}
|
|
@@ -27,7 +34,7 @@ const printSectionItem = (type, options) => {
|
|
|
27
34
|
const badges = (0, badge_1.printBadges)(type, options);
|
|
28
35
|
const tags = (0, directive_1.printCustomTags)(type, options);
|
|
29
36
|
const parentTypeLink = (0, link_1.printParentLink)(type, options);
|
|
30
|
-
const title = `${level} ${typeNameLink}${parentTypeLink} ${badges} ${tags}${strings_1.MARKDOWN_EOL}`;
|
|
37
|
+
const title = `${options_1.SectionLevels.LEVEL.repeat(level)} ${typeNameLink}${parentTypeLink} ${badges} ${tags}${strings_1.MARKDOWN_EOL}`;
|
|
31
38
|
const description = (0, common_1.printDescription)(type, options, "")
|
|
32
39
|
.trim()
|
|
33
40
|
.replaceAll("\n", `${strings_1.MARKDOWN_EOL}`);
|
|
@@ -36,7 +43,7 @@ const printSectionItem = (type, options) => {
|
|
|
36
43
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
37
44
|
section += (0, exports.printSectionItems)(type.args, {
|
|
38
45
|
...options,
|
|
39
|
-
level:
|
|
46
|
+
level: 5,
|
|
40
47
|
parentType: typeof options.parentType === "undefined"
|
|
41
48
|
? type.name
|
|
42
49
|
: `${options.parentType}.${type.name}`,
|
|
@@ -45,13 +52,20 @@ const printSectionItem = (type, options) => {
|
|
|
45
52
|
return section;
|
|
46
53
|
};
|
|
47
54
|
exports.printSectionItem = printSectionItem;
|
|
55
|
+
/**
|
|
56
|
+
* Prints an array of section items with consistent formatting.
|
|
57
|
+
*
|
|
58
|
+
* @param values - Single value or array of values to print as section items
|
|
59
|
+
* @param options - Configuration options for printing
|
|
60
|
+
* @returns Formatted MDX string containing all section items
|
|
61
|
+
*
|
|
62
|
+
* @template V - Type of the values being printed
|
|
63
|
+
*/
|
|
48
64
|
const printSectionItems = (values, options) => {
|
|
49
65
|
if (!Array.isArray(values) || values.length === 0) {
|
|
50
66
|
return "";
|
|
51
67
|
}
|
|
52
|
-
const level = ("level" in options && typeof options.level === "
|
|
53
|
-
? options.level
|
|
54
|
-
: options_1.SectionLevels.LEVEL_4);
|
|
68
|
+
const level = ("level" in options && typeof options.level === "number" ? options.level : 4);
|
|
55
69
|
return values
|
|
56
70
|
.map((v) => {
|
|
57
71
|
return (v &&
|
|
@@ -63,14 +77,21 @@ const printSectionItems = (values, options) => {
|
|
|
63
77
|
.join(strings_1.MARKDOWN_EOP);
|
|
64
78
|
};
|
|
65
79
|
exports.printSectionItems = printSectionItems;
|
|
80
|
+
/**
|
|
81
|
+
* Prints a complete section with title and content.
|
|
82
|
+
*
|
|
83
|
+
* @param values - Array of values to include in the section
|
|
84
|
+
* @param section - Section title/header
|
|
85
|
+
* @param options - Configuration options for printing
|
|
86
|
+
* @returns Formatted MDX string containing the complete section
|
|
87
|
+
*
|
|
88
|
+
* @template V - Type of the values being printed
|
|
89
|
+
*/
|
|
66
90
|
const printSection = (values, section, options) => {
|
|
67
91
|
if (!Array.isArray(values) || values.length === 0) {
|
|
68
92
|
return "";
|
|
69
93
|
}
|
|
70
|
-
const level = ("level" in options && typeof options.level === "
|
|
71
|
-
? options.level
|
|
72
|
-
: options_1.SectionLevels.LEVEL_3);
|
|
73
|
-
const levelPosition = exports.sectionLevels.indexOf(level);
|
|
94
|
+
const level = ("level" in options && typeof options.level === "number" ? options.level : 3);
|
|
74
95
|
const [openSection, closeSection] = (() => {
|
|
75
96
|
if (typeof options.collapsible?.dataOpen === "string" &&
|
|
76
97
|
typeof options.collapsible.dataClose === "string") {
|
|
@@ -81,16 +102,26 @@ const printSection = (values, section, options) => {
|
|
|
81
102
|
const items = (0, exports.printSectionItems)(values, {
|
|
82
103
|
...options,
|
|
83
104
|
collapsible: undefined, // do not propagate collapsible
|
|
84
|
-
level: (
|
|
85
|
-
? exports.sectionLevels[levelPosition + 1]
|
|
86
|
-
: undefined),
|
|
105
|
+
level: level >= 3 && level <= 5 ? (level + 1) : undefined,
|
|
87
106
|
});
|
|
88
107
|
if (items === "") {
|
|
89
108
|
return ""; // do not print section is no items printed
|
|
90
109
|
}
|
|
91
|
-
return `${level} ${section}${openSection}${items}${closeSection}`;
|
|
110
|
+
return `${options_1.SectionLevels.LEVEL.repeat(level)} ${section}${openSection}${items}${closeSection}`;
|
|
92
111
|
};
|
|
93
112
|
exports.printSection = printSection;
|
|
113
|
+
/**
|
|
114
|
+
* Prints a metadata section with special handling for deprecated items.
|
|
115
|
+
*
|
|
116
|
+
* @param type - The parent type containing the metadata
|
|
117
|
+
* @param values - Values to include in the metadata section
|
|
118
|
+
* @param section - Section title/header
|
|
119
|
+
* @param options - Configuration options for printing
|
|
120
|
+
* @returns Formatted MDX string containing the metadata section
|
|
121
|
+
*
|
|
122
|
+
* @template T - Type of the parent element
|
|
123
|
+
* @template V - Type of the values being printed
|
|
124
|
+
*/
|
|
94
125
|
const printMetadataSection = (type, values, section, options) => {
|
|
95
126
|
if (typeof type !== "object" ||
|
|
96
127
|
type === null ||
|
|
@@ -117,7 +148,7 @@ const printMetadataSection = (type, values, section, options) => {
|
|
|
117
148
|
const deprecatedMeta = (0, exports.printSection)(deprecated, "", {
|
|
118
149
|
...options,
|
|
119
150
|
parentType: type.name,
|
|
120
|
-
level:
|
|
151
|
+
level: 0,
|
|
121
152
|
collapsible: {
|
|
122
153
|
dataOpen: strings_1.DEPRECATED,
|
|
123
154
|
dataClose: strings_1.DEPRECATED,
|