@graphql-markdown/printer-legacy 1.4.1 → 1.4.3

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/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "bugs": {
6
6
  "url": "https://github.com/graphql-markdown/graphql-markdown/issues"
7
7
  },
8
- "version": "1.4.1",
8
+ "version": "1.4.3",
9
9
  "license": "MIT",
10
10
  "main": "src/index.js",
11
11
  "repository": {
package/src/badge.js CHANGED
@@ -63,6 +63,7 @@ function printBadge({ text, classname }) {
63
63
  }
64
64
 
65
65
  module.exports = {
66
+ DEFAULT_CSS_CLASSNAME,
66
67
  getTypeBadges,
67
68
  printBadge,
68
69
  printBadges,
@@ -4,19 +4,25 @@ const OPTION_DEPRECATED = {
4
4
  SKIP: "skip",
5
5
  };
6
6
 
7
- const DEFAULT_OPTIONS = {
8
- schema: undefined,
9
- basePath: "/",
10
- groups: {},
7
+ const PRINT_TYPE_DEFAULT_OPTIONS = {
11
8
  parentTypePrefix: true,
9
+ printDeprecated: OPTION_DEPRECATED.DEFAULT,
10
+ codeSection: true,
12
11
  relatedTypeSection: true,
13
12
  typeBadges: true,
14
- skipDocDirective: undefined,
15
- printDeprecated: OPTION_DEPRECATED.DEFAULT,
13
+ };
14
+
15
+ const DEFAULT_OPTIONS = {
16
+ ...PRINT_TYPE_DEFAULT_OPTIONS,
17
+ basePath: "/",
16
18
  customDirectives: {},
19
+ groups: {},
20
+ schema: undefined,
21
+ skipDocDirective: undefined,
17
22
  };
18
23
 
19
24
  module.exports = {
20
- OPTION_DEPRECATED,
21
25
  DEFAULT_OPTIONS,
26
+ OPTION_DEPRECATED,
27
+ PRINT_TYPE_DEFAULT_OPTIONS,
22
28
  };
package/src/link.js CHANGED
@@ -22,28 +22,28 @@ const {
22
22
  } = require("@graphql-markdown/utils");
23
23
 
24
24
  const { getGroup } = require("./group");
25
- const { ROOT_TYPE_LOCALE, DEPRECATED } = require("./const/strings");
25
+ const { DEPRECATED, ROOT_TYPE_LOCALE } = require("./const/strings");
26
26
  const { OPTION_DEPRECATED } = require("./const/options");
27
27
 
28
28
  class Link {
29
29
  static getLinkCategory = (graphLQLNamedType) => {
30
30
  switch (true) {
31
+ case isDirectiveType(graphLQLNamedType):
32
+ return ROOT_TYPE_LOCALE.DIRECTIVE;
31
33
  case isEnumType(graphLQLNamedType):
32
34
  return ROOT_TYPE_LOCALE.ENUM;
33
- case isUnionType(graphLQLNamedType):
34
- return ROOT_TYPE_LOCALE.UNION;
35
+ case isInputType(graphLQLNamedType):
36
+ return ROOT_TYPE_LOCALE.INPUT;
35
37
  case isInterfaceType(graphLQLNamedType):
36
38
  return ROOT_TYPE_LOCALE.INTERFACE;
37
39
  case isObjectType(graphLQLNamedType):
38
40
  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
41
  case isOperation(graphLQLNamedType):
46
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
47
  }
48
48
  return undefined;
49
49
  };
@@ -110,10 +110,9 @@ class Link {
110
110
 
111
111
  static getRelationLink = (category, type, options) => {
112
112
  if (typeof category === "undefined") {
113
- return "";
113
+ return undefined;
114
114
  }
115
- const link = Link.toLink(type, type.name, category, options);
116
- return `[\`${link.text}\`](${link.url}) <Badge class="secondary" text="${category.singular}"/>`;
115
+ return Link.toLink(type, type.name, category, options);
117
116
  };
118
117
 
119
118
  static printParentLink = (type, options) => {
package/src/printer.js CHANGED
@@ -1,15 +1,15 @@
1
1
  const {
2
2
  graphql: {
3
3
  getTypeName,
4
- isOperation,
4
+ hasDirective,
5
+ isDirectiveType,
5
6
  isEnumType,
6
- isUnionType,
7
+ isInputType,
7
8
  isInterfaceType,
8
9
  isObjectType,
9
- isInputType,
10
+ isOperation,
10
11
  isScalarType,
11
- isDirectiveType,
12
- hasDirective,
12
+ isUnionType,
13
13
  },
14
14
  } = require("@graphql-markdown/utils");
15
15
 
@@ -21,33 +21,36 @@ const { printRelations } = require("./relation");
21
21
  const { printDescription } = require("./common");
22
22
  const { printCustomDirectives, printCustomTags } = require("./directive");
23
23
  const {
24
- printOperationMetadata,
25
- printCodeOperation,
24
+ printCodeDirective,
26
25
  printCodeEnum,
27
- printEnumMetadata,
28
- printCodeUnion,
29
- printUnionMetadata,
26
+ printCodeInput,
30
27
  printCodeInterface,
31
- printInterfaceMetadata,
32
28
  printCodeObject,
33
- printObjectMetadata,
34
- printCodeInput,
35
- printInputMetadata,
29
+ printCodeOperation,
36
30
  printCodeScalar,
37
- printScalarMetadata,
38
- printCodeDirective,
31
+ printCodeUnion,
39
32
  printDirectiveMetadata,
33
+ printEnumMetadata,
34
+ printInputMetadata,
35
+ printInterfaceMetadata,
36
+ printObjectMetadata,
37
+ printOperationMetadata,
38
+ printScalarMetadata,
39
+ printUnionMetadata,
40
40
  } = require("./graphql");
41
41
  const {
42
- MARKDOWN_EOP,
42
+ FRONT_MATTER,
43
+ MARKDOWN_EOC,
43
44
  MARKDOWN_EOL,
45
+ MARKDOWN_EOP,
44
46
  MARKDOWN_SOC,
45
- MARKDOWN_EOC,
46
- FRONT_MATTER,
47
47
  } = require("./const/strings");
48
48
  const mdx = require("./const/mdx");
49
49
 
50
- const { DEFAULT_OPTIONS, OPTION_DEPRECATED } = require("./const/options");
50
+ const {
51
+ DEFAULT_OPTIONS,
52
+ PRINT_TYPE_DEFAULT_OPTIONS,
53
+ } = require("./const/options");
51
54
 
52
55
  class Printer {
53
56
  static options;
@@ -56,11 +59,11 @@ class Printer {
56
59
  schema,
57
60
  baseURL,
58
61
  linkRoot = "/",
59
- { groups, printTypeOptions, skipDocDirective, customDirectives } = {
62
+ { customDirectives, groups, printTypeOptions, skipDocDirective } = {
63
+ customDirectives: undefined,
60
64
  groups: undefined,
61
- printTypeOptions: undefined,
65
+ printTypeOptions: PRINT_TYPE_DEFAULT_OPTIONS,
62
66
  skipDocDirective: undefined,
63
- customDirectives: undefined,
64
67
  },
65
68
  ) => {
66
69
  if (typeof Printer.options !== "undefined" && Printer.options !== null) {
@@ -69,16 +72,24 @@ class Printer {
69
72
 
70
73
  Printer.options = {
71
74
  ...DEFAULT_OPTIONS,
72
- schema,
73
75
  basePath: pathUrl.join(linkRoot, baseURL),
76
+ codeSection:
77
+ printTypeOptions?.codeSection ?? PRINT_TYPE_DEFAULT_OPTIONS.codeSection,
78
+ customDirectives,
74
79
  groups,
75
- parentTypePrefix: printTypeOptions?.parentTypePrefix ?? true,
76
- relatedTypeSection: printTypeOptions?.relatedTypeSection ?? true,
77
- typeBadges: printTypeOptions?.typeBadges ?? true,
78
- skipDocDirective: skipDocDirective ?? undefined,
80
+ parentTypePrefix:
81
+ printTypeOptions?.parentTypePrefix ??
82
+ PRINT_TYPE_DEFAULT_OPTIONS.parentTypePrefix,
79
83
  printDeprecated:
80
- printTypeOptions?.deprecated ?? OPTION_DEPRECATED.DEFAULT,
81
- customDirectives,
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,
82
93
  };
83
94
  };
84
95
 
@@ -109,6 +120,13 @@ class Printer {
109
120
  static printCode = (type, options) => {
110
121
  let code = "";
111
122
 
123
+ if (
124
+ typeof options?.codeSection === "undefined" ||
125
+ options.codeSection !== true
126
+ ) {
127
+ return code;
128
+ }
129
+
112
130
  switch (true) {
113
131
  case isOperation(type):
114
132
  code += printCodeOperation(type, options);
package/src/relation.js CHANGED
@@ -1,17 +1,18 @@
1
1
  const {
2
2
  graphql: {
3
- isOperation,
4
- getRelationOfReturn,
5
3
  getRelationOfField,
6
4
  getRelationOfImplementation,
5
+ getRelationOfReturn,
6
+ isOperation,
7
7
  },
8
8
  } = require("@graphql-markdown/utils");
9
9
 
10
10
  const { getRelationLink } = require("./link");
11
+ const { DEFAULT_CSS_CLASSNAME, printBadge } = require("./badge");
11
12
  const {
12
- ROOT_TYPE_LOCALE,
13
13
  HEADER_SECTION_LEVEL,
14
14
  MARKDOWN_EOP,
15
+ ROOT_TYPE_LOCALE,
15
16
  } = require("./const/strings");
16
17
 
17
18
  const getRootTypeLocaleFromString = (text) => {
@@ -46,7 +47,16 @@ const printRelationOf = (type, section, getRelation, options) => {
46
47
  }
47
48
 
48
49
  const category = getRootTypeLocaleFromString(relation);
49
- data = data.concat(types.map((t) => getRelationLink(category, t, options)));
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
+ );
50
60
  }
51
61
 
52
62
  if (data.length === 0) {