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