@graphql-markdown/printer-legacy 1.4.3 → 1.5.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 (66) hide show
  1. package/dist/badge.d.ts +5 -0
  2. package/dist/badge.js +66 -0
  3. package/dist/code.d.ts +3 -0
  4. package/dist/code.js +46 -0
  5. package/dist/common.d.ts +6 -0
  6. package/dist/common.js +69 -0
  7. package/dist/const/mdx.d.ts +2 -0
  8. package/{src → dist}/const/mdx.js +4 -1
  9. package/dist/const/options.d.ts +17 -0
  10. package/dist/const/options.js +33 -0
  11. package/dist/const/strings.d.ts +12 -0
  12. package/dist/const/strings.js +26 -0
  13. package/dist/directive.d.ts +6 -0
  14. package/dist/directive.js +76 -0
  15. package/dist/graphql/directive.d.ts +3 -0
  16. package/dist/graphql/directive.js +34 -0
  17. package/dist/graphql/enum.d.ts +3 -0
  18. package/dist/graphql/enum.js +37 -0
  19. package/dist/graphql/index.d.ts +8 -0
  20. package/dist/graphql/index.js +24 -0
  21. package/dist/graphql/input.d.ts +3 -0
  22. package/dist/graphql/input.js +7 -0
  23. package/dist/graphql/interface.d.ts +3 -0
  24. package/dist/graphql/interface.js +7 -0
  25. package/dist/graphql/object.d.ts +4 -0
  26. package/dist/graphql/object.js +47 -0
  27. package/dist/graphql/operation.d.ts +4 -0
  28. package/dist/graphql/operation.js +27 -0
  29. package/dist/graphql/scalar.d.ts +4 -0
  30. package/dist/graphql/scalar.js +26 -0
  31. package/dist/graphql/union.d.ts +3 -0
  32. package/dist/graphql/union.js +27 -0
  33. package/dist/group.d.ts +2 -0
  34. package/dist/group.js +22 -0
  35. package/dist/index.d.ts +1 -0
  36. package/dist/index.js +5 -0
  37. package/dist/link.d.ts +9 -0
  38. package/dist/link.js +137 -0
  39. package/dist/printer.d.ts +21 -0
  40. package/dist/printer.js +166 -0
  41. package/dist/relation.d.ts +4 -0
  42. package/dist/relation.js +71 -0
  43. package/dist/section.d.ts +6 -0
  44. package/dist/section.js +136 -0
  45. package/package.json +51 -7
  46. package/src/badge.js +0 -70
  47. package/src/code.js +0 -60
  48. package/src/common.js +0 -66
  49. package/src/const/options.js +0 -28
  50. package/src/const/strings.js +0 -48
  51. package/src/directive.js +0 -105
  52. package/src/graphql/directive.js +0 -47
  53. package/src/graphql/enum.js +0 -47
  54. package/src/graphql/index.js +0 -10
  55. package/src/graphql/input.js +0 -10
  56. package/src/graphql/interface.js +0 -10
  57. package/src/graphql/object.js +0 -56
  58. package/src/graphql/operation.js +0 -28
  59. package/src/graphql/scalar.js +0 -30
  60. package/src/graphql/union.js +0 -31
  61. package/src/group.js +0 -21
  62. package/src/index.js +0 -3
  63. package/src/link.js +0 -182
  64. package/src/printer.js +0 -242
  65. package/src/relation.js +0 -92
  66. package/src/section.js +0 -185
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.printCodeScalar = exports.printScalarMetadata = exports.printSpecification = void 0;
4
+ const graphql_1 = require("@graphql-markdown/graphql");
5
+ const strings_1 = require("../const/strings");
6
+ const options_1 = require("../const/options");
7
+ const printSpecification = (type) => {
8
+ if (typeof type !== "object" ||
9
+ type === null ||
10
+ !("specifiedByURL" in type) ||
11
+ !type.specifiedByURL) {
12
+ return "";
13
+ }
14
+ const url = type.specifiedByURL;
15
+ // Needs newline between "export const specifiedByLinkCss" and markdown header to prevent compilation error in docusaurus
16
+ return `${options_1.SectionLevels.LEVEL_3} <SpecifiedBy url="${url}"/>${strings_1.MARKDOWN_EOP}`;
17
+ };
18
+ exports.printSpecification = printSpecification;
19
+ const printScalarMetadata = (type, options) => {
20
+ return (0, exports.printSpecification)(type);
21
+ };
22
+ exports.printScalarMetadata = printScalarMetadata;
23
+ const printCodeScalar = (type, options) => {
24
+ return `scalar ${(0, graphql_1.getTypeName)(type)}`;
25
+ };
26
+ exports.printCodeScalar = printCodeScalar;
@@ -0,0 +1,3 @@
1
+ import type { PrintTypeOptions, MDXString } from "@graphql-markdown/types";
2
+ export declare const printUnionMetadata: (type: unknown, options: PrintTypeOptions) => MDXString | string;
3
+ export declare const printCodeUnion: (type: unknown, options?: PrintTypeOptions) => string;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.printCodeUnion = exports.printUnionMetadata = void 0;
4
+ const graphql_1 = require("@graphql-markdown/graphql");
5
+ const section_1 = require("../section");
6
+ const printUnionMetadata = (type, options) => {
7
+ if (!(0, graphql_1.isUnionType)(type)) {
8
+ return "";
9
+ }
10
+ return (0, section_1.printSection)(type.getTypes(), "Possible types", {
11
+ ...options,
12
+ parentType: type.name,
13
+ });
14
+ };
15
+ exports.printUnionMetadata = printUnionMetadata;
16
+ const printCodeUnion = (type, options) => {
17
+ if (!(0, graphql_1.isUnionType)(type)) {
18
+ return "";
19
+ }
20
+ let code = `union ${(0, graphql_1.getTypeName)(type)} = `;
21
+ code += type
22
+ .getTypes()
23
+ .map((v) => (0, graphql_1.getTypeName)(v))
24
+ .join(" | ");
25
+ return code;
26
+ };
27
+ exports.printCodeUnion = printCodeUnion;
@@ -0,0 +1,2 @@
1
+ import type { SchemaEntitiesGroupMap, SchemaEntity, Maybe } from "@graphql-markdown/types";
2
+ export declare const getGroup: (type: unknown, groups: Maybe<SchemaEntitiesGroupMap>, typeCategory: Maybe<SchemaEntity>) => string;
package/dist/group.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGroup = void 0;
4
+ const graphql_1 = require("@graphql-markdown/graphql");
5
+ const utils_1 = require("@graphql-markdown/utils");
6
+ const getGroup = (type, groups, typeCategory) => {
7
+ if (typeof type !== "object" || type === null || !groups || !typeCategory) {
8
+ return "";
9
+ }
10
+ const graphQLNamedType = (0, graphql_1.getNamedType)(type);
11
+ if (!graphQLNamedType) {
12
+ return "";
13
+ }
14
+ const typeName = "name" in graphQLNamedType
15
+ ? graphQLNamedType.name
16
+ : String(graphQLNamedType);
17
+ if (!(typeCategory in groups && typeName in groups[typeCategory])) {
18
+ return "";
19
+ }
20
+ return (0, utils_1.slugify)(groups[typeCategory][typeName]);
21
+ };
22
+ exports.getGroup = getGroup;
@@ -0,0 +1 @@
1
+ export { Printer } from "./printer";
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Printer = void 0;
4
+ var printer_1 = require("./printer");
5
+ Object.defineProperty(exports, "Printer", { enumerable: true, get: function () { return printer_1.Printer; } });
package/dist/link.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import type { MDXString, Maybe, PrintLinkOptions, TypeLink, TypeLocale } from "@graphql-markdown/types";
2
+ export declare const getLinkCategory: (type: unknown) => Maybe<TypeLocale>;
3
+ export declare const hasOptionWithAttributes: (options: PrintLinkOptions) => boolean;
4
+ export declare const hasOptionParentType: (options: PrintLinkOptions) => boolean;
5
+ export declare const toLink: (type: unknown, name: string, operation: Maybe<TypeLocale>, options: PrintLinkOptions) => TypeLink;
6
+ export declare const getRelationLink: (category: Maybe<TypeLocale>, type: unknown, options: PrintLinkOptions) => Maybe<TypeLink>;
7
+ export declare const printLinkAttributes: (type: unknown, text?: Maybe<string>) => string;
8
+ export declare const printLink: (type: unknown, options: PrintLinkOptions) => string;
9
+ export declare const printParentLink: (type: unknown, options: PrintLinkOptions) => MDXString | string;
package/dist/link.js ADDED
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.printParentLink = exports.printLink = exports.printLinkAttributes = exports.getRelationLink = exports.toLink = exports.hasOptionParentType = exports.hasOptionWithAttributes = exports.getLinkCategory = void 0;
4
+ const graphql_1 = require("@graphql-markdown/graphql");
5
+ const utils_1 = require("@graphql-markdown/utils");
6
+ const group_1 = require("./group");
7
+ const strings_1 = require("./const/strings");
8
+ const common_1 = require("./common");
9
+ const getLinkCategory = (type) => {
10
+ switch (true) {
11
+ case (0, graphql_1.isDirectiveType)(type):
12
+ return strings_1.ROOT_TYPE_LOCALE.DIRECTIVE;
13
+ case (0, graphql_1.isEnumType)(type):
14
+ return strings_1.ROOT_TYPE_LOCALE.ENUM;
15
+ case (0, graphql_1.isInputType)(type):
16
+ return strings_1.ROOT_TYPE_LOCALE.INPUT;
17
+ case (0, graphql_1.isInterfaceType)(type):
18
+ return strings_1.ROOT_TYPE_LOCALE.INTERFACE;
19
+ case (0, graphql_1.isObjectType)(type):
20
+ return strings_1.ROOT_TYPE_LOCALE.TYPE;
21
+ case (0, graphql_1.isOperation)(type):
22
+ return strings_1.ROOT_TYPE_LOCALE.OPERATION;
23
+ case (0, graphql_1.isScalarType)(type):
24
+ return strings_1.ROOT_TYPE_LOCALE.SCALAR;
25
+ case (0, graphql_1.isUnionType)(type):
26
+ return strings_1.ROOT_TYPE_LOCALE.UNION;
27
+ }
28
+ return undefined;
29
+ };
30
+ exports.getLinkCategory = getLinkCategory;
31
+ const hasOptionWithAttributes = (options) => {
32
+ return "withAttributes" in options && options.withAttributes === true;
33
+ };
34
+ exports.hasOptionWithAttributes = hasOptionWithAttributes;
35
+ const hasOptionParentType = (options) => {
36
+ return ("parentTypePrefix" in options &&
37
+ options.parentTypePrefix === true &&
38
+ "parentType" in options &&
39
+ typeof options.parentType !== "undefined");
40
+ };
41
+ exports.hasOptionParentType = hasOptionParentType;
42
+ const toLink = (type, name, operation, options) => {
43
+ const fallback = {
44
+ text: name,
45
+ url: "#",
46
+ };
47
+ if (typeof type !== "object") {
48
+ return fallback;
49
+ }
50
+ if (typeof options !== "undefined" && !(0, common_1.hasPrintableDirective)(type, options)) {
51
+ return fallback;
52
+ }
53
+ const graphQLNamedType = (0, graphql_1.getNamedType)(type);
54
+ let category = (0, exports.getLinkCategory)(graphQLNamedType);
55
+ if (!category || !graphQLNamedType) {
56
+ return fallback;
57
+ }
58
+ // special case for relation map
59
+ if (category === strings_1.ROOT_TYPE_LOCALE.OPERATION) {
60
+ if (!operation) {
61
+ return fallback;
62
+ }
63
+ category = operation;
64
+ }
65
+ if (typeof category === "object") {
66
+ category = category.plural;
67
+ }
68
+ const text = graphQLNamedType.name || graphQLNamedType.toString();
69
+ const deprecated = typeof options !== "undefined" &&
70
+ "deprecated" in options &&
71
+ options.deprecated === "group" &&
72
+ (0, graphql_1.isDeprecated)(type)
73
+ ? strings_1.DEPRECATED
74
+ : "";
75
+ const group = "groups" in options && options.groups
76
+ ? (0, group_1.getGroup)(type, options.groups, category)
77
+ : "";
78
+ const url = utils_1.pathUrl.join(options.basePath, deprecated, group, category, (0, utils_1.slugify)(text));
79
+ return {
80
+ text: text,
81
+ url: url,
82
+ };
83
+ };
84
+ exports.toLink = toLink;
85
+ const getRelationLink = (category, type, options) => {
86
+ if (!category ||
87
+ typeof type !== "object" ||
88
+ type === null ||
89
+ !("name" in type)) {
90
+ return undefined;
91
+ }
92
+ return (0, exports.toLink)(type, type.name, category, options);
93
+ };
94
+ exports.getRelationLink = getRelationLink;
95
+ const printLinkAttributes = (type, text = "") => {
96
+ if (typeof type !== "object" || type === null) {
97
+ return text ?? "";
98
+ }
99
+ if (!(0, graphql_1.isLeafType)(type) &&
100
+ "ofType" in type &&
101
+ typeof type.ofType !== "undefined") {
102
+ text = (0, exports.printLinkAttributes)(type.ofType, text);
103
+ }
104
+ if ((0, graphql_1.isListType)(type)) {
105
+ return `[${text}]`;
106
+ }
107
+ if ((0, graphql_1.isNonNullType)(type)) {
108
+ return `${text}!`;
109
+ }
110
+ return text ?? "";
111
+ };
112
+ exports.printLinkAttributes = printLinkAttributes;
113
+ const printLink = (type, options) => {
114
+ if (typeof type !== "object" || type === null) {
115
+ return "";
116
+ }
117
+ const link = (0, exports.toLink)(type, (0, graphql_1.getTypeName)(type, String(type)), undefined, options);
118
+ if (typeof options !== "undefined" && !(0, exports.hasOptionWithAttributes)(options)) {
119
+ const textWithAttribute = (0, exports.hasOptionParentType)(options)
120
+ ? `<code style={{ fontWeight: 'normal' }}>${options.parentType}.<b>${link.text}</b></code>`
121
+ : `\`${link.text}\``;
122
+ return `[${textWithAttribute}](${link.url})`;
123
+ }
124
+ const text = (0, exports.printLinkAttributes)(type, link.text);
125
+ return `[\`${text}\`](${link.url})`;
126
+ };
127
+ exports.printLink = printLink;
128
+ const printParentLink = (type, options) => {
129
+ if (typeof type !== "object" || type === null || !("type" in type)) {
130
+ return "";
131
+ }
132
+ return `<Bullet />${(0, exports.printLink)(type.type, {
133
+ ...options,
134
+ withAttributes: true,
135
+ })}`;
136
+ };
137
+ exports.printParentLink = printParentLink;
@@ -0,0 +1,21 @@
1
+ import type { CustomDirectiveMap, GraphQLDirective, GraphQLSchema, IPrinter, MDXString, Maybe, PrintTypeOptions, PrinterConfigPrintTypeOptions, SchemaEntitiesGroupMap, TypeDeprecatedOption } from "@graphql-markdown/types";
2
+ export declare class Printer implements IPrinter {
3
+ static options: Maybe<PrintTypeOptions>;
4
+ static printDescription: (type: unknown, options?: PrintTypeOptions | undefined, noText?: string | undefined) => string | MDXString;
5
+ static printCustomDirectives: (type: unknown, options: PrintTypeOptions) => string;
6
+ static printCustomTags: (type: unknown, options: PrintTypeOptions) => string | MDXString;
7
+ static init(schema: Maybe<GraphQLSchema>, baseURL?: Maybe<string>, linkRoot?: Maybe<string>, { customDirectives, groups, onlyDocDirectives, printTypeOptions, skipDocDirectives, }?: {
8
+ customDirectives?: CustomDirectiveMap;
9
+ deprecated?: TypeDeprecatedOption;
10
+ groups?: SchemaEntitiesGroupMap;
11
+ onlyDocDirectives?: GraphQLDirective[];
12
+ printTypeOptions?: PrinterConfigPrintTypeOptions;
13
+ skipDocDirectives?: GraphQLDirective[];
14
+ }): void;
15
+ static printHeader: (id: string, title: string, options: PrintTypeOptions) => string;
16
+ static printCode: (type: unknown, options: PrintTypeOptions) => string;
17
+ static printTypeMetadata: (type: unknown, options: PrintTypeOptions) => MDXString | string;
18
+ static printRelations: (type: unknown, options: PrintTypeOptions) => MDXString | string;
19
+ static printMetaTags: (_type: unknown, { metatags }: PrintTypeOptions) => MDXString | string;
20
+ static printType: (name: Maybe<string>, type: unknown, options?: Maybe<Partial<PrintTypeOptions>>) => Maybe<MDXString>;
21
+ }
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Printer = void 0;
4
+ const graphql_1 = require("@graphql-markdown/graphql");
5
+ const utils_1 = require("@graphql-markdown/utils");
6
+ const relation_1 = require("./relation");
7
+ const common_1 = require("./common");
8
+ const directive_1 = require("./directive");
9
+ const graphql_2 = require("./graphql");
10
+ const strings_1 = require("./const/strings");
11
+ const mdx_1 = require("./const/mdx");
12
+ const options_1 = require("./const/options");
13
+ class Printer {
14
+ static options;
15
+ static printDescription = common_1.printDescription;
16
+ static printCustomDirectives = directive_1.printCustomDirectives;
17
+ static printCustomTags = directive_1.printCustomTags;
18
+ static init(schema, baseURL = "schema", linkRoot = "/", { customDirectives, groups, onlyDocDirectives, printTypeOptions, skipDocDirectives, } = {
19
+ customDirectives: undefined,
20
+ groups: undefined,
21
+ onlyDocDirectives: [],
22
+ printTypeOptions: options_1.PRINT_TYPE_DEFAULT_OPTIONS,
23
+ skipDocDirectives: [],
24
+ }) {
25
+ if (typeof Printer.options !== "undefined") {
26
+ return;
27
+ }
28
+ Printer.options = {
29
+ ...options_1.DEFAULT_OPTIONS,
30
+ basePath: utils_1.pathUrl.join(linkRoot ?? "", baseURL ?? ""),
31
+ codeSection: printTypeOptions?.codeSection ?? options_1.PRINT_TYPE_DEFAULT_OPTIONS.codeSection,
32
+ customDirectives,
33
+ groups,
34
+ parentTypePrefix: printTypeOptions?.parentTypePrefix ??
35
+ options_1.PRINT_TYPE_DEFAULT_OPTIONS.parentTypePrefix,
36
+ deprecated: printTypeOptions?.deprecated ?? options_1.PRINT_TYPE_DEFAULT_OPTIONS.deprecated,
37
+ relatedTypeSection: printTypeOptions?.relatedTypeSection ??
38
+ options_1.PRINT_TYPE_DEFAULT_OPTIONS.relatedTypeSection,
39
+ schema,
40
+ onlyDocDirectives: onlyDocDirectives ?? [],
41
+ skipDocDirectives: skipDocDirectives ?? [],
42
+ typeBadges: printTypeOptions?.typeBadges ?? options_1.PRINT_TYPE_DEFAULT_OPTIONS.typeBadges,
43
+ };
44
+ }
45
+ static printHeader = (id, title, options) => {
46
+ const { toc, pagination } = options.header ?? options_1.DEFAULT_OPTIONS.header;
47
+ const paginationButtons = pagination
48
+ ? []
49
+ : ["pagination_next: null", "pagination_prev: null"];
50
+ const header = [
51
+ strings_1.FRONT_MATTER,
52
+ `id: ${id}`,
53
+ `title: ${title}`,
54
+ `hide_table_of_contents: ${!toc}`,
55
+ ...paginationButtons,
56
+ strings_1.FRONT_MATTER,
57
+ ];
58
+ return header.join(strings_1.MARKDOWN_EOL);
59
+ };
60
+ static printCode = (type, options) => {
61
+ let code = "";
62
+ if (typeof options.codeSection === "undefined" ||
63
+ options.codeSection !== true) {
64
+ return code;
65
+ }
66
+ switch (true) {
67
+ case (0, graphql_1.isOperation)(type):
68
+ code += (0, graphql_2.printCodeOperation)(type, options);
69
+ break;
70
+ case (0, graphql_1.isEnumType)(type):
71
+ code += (0, graphql_2.printCodeEnum)(type, options);
72
+ break;
73
+ case (0, graphql_1.isUnionType)(type):
74
+ code += (0, graphql_2.printCodeUnion)(type, options);
75
+ break;
76
+ case (0, graphql_1.isInterfaceType)(type):
77
+ code += (0, graphql_2.printCodeInterface)(type, options);
78
+ break;
79
+ case (0, graphql_1.isObjectType)(type):
80
+ code += (0, graphql_2.printCodeObject)(type, options);
81
+ break;
82
+ case (0, graphql_1.isInputType)(type):
83
+ code += (0, graphql_2.printCodeInput)(type, options);
84
+ break;
85
+ case (0, graphql_1.isScalarType)(type):
86
+ code += (0, graphql_2.printCodeScalar)(type, options);
87
+ break;
88
+ case (0, graphql_1.isDirectiveType)(type):
89
+ code += (0, graphql_2.printCodeDirective)(type, options);
90
+ break;
91
+ default:
92
+ code += `"${(0, graphql_1.getTypeName)(type)}" not supported`;
93
+ }
94
+ return strings_1.MARKDOWN_SOC + code.trim() + strings_1.MARKDOWN_EOC;
95
+ };
96
+ static printTypeMetadata = (type, options) => {
97
+ switch (true) {
98
+ case (0, graphql_1.isScalarType)(type):
99
+ return (0, graphql_2.printScalarMetadata)(type, options);
100
+ case (0, graphql_1.isEnumType)(type):
101
+ return (0, graphql_2.printEnumMetadata)(type, options);
102
+ case (0, graphql_1.isUnionType)(type):
103
+ return (0, graphql_2.printUnionMetadata)(type, options);
104
+ case (0, graphql_1.isObjectType)(type):
105
+ return (0, graphql_2.printObjectMetadata)(type, options);
106
+ case (0, graphql_1.isInterfaceType)(type):
107
+ return (0, graphql_2.printInterfaceMetadata)(type, options);
108
+ case (0, graphql_1.isInputType)(type):
109
+ return (0, graphql_2.printInputMetadata)(type, options);
110
+ case (0, graphql_1.isDirectiveType)(type):
111
+ return (0, graphql_2.printDirectiveMetadata)(type, options);
112
+ case (0, graphql_1.isOperation)(type):
113
+ return (0, graphql_2.printOperationMetadata)(type, options);
114
+ default:
115
+ return "";
116
+ }
117
+ };
118
+ static printRelations = (type, options) => {
119
+ if (options.relatedTypeSection !== true) {
120
+ return "";
121
+ }
122
+ return (0, relation_1.printRelations)(type, options);
123
+ };
124
+ static printMetaTags = (_type, { metatags }) => {
125
+ if (!metatags || metatags.length < 1) {
126
+ return "";
127
+ }
128
+ const meta = metatags.map((tag) => {
129
+ const props = Object.entries(tag).map(([name, value]) => {
130
+ return `${name}="${value}"`;
131
+ });
132
+ return `<meta ${props.join(" ")} />`;
133
+ });
134
+ return ["<head>", ...meta, "</head>"].join(strings_1.MARKDOWN_EOL);
135
+ };
136
+ static printType = (name, type, options) => {
137
+ const printTypeOptions = {
138
+ ...options_1.DEFAULT_OPTIONS,
139
+ ...Printer.options,
140
+ ...options,
141
+ };
142
+ if (!name || !(0, common_1.hasPrintableDirective)(type, printTypeOptions)) {
143
+ return undefined;
144
+ }
145
+ const header = Printer.printHeader(name, (0, graphql_1.getTypeName)(type), printTypeOptions);
146
+ const metatags = Printer.printMetaTags(type, printTypeOptions);
147
+ const description = Printer.printDescription(type, printTypeOptions);
148
+ const code = Printer.printCode(type, printTypeOptions);
149
+ const customDirectives = Printer.printCustomDirectives(type, printTypeOptions);
150
+ const tags = Printer.printCustomTags(type, printTypeOptions);
151
+ const metadata = Printer.printTypeMetadata(type, printTypeOptions);
152
+ const relations = Printer.printRelations(type, printTypeOptions);
153
+ return [
154
+ header,
155
+ mdx_1.mdx,
156
+ metatags,
157
+ tags,
158
+ description,
159
+ code,
160
+ customDirectives,
161
+ metadata,
162
+ relations,
163
+ ].join(strings_1.MARKDOWN_EOP);
164
+ };
165
+ }
166
+ exports.Printer = Printer;
@@ -0,0 +1,4 @@
1
+ import type { IGetRelation, MDXString, Maybe, PrintTypeOptions, TypeLocale } from "@graphql-markdown/types";
2
+ export declare const getRootTypeLocaleFromString: (text: string) => Maybe<TypeLocale>;
3
+ export declare const printRelationOf: <T>(type: unknown, section: unknown, getRelation: Maybe<IGetRelation<T>>, options: PrintTypeOptions) => MDXString | string;
4
+ export declare const printRelations: (type: unknown, options: PrintTypeOptions) => MDXString | string;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.printRelations = exports.printRelationOf = exports.getRootTypeLocaleFromString = void 0;
4
+ const graphql_1 = require("@graphql-markdown/graphql");
5
+ const link_1 = require("./link");
6
+ const badge_1 = require("./badge");
7
+ const strings_1 = require("./const/strings");
8
+ const options_1 = require("./const/options");
9
+ const getRootTypeLocaleFromString = (text) => {
10
+ for (const [type, props] of Object.entries(strings_1.ROOT_TYPE_LOCALE)) {
11
+ if (Object.values(props).includes(text)) {
12
+ return strings_1.ROOT_TYPE_LOCALE[type];
13
+ }
14
+ }
15
+ return undefined;
16
+ };
17
+ exports.getRootTypeLocaleFromString = getRootTypeLocaleFromString;
18
+ const printRelationOf = (type, section, getRelation, options) => {
19
+ if (!(0, graphql_1.isNamedType)(type) ||
20
+ (0, graphql_1.isOperation)(type) ||
21
+ !options.schema ||
22
+ typeof getRelation !== "function") {
23
+ return "";
24
+ }
25
+ const schemaMap = (0, graphql_1.getSchemaMap)(options.schema);
26
+ const relations = getRelation(type, schemaMap);
27
+ if (!relations) {
28
+ return "";
29
+ }
30
+ let data = [];
31
+ for (const [relation, types] of Object.entries(relations)) {
32
+ if (types.length === 0) {
33
+ continue;
34
+ }
35
+ const category = (0, exports.getRootTypeLocaleFromString)(relation);
36
+ const badge = (0, badge_1.printBadge)({
37
+ text: typeof category === "string" ? category : category.singular,
38
+ classname: badge_1.DEFAULT_CSS_CLASSNAME,
39
+ });
40
+ data = data.concat(types.map((t) => {
41
+ const link = (0, link_1.getRelationLink)(category, t, options);
42
+ return link ? `[\`${link.text}\`](${link.url}) ${badge}` : "";
43
+ }));
44
+ }
45
+ if (data.length === 0) {
46
+ return "";
47
+ }
48
+ const content = [...data]
49
+ .sort((a, b) => {
50
+ return a.localeCompare(b);
51
+ })
52
+ .join("<Bullet />");
53
+ return `${options_1.SectionLevels.LEVEL_3} ${section}${strings_1.MARKDOWN_EOP}${content}${strings_1.MARKDOWN_EOP}`;
54
+ };
55
+ exports.printRelationOf = printRelationOf;
56
+ const printRelations = (type, options) => {
57
+ const relations = {
58
+ returnedBy: { section: "Returned by", getRelation: graphql_1.getRelationOfReturn },
59
+ memberOf: { section: "Member Of", getRelation: graphql_1.getRelationOfField },
60
+ implementedBy: {
61
+ section: "Implemented By",
62
+ getRelation: graphql_1.getRelationOfImplementation,
63
+ },
64
+ };
65
+ let data = "";
66
+ for (const { section, getRelation } of Object.values(relations)) {
67
+ data += (0, exports.printRelationOf)(type, section, getRelation, options);
68
+ }
69
+ return data;
70
+ };
71
+ exports.printRelations = printRelations;
@@ -0,0 +1,6 @@
1
+ import type { MDXString, PrintTypeOptions, SectionLevel } from "@graphql-markdown/types";
2
+ export declare const sectionLevels: SectionLevel[];
3
+ export declare const printSectionItem: <T>(type: T, options: PrintTypeOptions) => MDXString | string;
4
+ export declare const printSectionItems: <V>(values: V | V[], options: PrintTypeOptions) => MDXString | string;
5
+ export declare const printSection: <V>(values: V[] | readonly V[], section: string, options: PrintTypeOptions) => MDXString | string;
6
+ export declare const printMetadataSection: <T, V>(type: T, values: V | V[] | readonly V[], section: string, options: PrintTypeOptions) => MDXString | string;
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.printMetadataSection = exports.printSection = exports.printSectionItems = exports.printSectionItem = exports.sectionLevels = void 0;
4
+ const graphql_1 = require("@graphql-markdown/graphql");
5
+ const common_1 = require("./common");
6
+ const badge_1 = require("./badge");
7
+ const link_1 = require("./link");
8
+ const directive_1 = require("./directive");
9
+ const strings_1 = require("./const/strings");
10
+ const options_1 = require("./const/options");
11
+ exports.sectionLevels = [
12
+ options_1.SectionLevels.LEVEL_3,
13
+ options_1.SectionLevels.LEVEL_4,
14
+ options_1.SectionLevels.LEVEL_5,
15
+ ];
16
+ const printSectionItem = (type, options) => {
17
+ const level = "level" in options && typeof options.level === "string"
18
+ ? options.level
19
+ : options_1.SectionLevels.LEVEL_4;
20
+ if (!(0, common_1.hasPrintableDirective)(type, options)) {
21
+ return "";
22
+ }
23
+ const typeNameLink = (0, link_1.printLink)(type, {
24
+ ...options,
25
+ withAttributes: false,
26
+ });
27
+ const description = (0, common_1.printDescription)(type, options, "").replaceAll("\n", `${strings_1.MARKDOWN_EOL}> `);
28
+ const badges = (0, badge_1.printBadges)(type, options);
29
+ const tags = (0, directive_1.printCustomTags)(type, options);
30
+ const parentTypeLink = (0, link_1.printParentLink)(type, options);
31
+ let section = `${level} ${typeNameLink}${parentTypeLink} ${badges} ${tags}${strings_1.MARKDOWN_EOL}> ${description}${strings_1.MARKDOWN_EOL}> `;
32
+ if ((0, graphql_1.isGraphQLFieldType)(type)) {
33
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
34
+ section += (0, exports.printSectionItems)(type.args, {
35
+ ...options,
36
+ level: options_1.SectionLevels.LEVEL_5,
37
+ parentType: typeof options.parentType === "undefined"
38
+ ? type.name
39
+ : `${options.parentType}.${type.name}`,
40
+ });
41
+ }
42
+ return section;
43
+ };
44
+ exports.printSectionItem = printSectionItem;
45
+ const printSectionItems = (values, options) => {
46
+ if (!Array.isArray(values) || values.length === 0) {
47
+ return "";
48
+ }
49
+ const level = ("level" in options && typeof options.level === "string"
50
+ ? options.level
51
+ : options_1.SectionLevels.LEVEL_4);
52
+ return values
53
+ .map((v) => {
54
+ return (v &&
55
+ (0, exports.printSectionItem)(v, {
56
+ ...options,
57
+ level,
58
+ }));
59
+ })
60
+ .join(strings_1.MARKDOWN_EOP);
61
+ };
62
+ exports.printSectionItems = printSectionItems;
63
+ const printSection = (values, section, options) => {
64
+ if (!Array.isArray(values) || values.length === 0) {
65
+ return "";
66
+ }
67
+ const level = ("level" in options && typeof options.level === "string"
68
+ ? options.level
69
+ : options_1.SectionLevels.LEVEL_3);
70
+ const levelPosition = exports.sectionLevels.indexOf(level);
71
+ const [openSection, closeSection] = (() => {
72
+ if (typeof options.collapsible?.dataOpen === "string" &&
73
+ typeof options.collapsible.dataClose === "string") {
74
+ return [
75
+ `${strings_1.MARKDOWN_EOP}<Details dataOpen={${options.collapsible.dataOpen}} dataClose={${options.collapsible.dataClose}}>${strings_1.MARKDOWN_EOP}`,
76
+ `${strings_1.MARKDOWN_EOP}</Details>${strings_1.MARKDOWN_EOP}`,
77
+ ];
78
+ }
79
+ return [strings_1.MARKDOWN_EOP, strings_1.MARKDOWN_EOP];
80
+ })();
81
+ const items = (0, exports.printSectionItems)(values, {
82
+ ...options,
83
+ collapsible: undefined,
84
+ level: (levelPosition > -1
85
+ ? exports.sectionLevels[levelPosition + 1]
86
+ : undefined),
87
+ });
88
+ if (items === "") {
89
+ return ""; // do not print section is no items printed
90
+ }
91
+ return `${level} ${section}${openSection}${items}${closeSection}`;
92
+ };
93
+ exports.printSection = printSection;
94
+ const printMetadataSection = (type, values, section, options) => {
95
+ if (typeof type !== "object" ||
96
+ type === null ||
97
+ !("name" in type) ||
98
+ !Array.isArray(values) ||
99
+ values.length === 0) {
100
+ return "";
101
+ }
102
+ switch (options.deprecated) {
103
+ case "group": {
104
+ const { fields, deprecated } = values.reduce((res, arg) => {
105
+ if ((0, graphql_1.isDeprecated)(arg)) {
106
+ res.deprecated.push(arg);
107
+ }
108
+ else {
109
+ res.fields.push(arg);
110
+ }
111
+ return res;
112
+ }, { fields: [], deprecated: [] });
113
+ const meta = (0, exports.printSection)(fields, section, {
114
+ ...options,
115
+ parentType: type.name,
116
+ });
117
+ const deprecatedMeta = (0, exports.printSection)(deprecated, "", {
118
+ ...options,
119
+ parentType: type.name,
120
+ level: options_1.SectionLevels.NONE,
121
+ collapsible: {
122
+ dataOpen: strings_1.HIDE_DEPRECATED,
123
+ dataClose: strings_1.SHOW_DEPRECATED,
124
+ },
125
+ });
126
+ return `${meta}${deprecatedMeta}`;
127
+ }
128
+ case "default":
129
+ default:
130
+ return (0, exports.printSection)(values, section, {
131
+ ...options,
132
+ parentType: type.name,
133
+ });
134
+ }
135
+ };
136
+ exports.printMetadataSection = printMetadataSection;