@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
@@ -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
- };
@@ -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
@@ -1,3 +0,0 @@
1
- const { Printer } = require("./printer");
2
-
3
- module.exports = Printer;
package/src/link.js DELETED
@@ -1,182 +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 { DEPRECATED, ROOT_TYPE_LOCALE } = require("./const/strings");
26
- const { OPTION_DEPRECATED } = require("./const/options");
27
-
28
- class Link {
29
- static getLinkCategory = (graphLQLNamedType) => {
30
- switch (true) {
31
- case isDirectiveType(graphLQLNamedType):
32
- return ROOT_TYPE_LOCALE.DIRECTIVE;
33
- case isEnumType(graphLQLNamedType):
34
- return ROOT_TYPE_LOCALE.ENUM;
35
- case isInputType(graphLQLNamedType):
36
- return ROOT_TYPE_LOCALE.INPUT;
37
- case isInterfaceType(graphLQLNamedType):
38
- return ROOT_TYPE_LOCALE.INTERFACE;
39
- case isObjectType(graphLQLNamedType):
40
- return ROOT_TYPE_LOCALE.TYPE;
41
- case isOperation(graphLQLNamedType):
42
- return ROOT_TYPE_LOCALE.OPERATION;
43
- case isScalarType(graphLQLNamedType):
44
- return ROOT_TYPE_LOCALE.SCALAR;
45
- case isUnionType(graphLQLNamedType):
46
- return ROOT_TYPE_LOCALE.UNION;
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 undefined;
114
- }
115
- return Link.toLink(type, type.name, category, options);
116
- };
117
-
118
- static printParentLink = (type, options) => {
119
- return hasProperty(type, "type")
120
- ? `<Bullet />${Link.printLink(type.type, {
121
- withAttributes: true,
122
- ...options,
123
- })}`
124
- : "";
125
- };
126
-
127
- static hasOptionWithAttributes = (options) =>
128
- hasProperty(options, "withAttributes") === true &&
129
- options.withAttributes === true;
130
-
131
- static hasOptionParentType = (options) =>
132
- hasProperty(options, "parentTypePrefix") &&
133
- options.parentTypePrefix === true &&
134
- hasProperty(options, "parentType") &&
135
- typeof options.parentType !== "undefined" &&
136
- options.parentType !== null;
137
-
138
- static printLink = (type, options) => {
139
- let text;
140
-
141
- const link = Link.toLink(
142
- type,
143
- getTypeName(type, type.toString()),
144
- undefined,
145
- options,
146
- );
147
-
148
- if (Link.hasOptionWithAttributes(options) === false) {
149
- text =
150
- Link.hasOptionParentType(options) === true
151
- ? `<code style={{ fontWeight: 'normal' }}>${options.parentType}.<b>${link.text}</b></code>`
152
- : `\`${link.text}\``;
153
- return `[${text}](${link.url})`;
154
- }
155
-
156
- text = Link.printLinkAttributes(type, link.text);
157
-
158
- return `[\`${text}\`](${link.url})`;
159
- };
160
-
161
- static printLinkAttributes = (type, text) => {
162
- if (typeof type === "undefined" || type === null) {
163
- return text ?? "";
164
- }
165
-
166
- if (!isLeafType(type, text) && typeof type.ofType != "undefined") {
167
- text = Link.printLinkAttributes(type.ofType, text);
168
- }
169
-
170
- if (isListType(type)) {
171
- return `[${text}]`;
172
- }
173
-
174
- if (isNonNullType(type)) {
175
- return `${text}!`;
176
- }
177
-
178
- return text;
179
- };
180
- }
181
-
182
- 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,92 +0,0 @@
1
- const {
2
- graphql: {
3
- getRelationOfField,
4
- getRelationOfImplementation,
5
- getRelationOfReturn,
6
- isOperation,
7
- },
8
- } = require("@graphql-markdown/utils");
9
-
10
- const { getRelationLink } = require("./link");
11
- const { DEFAULT_CSS_CLASSNAME, printBadge } = require("./badge");
12
- const {
13
- HEADER_SECTION_LEVEL,
14
- MARKDOWN_EOP,
15
- ROOT_TYPE_LOCALE,
16
- } = require("./const/strings");
17
-
18
- const getRootTypeLocaleFromString = (text) => {
19
- for (const [type, props] of Object.entries(ROOT_TYPE_LOCALE)) {
20
- if (Object.values(props).includes(text)) {
21
- return ROOT_TYPE_LOCALE[type];
22
- }
23
- }
24
- return undefined;
25
- };
26
-
27
- const printRelationOf = (type, section, getRelation, options) => {
28
- if (
29
- typeof type === "undefined" ||
30
- typeof getRelation !== "function" ||
31
- typeof options === "undefined" ||
32
- isOperation(type)
33
- ) {
34
- return "";
35
- }
36
-
37
- const relations = getRelation(type, options.schema);
38
-
39
- if (typeof relations === "undefined") {
40
- return "";
41
- }
42
-
43
- let data = [];
44
- for (const [relation, types] of Object.entries(relations)) {
45
- if (types.length === 0) {
46
- continue;
47
- }
48
-
49
- const category = getRootTypeLocaleFromString(relation);
50
- const badge = printBadge({
51
- text: category.singular,
52
- classname: DEFAULT_CSS_CLASSNAME,
53
- });
54
- data = data.concat(
55
- types.map((t) => {
56
- const link = getRelationLink(category, t, options);
57
- return link ? `[\`${link.text}\`](${link.url}) ${badge}` : "";
58
- }),
59
- );
60
- }
61
-
62
- if (data.length === 0) {
63
- return "";
64
- }
65
-
66
- const content = [...data]
67
- .sort((a, b) => a.localeCompare(b))
68
- .join("<Bullet />");
69
-
70
- return `${HEADER_SECTION_LEVEL} ${section}${MARKDOWN_EOP}${content}${MARKDOWN_EOP}`;
71
- };
72
-
73
- const printRelations = (type, options) => {
74
- const relations = {
75
- "Returned by": getRelationOfReturn,
76
- "Member of": getRelationOfField,
77
- "Implemented by": getRelationOfImplementation,
78
- };
79
-
80
- let data = "";
81
- for (const [section, getRelation] of Object.entries(relations)) {
82
- data += printRelationOf(type, section, getRelation, options);
83
- }
84
-
85
- return data;
86
- };
87
-
88
- module.exports = {
89
- getRootTypeLocaleFromString,
90
- printRelationOf,
91
- printRelations,
92
- };