@graphql-markdown/printer-legacy 1.3.0 → 1.3.1

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.3.0",
8
+ "version": "1.3.1",
9
9
  "license": "MIT",
10
10
  "main": "src/index.js",
11
11
  "repository": {
package/src/code.js CHANGED
@@ -3,10 +3,14 @@ const {
3
3
  graphql: { getDefaultValue, getTypeName, isDeprecated, hasDirective },
4
4
  } = require("@graphql-markdown/utils");
5
5
 
6
- const { MARKDOWN_EOL, DEPRECATED } = require("./const/strings");
6
+ const {
7
+ MARKDOWN_EOL,
8
+ DEPRECATED,
9
+ MARKDOWN_CODE_INDENTATION,
10
+ } = require("./const/strings");
7
11
  const { OPTION_DEPRECATED } = require("./const/options");
8
12
 
9
- const printCodeField = (type, options = {}) => {
13
+ const printCodeField = (type, options = {}, indentationLevel = 0) => {
10
14
  const skipDirective =
11
15
  hasProperty(options, "skipDocDirective") &&
12
16
  hasDirective(type, options.skipDocDirective) === true;
@@ -19,7 +23,7 @@ const printCodeField = (type, options = {}) => {
19
23
  }
20
24
 
21
25
  let code = `${getTypeName(type)}`;
22
- code += printCodeArguments(type);
26
+ code += printCodeArguments(type, indentationLevel + 1);
23
27
  code += `: ${getTypeName(type.type)}`;
24
28
  code += isDeprecated(type) ? ` @${DEPRECATED}` : "";
25
29
  code += MARKDOWN_EOL;
@@ -27,11 +31,14 @@ const printCodeField = (type, options = {}) => {
27
31
  return code;
28
32
  };
29
33
 
30
- const printCodeArguments = (type) => {
34
+ const printCodeArguments = (type, indentationLevel = 1) => {
31
35
  if (!hasProperty(type, "args") || type.args.length === 0) {
32
36
  return "";
33
37
  }
34
38
 
39
+ const argIndentation = MARKDOWN_CODE_INDENTATION.repeat(indentationLevel);
40
+ const parentIndentation =
41
+ indentationLevel === 1 ? "" : MARKDOWN_CODE_INDENTATION;
35
42
  let code = `(${MARKDOWN_EOL}`;
36
43
  code += type.args.reduce((r, v) => {
37
44
  const defaultValue = getDefaultValue(v);
@@ -40,9 +47,9 @@ const printCodeArguments = (type) => {
40
47
  const printedDefault = hasDefaultValue ? ` = ${getDefaultValue(v)}` : "";
41
48
  const propType = v.type.toString();
42
49
  const propName = v.name.toString();
43
- return `${r} ${propName}: ${propType}${printedDefault}${MARKDOWN_EOL}`;
50
+ return `${r}${argIndentation}${propName}: ${propType}${printedDefault}${MARKDOWN_EOL}`;
44
51
  }, "");
45
- code += `)`;
52
+ code += `${parentIndentation})`;
46
53
 
47
54
  return code;
48
55
  };
@@ -20,6 +20,7 @@ const MARKDOWN_EOL = "\n";
20
20
  const MARKDOWN_EOP = "\n\n";
21
21
  const MARKDOWN_SOC = `${MARKDOWN_EOL}\`\`\`graphql${MARKDOWN_EOL}`;
22
22
  const MARKDOWN_EOC = `${MARKDOWN_EOL}\`\`\`${MARKDOWN_EOL}`;
23
+ const MARKDOWN_CODE_INDENTATION = " ";
23
24
  const FRONT_MATTER = "---";
24
25
 
25
26
  const DEPRECATED = "deprecated";
@@ -34,6 +35,7 @@ module.exports = {
34
35
  MARKDOWN_EOP,
35
36
  MARKDOWN_SOC,
36
37
  MARKDOWN_EOC,
38
+ MARKDOWN_CODE_INDENTATION,
37
39
  FRONT_MATTER,
38
40
  DEPRECATED,
39
41
  };
@@ -5,7 +5,7 @@ const {
5
5
 
6
6
  const { printSection, printMetadataSection } = require("../section");
7
7
  const { printCodeField } = require("../code");
8
- const { MARKDOWN_EOL } = require("../const/strings");
8
+ const { MARKDOWN_EOL, MARKDOWN_CODE_INDENTATION } = require("../const/strings");
9
9
 
10
10
  const printInterfaceMetadata = (type, options) => {
11
11
  if (hasMethod(type, "getInterfaces") === false) {
@@ -38,8 +38,8 @@ const printCodeType = (type, entity, options) => {
38
38
  : "";
39
39
  const typeFields = getFields(type)
40
40
  .map((field) => {
41
- const f = printCodeField(field, options);
42
- return f.length > 0 ? ` ${f}` : "";
41
+ const f = printCodeField(field, options, 1);
42
+ return f.length > 0 ? `${MARKDOWN_CODE_INDENTATION}${f}` : "";
43
43
  })
44
44
  .filter((field) => field.length > 0)
45
45
  .join("");