@graphql-markdown/printer-legacy 1.4.0 → 1.4.2

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.0",
8
+ "version": "1.4.2",
9
9
  "license": "MIT",
10
10
  "main": "src/index.js",
11
11
  "repository": {
@@ -22,7 +22,7 @@
22
22
  "stryker": "stryker run"
23
23
  },
24
24
  "dependencies": {
25
- "@graphql-markdown/utils": "^1.5.0"
25
+ "@graphql-markdown/utils": "^1.5.1"
26
26
  },
27
27
  "directories": {
28
28
  "test": "tests"
@@ -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/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);