@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
package/src/graphql/scalar.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
graphql: { getTypeName },
|
|
3
|
-
} = require("@graphql-markdown/utils");
|
|
4
|
-
|
|
5
|
-
const { HEADER_SECTION_LEVEL, MARKDOWN_EOP } = require("../const/strings");
|
|
6
|
-
|
|
7
|
-
const printSpecification = (type) => {
|
|
8
|
-
if (!type.specifiedByURL && !type.specifiedByUrl) {
|
|
9
|
-
return "";
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const url = type.specifiedByURL || type.specifiedByUrl;
|
|
13
|
-
|
|
14
|
-
// Needs newline between "export const specifiedByLinkCss" and markdown header to prevent compilation error in docusaurus
|
|
15
|
-
return `${HEADER_SECTION_LEVEL} <SpecifiedBy url="${url}"/>${MARKDOWN_EOP}`;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const printScalarMetadata = (type) => {
|
|
19
|
-
return printSpecification(type);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const printCodeScalar = (type) => {
|
|
23
|
-
return `scalar ${getTypeName(type)}`;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
module.exports = {
|
|
27
|
-
printSpecification,
|
|
28
|
-
printScalarMetadata,
|
|
29
|
-
printCodeScalar,
|
|
30
|
-
};
|
package/src/graphql/union.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
graphql: { isUnionType, getTypeName },
|
|
3
|
-
} = require("@graphql-markdown/utils");
|
|
4
|
-
|
|
5
|
-
const { printSection } = require("../section");
|
|
6
|
-
|
|
7
|
-
const printUnionMetadata = (type, options) => {
|
|
8
|
-
return printSection(type.getTypes(), "Possible types", {
|
|
9
|
-
...options,
|
|
10
|
-
parentType: type.name,
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const printCodeUnion = (type) => {
|
|
15
|
-
if (!isUnionType(type)) {
|
|
16
|
-
return "";
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
let code = `union ${getTypeName(type)} = `;
|
|
20
|
-
code += type
|
|
21
|
-
.getTypes()
|
|
22
|
-
.map((v) => getTypeName(v))
|
|
23
|
-
.join(" | ");
|
|
24
|
-
|
|
25
|
-
return code;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
module.exports = {
|
|
29
|
-
printUnionMetadata,
|
|
30
|
-
printCodeUnion,
|
|
31
|
-
};
|
package/src/group.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
string: { toSlug },
|
|
3
|
-
object: { hasProperty },
|
|
4
|
-
graphql: { getNamedType },
|
|
5
|
-
} = require("@graphql-markdown/utils");
|
|
6
|
-
|
|
7
|
-
const getGroup = (type, groups, typeCategory) => {
|
|
8
|
-
if (typeof groups !== "object" || groups === null) {
|
|
9
|
-
return "";
|
|
10
|
-
}
|
|
11
|
-
const graphLQLNamedType = getNamedType(type);
|
|
12
|
-
const typeName = graphLQLNamedType.name || graphLQLNamedType;
|
|
13
|
-
return hasProperty(groups, typeCategory) &&
|
|
14
|
-
hasProperty(groups[typeCategory], typeName)
|
|
15
|
-
? toSlug(groups[typeCategory][typeName])
|
|
16
|
-
: "";
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
module.exports = {
|
|
20
|
-
getGroup,
|
|
21
|
-
};
|
package/src/index.js
DELETED
package/src/link.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
graphql: {
|
|
3
|
-
getNamedType,
|
|
4
|
-
getTypeName,
|
|
5
|
-
hasDirective,
|
|
6
|
-
isDeprecated,
|
|
7
|
-
isDirectiveType,
|
|
8
|
-
isEnumType,
|
|
9
|
-
isInputType,
|
|
10
|
-
isInterfaceType,
|
|
11
|
-
isLeafType,
|
|
12
|
-
isListType,
|
|
13
|
-
isNonNullType,
|
|
14
|
-
isObjectType,
|
|
15
|
-
isOperation,
|
|
16
|
-
isScalarType,
|
|
17
|
-
isUnionType,
|
|
18
|
-
},
|
|
19
|
-
object: { hasProperty },
|
|
20
|
-
string: { toSlug },
|
|
21
|
-
url: { pathUrl },
|
|
22
|
-
} = require("@graphql-markdown/utils");
|
|
23
|
-
|
|
24
|
-
const { getGroup } = require("./group");
|
|
25
|
-
const { ROOT_TYPE_LOCALE, DEPRECATED } = require("./const/strings");
|
|
26
|
-
const { OPTION_DEPRECATED } = require("./const/options");
|
|
27
|
-
|
|
28
|
-
class Link {
|
|
29
|
-
static getLinkCategory = (graphLQLNamedType) => {
|
|
30
|
-
switch (true) {
|
|
31
|
-
case isEnumType(graphLQLNamedType):
|
|
32
|
-
return ROOT_TYPE_LOCALE.ENUM;
|
|
33
|
-
case isUnionType(graphLQLNamedType):
|
|
34
|
-
return ROOT_TYPE_LOCALE.UNION;
|
|
35
|
-
case isInterfaceType(graphLQLNamedType):
|
|
36
|
-
return ROOT_TYPE_LOCALE.INTERFACE;
|
|
37
|
-
case isObjectType(graphLQLNamedType):
|
|
38
|
-
return ROOT_TYPE_LOCALE.TYPE;
|
|
39
|
-
case isInputType(graphLQLNamedType):
|
|
40
|
-
return ROOT_TYPE_LOCALE.INPUT;
|
|
41
|
-
case isScalarType(graphLQLNamedType):
|
|
42
|
-
return ROOT_TYPE_LOCALE.SCALAR;
|
|
43
|
-
case isDirectiveType(graphLQLNamedType):
|
|
44
|
-
return ROOT_TYPE_LOCALE.DIRECTIVE;
|
|
45
|
-
case isOperation(graphLQLNamedType):
|
|
46
|
-
return ROOT_TYPE_LOCALE.OPERATION;
|
|
47
|
-
}
|
|
48
|
-
return undefined;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
static toLink = (type, name, operation, options) => {
|
|
52
|
-
const fallback = {
|
|
53
|
-
text: name,
|
|
54
|
-
url: "#",
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
if (typeof type === "undefined") {
|
|
58
|
-
return fallback;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (hasProperty(options, "skipDocDirective")) {
|
|
62
|
-
if (hasDirective(type, options.skipDocDirective)) {
|
|
63
|
-
return fallback;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const graphLQLNamedType = getNamedType(type);
|
|
68
|
-
|
|
69
|
-
let category = Link.getLinkCategory(graphLQLNamedType);
|
|
70
|
-
|
|
71
|
-
if (
|
|
72
|
-
typeof category === "undefined" ||
|
|
73
|
-
typeof graphLQLNamedType === "undefined" ||
|
|
74
|
-
graphLQLNamedType === null
|
|
75
|
-
) {
|
|
76
|
-
return fallback;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// special case for relation map
|
|
80
|
-
if (category === ROOT_TYPE_LOCALE.OPERATION) {
|
|
81
|
-
if (typeof operation === "undefined") {
|
|
82
|
-
return fallback;
|
|
83
|
-
}
|
|
84
|
-
category = operation;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const text = graphLQLNamedType.name || graphLQLNamedType;
|
|
88
|
-
const deprecated =
|
|
89
|
-
hasProperty(options, "printDeprecated") &&
|
|
90
|
-
options.printDeprecated === OPTION_DEPRECATED.GROUP &&
|
|
91
|
-
isDeprecated(type)
|
|
92
|
-
? DEPRECATED
|
|
93
|
-
: "";
|
|
94
|
-
const group = hasProperty(options, "groups")
|
|
95
|
-
? getGroup(type, options.groups, category.plural)
|
|
96
|
-
: "";
|
|
97
|
-
const url = pathUrl.join(
|
|
98
|
-
options.basePath,
|
|
99
|
-
deprecated,
|
|
100
|
-
group,
|
|
101
|
-
category.plural,
|
|
102
|
-
toSlug(text),
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
return {
|
|
106
|
-
text: text,
|
|
107
|
-
url: url,
|
|
108
|
-
};
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
static getRelationLink = (category, type, options) => {
|
|
112
|
-
if (typeof category === "undefined") {
|
|
113
|
-
return "";
|
|
114
|
-
}
|
|
115
|
-
const link = Link.toLink(type, type.name, category, options);
|
|
116
|
-
return `[\`${link.text}\`](${link.url}) <Badge class="secondary" text="${category.singular}"/>`;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
static printParentLink = (type, options) => {
|
|
120
|
-
return hasProperty(type, "type")
|
|
121
|
-
? `<Bullet />${Link.printLink(type.type, {
|
|
122
|
-
withAttributes: true,
|
|
123
|
-
...options,
|
|
124
|
-
})}`
|
|
125
|
-
: "";
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
static hasOptionWithAttributes = (options) =>
|
|
129
|
-
hasProperty(options, "withAttributes") === true &&
|
|
130
|
-
options.withAttributes === true;
|
|
131
|
-
|
|
132
|
-
static hasOptionParentType = (options) =>
|
|
133
|
-
hasProperty(options, "parentTypePrefix") &&
|
|
134
|
-
options.parentTypePrefix === true &&
|
|
135
|
-
hasProperty(options, "parentType") &&
|
|
136
|
-
typeof options.parentType !== "undefined" &&
|
|
137
|
-
options.parentType !== null;
|
|
138
|
-
|
|
139
|
-
static printLink = (type, options) => {
|
|
140
|
-
let text;
|
|
141
|
-
|
|
142
|
-
const link = Link.toLink(
|
|
143
|
-
type,
|
|
144
|
-
getTypeName(type, type.toString()),
|
|
145
|
-
undefined,
|
|
146
|
-
options,
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
if (Link.hasOptionWithAttributes(options) === false) {
|
|
150
|
-
text =
|
|
151
|
-
Link.hasOptionParentType(options) === true
|
|
152
|
-
? `<code style={{ fontWeight: 'normal' }}>${options.parentType}.<b>${link.text}</b></code>`
|
|
153
|
-
: `\`${link.text}\``;
|
|
154
|
-
return `[${text}](${link.url})`;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
text = Link.printLinkAttributes(type, link.text);
|
|
158
|
-
|
|
159
|
-
return `[\`${text}\`](${link.url})`;
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
static printLinkAttributes = (type, text) => {
|
|
163
|
-
if (typeof type === "undefined" || type === null) {
|
|
164
|
-
return text ?? "";
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (!isLeafType(type, text) && typeof type.ofType != "undefined") {
|
|
168
|
-
text = Link.printLinkAttributes(type.ofType, text);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (isListType(type)) {
|
|
172
|
-
return `[${text}]`;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (isNonNullType(type)) {
|
|
176
|
-
return `${text}!`;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return text;
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
module.exports = Link;
|
package/src/printer.js
DELETED
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
graphql: {
|
|
3
|
-
getTypeName,
|
|
4
|
-
hasDirective,
|
|
5
|
-
isDirectiveType,
|
|
6
|
-
isEnumType,
|
|
7
|
-
isInputType,
|
|
8
|
-
isInterfaceType,
|
|
9
|
-
isObjectType,
|
|
10
|
-
isOperation,
|
|
11
|
-
isScalarType,
|
|
12
|
-
isUnionType,
|
|
13
|
-
},
|
|
14
|
-
} = require("@graphql-markdown/utils");
|
|
15
|
-
|
|
16
|
-
const {
|
|
17
|
-
url: { pathUrl },
|
|
18
|
-
} = require("@graphql-markdown/utils");
|
|
19
|
-
|
|
20
|
-
const { printRelations } = require("./relation");
|
|
21
|
-
const { printDescription } = require("./common");
|
|
22
|
-
const { printCustomDirectives, printCustomTags } = require("./directive");
|
|
23
|
-
const {
|
|
24
|
-
printCodeDirective,
|
|
25
|
-
printCodeEnum,
|
|
26
|
-
printCodeInput,
|
|
27
|
-
printCodeInterface,
|
|
28
|
-
printCodeObject,
|
|
29
|
-
printCodeOperation,
|
|
30
|
-
printCodeScalar,
|
|
31
|
-
printCodeUnion,
|
|
32
|
-
printDirectiveMetadata,
|
|
33
|
-
printEnumMetadata,
|
|
34
|
-
printInputMetadata,
|
|
35
|
-
printInterfaceMetadata,
|
|
36
|
-
printObjectMetadata,
|
|
37
|
-
printOperationMetadata,
|
|
38
|
-
printScalarMetadata,
|
|
39
|
-
printUnionMetadata,
|
|
40
|
-
} = require("./graphql");
|
|
41
|
-
const {
|
|
42
|
-
FRONT_MATTER,
|
|
43
|
-
MARKDOWN_EOC,
|
|
44
|
-
MARKDOWN_EOL,
|
|
45
|
-
MARKDOWN_EOP,
|
|
46
|
-
MARKDOWN_SOC,
|
|
47
|
-
} = require("./const/strings");
|
|
48
|
-
const mdx = require("./const/mdx");
|
|
49
|
-
|
|
50
|
-
const {
|
|
51
|
-
DEFAULT_OPTIONS,
|
|
52
|
-
PRINT_TYPE_DEFAULT_OPTIONS,
|
|
53
|
-
} = require("./const/options");
|
|
54
|
-
|
|
55
|
-
class Printer {
|
|
56
|
-
static options;
|
|
57
|
-
|
|
58
|
-
static init = (
|
|
59
|
-
schema,
|
|
60
|
-
baseURL,
|
|
61
|
-
linkRoot = "/",
|
|
62
|
-
{ customDirectives, groups, printTypeOptions, skipDocDirective } = {
|
|
63
|
-
customDirectives: undefined,
|
|
64
|
-
groups: undefined,
|
|
65
|
-
printTypeOptions: PRINT_TYPE_DEFAULT_OPTIONS,
|
|
66
|
-
skipDocDirective: undefined,
|
|
67
|
-
},
|
|
68
|
-
) => {
|
|
69
|
-
if (typeof Printer.options !== "undefined" && Printer.options !== null) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
Printer.options = {
|
|
74
|
-
...DEFAULT_OPTIONS,
|
|
75
|
-
basePath: pathUrl.join(linkRoot, baseURL),
|
|
76
|
-
codeSection:
|
|
77
|
-
printTypeOptions?.codeSection ?? PRINT_TYPE_DEFAULT_OPTIONS.codeSection,
|
|
78
|
-
customDirectives,
|
|
79
|
-
groups,
|
|
80
|
-
parentTypePrefix:
|
|
81
|
-
printTypeOptions?.parentTypePrefix ??
|
|
82
|
-
PRINT_TYPE_DEFAULT_OPTIONS.parentTypePrefix,
|
|
83
|
-
printDeprecated:
|
|
84
|
-
printTypeOptions?.deprecated ??
|
|
85
|
-
PRINT_TYPE_DEFAULT_OPTIONS.printDeprecated,
|
|
86
|
-
relatedTypeSection:
|
|
87
|
-
printTypeOptions?.relatedTypeSection ??
|
|
88
|
-
PRINT_TYPE_DEFAULT_OPTIONS.relatedTypeSection,
|
|
89
|
-
schema,
|
|
90
|
-
skipDocDirective: skipDocDirective ?? undefined,
|
|
91
|
-
typeBadges:
|
|
92
|
-
printTypeOptions?.typeBadges ?? PRINT_TYPE_DEFAULT_OPTIONS.typeBadges,
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
static printHeader = (id, title, options) => {
|
|
97
|
-
const { toc, pagination } = {
|
|
98
|
-
toc: true,
|
|
99
|
-
pagination: true,
|
|
100
|
-
...(options.header ?? undefined),
|
|
101
|
-
};
|
|
102
|
-
const pagination_buttons = pagination
|
|
103
|
-
? []
|
|
104
|
-
: ["pagination_next: null", "pagination_prev: null"];
|
|
105
|
-
|
|
106
|
-
const header = [
|
|
107
|
-
FRONT_MATTER,
|
|
108
|
-
`id: ${id}`,
|
|
109
|
-
`title: ${title}`,
|
|
110
|
-
`hide_table_of_contents: ${!toc}`,
|
|
111
|
-
...pagination_buttons,
|
|
112
|
-
FRONT_MATTER,
|
|
113
|
-
];
|
|
114
|
-
|
|
115
|
-
return header.join(MARKDOWN_EOL);
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
static printDescription = printDescription;
|
|
119
|
-
|
|
120
|
-
static printCode = (type, options) => {
|
|
121
|
-
let code = "";
|
|
122
|
-
|
|
123
|
-
if (
|
|
124
|
-
typeof options?.codeSection === "undefined" ||
|
|
125
|
-
options.codeSection !== true
|
|
126
|
-
) {
|
|
127
|
-
return code;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
switch (true) {
|
|
131
|
-
case isOperation(type):
|
|
132
|
-
code += printCodeOperation(type, options);
|
|
133
|
-
break;
|
|
134
|
-
case isEnumType(type):
|
|
135
|
-
code += printCodeEnum(type, options);
|
|
136
|
-
break;
|
|
137
|
-
case isUnionType(type, options):
|
|
138
|
-
code += printCodeUnion(type, options);
|
|
139
|
-
break;
|
|
140
|
-
case isInterfaceType(type, options):
|
|
141
|
-
code += printCodeInterface(type, options);
|
|
142
|
-
break;
|
|
143
|
-
case isObjectType(type):
|
|
144
|
-
code += printCodeObject(type, options);
|
|
145
|
-
break;
|
|
146
|
-
case isInputType(type):
|
|
147
|
-
code += printCodeInput(type, options);
|
|
148
|
-
break;
|
|
149
|
-
case isScalarType(type):
|
|
150
|
-
code += printCodeScalar(type, options);
|
|
151
|
-
break;
|
|
152
|
-
case isDirectiveType(type):
|
|
153
|
-
code += printCodeDirective(type, options);
|
|
154
|
-
break;
|
|
155
|
-
default:
|
|
156
|
-
code += `"${getTypeName(type)}" not supported`;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return MARKDOWN_SOC + code.trim() + MARKDOWN_EOC;
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
static printCustomDirectives = printCustomDirectives;
|
|
163
|
-
|
|
164
|
-
static printCustomTags = printCustomTags;
|
|
165
|
-
|
|
166
|
-
static printTypeMetadata = (type, options) => {
|
|
167
|
-
let metadata;
|
|
168
|
-
|
|
169
|
-
switch (true) {
|
|
170
|
-
case isScalarType(type):
|
|
171
|
-
return printScalarMetadata(type, options);
|
|
172
|
-
case isEnumType(type):
|
|
173
|
-
return printEnumMetadata(type, options);
|
|
174
|
-
case isUnionType(type):
|
|
175
|
-
return printUnionMetadata(type, options);
|
|
176
|
-
case isObjectType(type):
|
|
177
|
-
return printObjectMetadata(type, options);
|
|
178
|
-
case isInterfaceType(type):
|
|
179
|
-
return printInterfaceMetadata(type, options);
|
|
180
|
-
case isInputType(type):
|
|
181
|
-
return printInputMetadata(type, options);
|
|
182
|
-
case isDirectiveType(type):
|
|
183
|
-
return printDirectiveMetadata(type, options);
|
|
184
|
-
case isOperation(type):
|
|
185
|
-
return printOperationMetadata(type, options);
|
|
186
|
-
default:
|
|
187
|
-
return metadata;
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
static printRelations = (type, options) => {
|
|
192
|
-
if (Printer.options.relatedTypeSection !== true) {
|
|
193
|
-
return "";
|
|
194
|
-
}
|
|
195
|
-
return printRelations(type, options);
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
static printType = (name, type, options) => {
|
|
199
|
-
if (
|
|
200
|
-
typeof type === "undefined" ||
|
|
201
|
-
type === null ||
|
|
202
|
-
typeof name === "undefined" ||
|
|
203
|
-
name === null ||
|
|
204
|
-
hasDirective(type, Printer.options.skipDocDirective)
|
|
205
|
-
) {
|
|
206
|
-
return undefined;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const printTypeOptions = {
|
|
210
|
-
...DEFAULT_OPTIONS,
|
|
211
|
-
...Printer.options,
|
|
212
|
-
...options,
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
const header = Printer.printHeader(name, getTypeName(type), {
|
|
216
|
-
...printTypeOptions,
|
|
217
|
-
header: options,
|
|
218
|
-
});
|
|
219
|
-
const description = Printer.printDescription(type);
|
|
220
|
-
const code = Printer.printCode(type, printTypeOptions);
|
|
221
|
-
const customDirectives = Printer.printCustomDirectives(
|
|
222
|
-
type,
|
|
223
|
-
printTypeOptions,
|
|
224
|
-
);
|
|
225
|
-
const tags = Printer.printCustomTags(type, printTypeOptions);
|
|
226
|
-
const metadata = Printer.printTypeMetadata(type, printTypeOptions);
|
|
227
|
-
const relations = Printer.printRelations(type, printTypeOptions);
|
|
228
|
-
|
|
229
|
-
return [
|
|
230
|
-
header,
|
|
231
|
-
mdx,
|
|
232
|
-
tags,
|
|
233
|
-
description,
|
|
234
|
-
code,
|
|
235
|
-
customDirectives,
|
|
236
|
-
metadata,
|
|
237
|
-
relations,
|
|
238
|
-
].join(MARKDOWN_EOP);
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
module.exports = { Printer, DEFAULT_OPTIONS };
|
package/src/relation.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
graphql: {
|
|
3
|
-
isOperation,
|
|
4
|
-
getRelationOfReturn,
|
|
5
|
-
getRelationOfField,
|
|
6
|
-
getRelationOfImplementation,
|
|
7
|
-
},
|
|
8
|
-
} = require("@graphql-markdown/utils");
|
|
9
|
-
|
|
10
|
-
const { getRelationLink } = require("./link");
|
|
11
|
-
const {
|
|
12
|
-
ROOT_TYPE_LOCALE,
|
|
13
|
-
HEADER_SECTION_LEVEL,
|
|
14
|
-
MARKDOWN_EOP,
|
|
15
|
-
} = require("./const/strings");
|
|
16
|
-
|
|
17
|
-
const getRootTypeLocaleFromString = (text) => {
|
|
18
|
-
for (const [type, props] of Object.entries(ROOT_TYPE_LOCALE)) {
|
|
19
|
-
if (Object.values(props).includes(text)) {
|
|
20
|
-
return ROOT_TYPE_LOCALE[type];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return undefined;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const printRelationOf = (type, section, getRelation, options) => {
|
|
27
|
-
if (
|
|
28
|
-
typeof type === "undefined" ||
|
|
29
|
-
typeof getRelation !== "function" ||
|
|
30
|
-
typeof options === "undefined" ||
|
|
31
|
-
isOperation(type)
|
|
32
|
-
) {
|
|
33
|
-
return "";
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const relations = getRelation(type, options.schema);
|
|
37
|
-
|
|
38
|
-
if (typeof relations === "undefined") {
|
|
39
|
-
return "";
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
let data = [];
|
|
43
|
-
for (const [relation, types] of Object.entries(relations)) {
|
|
44
|
-
if (types.length === 0) {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const category = getRootTypeLocaleFromString(relation);
|
|
49
|
-
data = data.concat(types.map((t) => getRelationLink(category, t, options)));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (data.length === 0) {
|
|
53
|
-
return "";
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const content = [...data]
|
|
57
|
-
.sort((a, b) => a.localeCompare(b))
|
|
58
|
-
.join("<Bullet />");
|
|
59
|
-
|
|
60
|
-
return `${HEADER_SECTION_LEVEL} ${section}${MARKDOWN_EOP}${content}${MARKDOWN_EOP}`;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const printRelations = (type, options) => {
|
|
64
|
-
const relations = {
|
|
65
|
-
"Returned by": getRelationOfReturn,
|
|
66
|
-
"Member of": getRelationOfField,
|
|
67
|
-
"Implemented by": getRelationOfImplementation,
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
let data = "";
|
|
71
|
-
for (const [section, getRelation] of Object.entries(relations)) {
|
|
72
|
-
data += printRelationOf(type, section, getRelation, options);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return data;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
module.exports = {
|
|
79
|
-
getRootTypeLocaleFromString,
|
|
80
|
-
printRelationOf,
|
|
81
|
-
printRelations,
|
|
82
|
-
};
|