@graphql-markdown/printer-legacy 1.4.3 → 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.
Files changed (66) hide show
  1. package/dist/badge.d.ts +5 -0
  2. package/dist/badge.js +64 -0
  3. package/dist/code.d.ts +3 -0
  4. package/dist/code.js +52 -0
  5. package/dist/common.d.ts +5 -0
  6. package/dist/common.js +46 -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 +16 -0
  10. package/dist/const/options.js +30 -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 +66 -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 +39 -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 +134 -0
  39. package/dist/printer.d.ts +19 -0
  40. package/dist/printer.js +152 -0
  41. package/dist/relation.d.ts +4 -0
  42. package/dist/relation.js +66 -0
  43. package/dist/section.d.ts +6 -0
  44. package/dist/section.js +130 -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
package/package.json CHANGED
@@ -5,24 +5,61 @@
5
5
  "bugs": {
6
6
  "url": "https://github.com/graphql-markdown/graphql-markdown/issues"
7
7
  },
8
- "version": "1.4.3",
8
+ "version": "1.5.0-next.0",
9
9
  "license": "MIT",
10
- "main": "src/index.js",
11
10
  "repository": {
12
11
  "type": "git",
13
- "url": "https://github.com/graphql-markdown/graphql-markdown.git"
12
+ "url": "graphql-markdown/graphql-markdown",
13
+ "directory": "packages/utils"
14
14
  },
15
15
  "author": {
16
16
  "name": "Gregory Heitz"
17
17
  },
18
+ "main": "dist/index.js",
19
+ "types": "dist/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "require": {
23
+ "types": "./dist/index.d.ts",
24
+ "default": "./dist/index.js"
25
+ },
26
+ "import": {
27
+ "types": "./dist/index.d.ts",
28
+ "default": "./dist/index.js"
29
+ },
30
+ "default": {
31
+ "types": "./dist/index.d.ts",
32
+ "default": "./dist/index.js"
33
+ }
34
+ },
35
+ "./*": {
36
+ "require": {
37
+ "types": "./dist/*.d.ts",
38
+ "default": "./dist/*.js"
39
+ },
40
+ "import": {
41
+ "types": "./dist/*.d.ts",
42
+ "default": "./dist/*.js"
43
+ },
44
+ "default": {
45
+ "types": "./dist/*.d.ts",
46
+ "default": "./dist/*.js"
47
+ }
48
+ },
49
+ "./package.json": "./package.json"
50
+ },
18
51
  "scripts": {
19
52
  "prepack": "pinst --disable",
20
53
  "postpack": "pinst --enable",
21
- "test": "jest",
22
- "stryker": "stryker run"
54
+ "stryker": "stryker run",
55
+ "clean": "rm -rf ./dist"
23
56
  },
24
57
  "dependencies": {
25
- "@graphql-markdown/utils": "^1.5.1"
58
+ "@graphql-markdown/graphql": "^1.0.0-next.0",
59
+ "@graphql-markdown/utils": "^1.6.0-next.0"
60
+ },
61
+ "devDependencies": {
62
+ "@graphql-markdown/types": "^1.0.0-next.0"
26
63
  },
27
64
  "directories": {
28
65
  "test": "tests"
@@ -31,6 +68,13 @@
31
68
  "node": ">=16.14"
32
69
  },
33
70
  "publishConfig": {
71
+ "directory": "dist",
34
72
  "access": "public"
35
- }
73
+ },
74
+ "typescript": {
75
+ "definition": "dist/index.d.ts"
76
+ },
77
+ "files": [
78
+ "dist"
79
+ ]
36
80
  }
package/src/badge.js DELETED
@@ -1,70 +0,0 @@
1
- const {
2
- graphql: { getNamedType, isDeprecated, isListType, isNonNullType },
3
- object: { hasProperty },
4
- string: { escapeMDX },
5
- } = require("@graphql-markdown/utils");
6
-
7
- const { getLinkCategory } = require("./link");
8
- const { getGroup } = require("./group");
9
-
10
- const DEFAULT_CSS_CLASSNAME = "badge--secondary";
11
-
12
- const getTypeBadges = (type) => {
13
- const rootType = hasProperty(type, "type") ? type.type : type;
14
-
15
- const badges = [];
16
-
17
- if (isDeprecated(type) === true) {
18
- badges.push({
19
- text: "deprecated",
20
- classname: "badge--deprecated badge--secondary",
21
- });
22
- }
23
-
24
- if (isNonNullType(rootType) === true) {
25
- badges.push({ text: "non-null", classname: DEFAULT_CSS_CLASSNAME });
26
- }
27
-
28
- if (isListType(rootType) === true) {
29
- badges.push({ text: "list", classname: DEFAULT_CSS_CLASSNAME });
30
- }
31
-
32
- const category = getLinkCategory(getNamedType(rootType));
33
- if (typeof category !== "undefined") {
34
- badges.push({ text: category, classname: DEFAULT_CSS_CLASSNAME });
35
- }
36
-
37
- const group = getGroup(rootType);
38
- if (typeof group !== "undefined" && group !== "") {
39
- badges.push({ text: group, classname: DEFAULT_CSS_CLASSNAME });
40
- }
41
-
42
- return badges;
43
- };
44
-
45
- const printBadges = (type, options) => {
46
- if (!hasProperty(options, "typeBadges") || options.typeBadges !== true) {
47
- return "";
48
- }
49
-
50
- const badges = getTypeBadges(type);
51
-
52
- if (badges.length === 0) {
53
- return "";
54
- }
55
-
56
- return badges.map((badge) => printBadge(badge)).join(" ");
57
- };
58
-
59
- function printBadge({ text, classname }) {
60
- const textString = hasProperty(text, "singular") ? text.singular : text;
61
- const formattedText = escapeMDX(textString);
62
- return `<Badge class="badge ${classname}" text="${formattedText}"/>`;
63
- }
64
-
65
- module.exports = {
66
- DEFAULT_CSS_CLASSNAME,
67
- getTypeBadges,
68
- printBadge,
69
- printBadges,
70
- };
package/src/code.js DELETED
@@ -1,60 +0,0 @@
1
- const {
2
- object: { hasProperty },
3
- graphql: { getDefaultValue, getTypeName, isDeprecated, hasDirective },
4
- } = require("@graphql-markdown/utils");
5
-
6
- const {
7
- MARKDOWN_EOL,
8
- DEPRECATED,
9
- MARKDOWN_CODE_INDENTATION,
10
- } = require("./const/strings");
11
- const { OPTION_DEPRECATED } = require("./const/options");
12
-
13
- const printCodeField = (type, options = {}, indentationLevel = 0) => {
14
- const skipDirective =
15
- hasProperty(options, "skipDocDirective") &&
16
- hasDirective(type, options.skipDocDirective) === true;
17
- const skipDeprecated =
18
- hasProperty(options, "printDeprecated") &&
19
- options.printDeprecated === OPTION_DEPRECATED.SKIP &&
20
- isDeprecated(type) === true;
21
- if (skipDirective === true || skipDeprecated === true) {
22
- return "";
23
- }
24
-
25
- let code = `${getTypeName(type)}`;
26
- code += printCodeArguments(type, indentationLevel + 1);
27
- code += `: ${getTypeName(type.type)}`;
28
- code += isDeprecated(type) ? ` @${DEPRECATED}` : "";
29
- code += MARKDOWN_EOL;
30
-
31
- return code;
32
- };
33
-
34
- const printCodeArguments = (type, indentationLevel = 1) => {
35
- if (!hasProperty(type, "args") || type.args.length === 0) {
36
- return "";
37
- }
38
-
39
- const argIndentation = MARKDOWN_CODE_INDENTATION.repeat(indentationLevel);
40
- const parentIndentation =
41
- indentationLevel === 1 ? "" : MARKDOWN_CODE_INDENTATION;
42
- let code = `(${MARKDOWN_EOL}`;
43
- code += type.args.reduce((r, v) => {
44
- const defaultValue = getDefaultValue(v);
45
- const hasDefaultValue =
46
- typeof defaultValue !== "undefined" && defaultValue !== null;
47
- const printedDefault = hasDefaultValue ? ` = ${getDefaultValue(v)}` : "";
48
- const propType = v.type.toString();
49
- const propName = v.name.toString();
50
- return `${r}${argIndentation}${propName}: ${propType}${printedDefault}${MARKDOWN_EOL}`;
51
- }, "");
52
- code += `${parentIndentation})`;
53
-
54
- return code;
55
- };
56
-
57
- module.exports = {
58
- printCodeField,
59
- printCodeArguments,
60
- };
package/src/common.js DELETED
@@ -1,66 +0,0 @@
1
- const {
2
- graphql: { isDeprecated, getConstDirectiveMap },
3
- object: { hasProperty, isEmpty },
4
- string: { escapeMDX },
5
- } = require("@graphql-markdown/utils");
6
-
7
- const { getCustomDirectiveResolver } = require("./directive");
8
-
9
- const {
10
- DEPRECATED,
11
- MARKDOWN_EOL,
12
- MARKDOWN_EOP,
13
- NO_DESCRIPTION_TEXT,
14
- } = require("./const/strings");
15
-
16
- const printCustomDirectives = (type, options) => {
17
- const constDirectiveMap = getConstDirectiveMap(type, options);
18
-
19
- if (isEmpty(constDirectiveMap)) {
20
- return "";
21
- }
22
-
23
- const content = Object.values(constDirectiveMap)
24
- .map((constDirectiveOption) =>
25
- getCustomDirectiveResolver("descriptor", type, constDirectiveOption, ""),
26
- )
27
- .filter((text) => text.length > 0)
28
- .join(MARKDOWN_EOP);
29
-
30
- return `${MARKDOWN_EOP}${content}`;
31
- };
32
-
33
- const formatDescription = (type, noText = NO_DESCRIPTION_TEXT) => {
34
- const replacement = typeof noText === "string" ? noText : NO_DESCRIPTION_TEXT;
35
- const description =
36
- hasProperty(type, "description") && typeof type.description === "string"
37
- ? escapeMDX(type.description)
38
- : replacement;
39
- return `${MARKDOWN_EOP}${description}`;
40
- };
41
-
42
- const printDeprecation = (type) => {
43
- if (isDeprecated(type) === false) {
44
- return "";
45
- }
46
-
47
- const reason =
48
- typeof type.deprecationReason === "string"
49
- ? type.deprecationReason + MARKDOWN_EOL
50
- : "";
51
-
52
- return `${MARKDOWN_EOP}:::caution ${DEPRECATED.toUpperCase()}${MARKDOWN_EOL}${reason}:::`;
53
- };
54
-
55
- const printDescription = (type, options, noText) => {
56
- const description = formatDescription(type, noText);
57
- const customDirectives = printCustomDirectives(type, options);
58
- const deprecation = printDeprecation(type);
59
- return `${deprecation}${description}${customDirectives}`;
60
- };
61
-
62
- module.exports = {
63
- printCustomDirectives,
64
- printDeprecation,
65
- printDescription,
66
- };
@@ -1,28 +0,0 @@
1
- const OPTION_DEPRECATED = {
2
- DEFAULT: "default",
3
- GROUP: "group",
4
- SKIP: "skip",
5
- };
6
-
7
- const PRINT_TYPE_DEFAULT_OPTIONS = {
8
- parentTypePrefix: true,
9
- printDeprecated: OPTION_DEPRECATED.DEFAULT,
10
- codeSection: true,
11
- relatedTypeSection: true,
12
- typeBadges: true,
13
- };
14
-
15
- const DEFAULT_OPTIONS = {
16
- ...PRINT_TYPE_DEFAULT_OPTIONS,
17
- basePath: "/",
18
- customDirectives: {},
19
- groups: {},
20
- schema: undefined,
21
- skipDocDirective: undefined,
22
- };
23
-
24
- module.exports = {
25
- DEFAULT_OPTIONS,
26
- OPTION_DEPRECATED,
27
- PRINT_TYPE_DEFAULT_OPTIONS,
28
- };
@@ -1,48 +0,0 @@
1
- const ROOT_TYPE_LOCALE = {
2
- DIRECTIVE: { singular: "directive", plural: "directives" },
3
- ENUM: { singular: "enum", plural: "enums" },
4
- INPUT: { singular: "input", plural: "inputs" },
5
- INTERFACE: { singular: "interface", plural: "interfaces" },
6
- MUTATION: { singular: "mutation", plural: "mutations" },
7
- OPERATION: { singular: "operation", plural: "operations" },
8
- QUERY: { singular: "query", plural: "queries" },
9
- SCALAR: { singular: "scalar", plural: "scalars" },
10
- SUBSCRIPTION: { singular: "subscription", plural: "subscriptions" },
11
- TYPE: { singular: "object", plural: "objects" },
12
- UNION: { singular: "union", plural: "unions" },
13
- };
14
-
15
- const HEADER_SECTION_ITEM_LEVEL = "#####";
16
- const HEADER_SECTION_LEVEL = "###";
17
- const HEADER_SECTION_SUB_LEVEL = "####";
18
-
19
- const NO_DESCRIPTION_TEXT = "No description";
20
-
21
- const FRONT_MATTER = "---";
22
- const MARKDOWN_CODE_INDENTATION = " ";
23
- const MARKDOWN_EOL = "\n";
24
- const MARKDOWN_EOP = "\n\n";
25
- const MARKDOWN_EOC = `${MARKDOWN_EOL}\`\`\`${MARKDOWN_EOL}`;
26
- const MARKDOWN_SOC = `${MARKDOWN_EOL}\`\`\`graphql${MARKDOWN_EOL}`;
27
-
28
- const DEPRECATED = "deprecated";
29
-
30
- const HIDE_DEPRECATED = `<><span className="deprecated">Hide deprecated</span></>`;
31
- const SHOW_DEPRECATED = `<><span className="deprecated">Show deprecated</span></>`;
32
-
33
- module.exports = {
34
- DEPRECATED,
35
- FRONT_MATTER,
36
- HEADER_SECTION_ITEM_LEVEL,
37
- HEADER_SECTION_LEVEL,
38
- HEADER_SECTION_SUB_LEVEL,
39
- HIDE_DEPRECATED,
40
- MARKDOWN_CODE_INDENTATION,
41
- MARKDOWN_EOC,
42
- MARKDOWN_EOL,
43
- MARKDOWN_EOP,
44
- MARKDOWN_SOC,
45
- NO_DESCRIPTION_TEXT,
46
- ROOT_TYPE_LOCALE,
47
- SHOW_DEPRECATED,
48
- };
package/src/directive.js DELETED
@@ -1,105 +0,0 @@
1
- const {
2
- graphql: { getConstDirectiveMap },
3
- } = require("@graphql-markdown/utils");
4
- const {
5
- HEADER_SECTION_LEVEL,
6
- HEADER_SECTION_SUB_LEVEL,
7
- MARKDOWN_EOL,
8
- MARKDOWN_EOP,
9
- } = require("./const/strings");
10
- const { printLink } = require("./link");
11
- const { printBadge } = require("./badge");
12
-
13
- function printCustomDirectives(type, options) {
14
- const constDirectiveMap = getConstDirectiveMap(type, options);
15
-
16
- if (
17
- typeof constDirectiveMap !== "object" ||
18
- !Object.keys(constDirectiveMap).length
19
- ) {
20
- return "";
21
- }
22
-
23
- const directives = Object.values(constDirectiveMap)
24
- .map((constDirectiveOption) =>
25
- printCustomDirective(type, constDirectiveOption, options),
26
- )
27
- .filter((value) => typeof value !== "undefined");
28
-
29
- if (directives.length === 0) {
30
- return "";
31
- }
32
-
33
- const content = directives.join(MARKDOWN_EOP);
34
-
35
- return `${HEADER_SECTION_LEVEL} Directives${MARKDOWN_EOP}${content}${MARKDOWN_EOP}`;
36
- }
37
-
38
- function printCustomDirective(type, constDirectiveOption, options) {
39
- const typeNameLink = printLink(constDirectiveOption.type, {
40
- ...options,
41
- withAttributes: false,
42
- });
43
- const description = getCustomDirectiveResolver(
44
- "descriptor",
45
- type,
46
- constDirectiveOption,
47
- );
48
-
49
- if (typeof description === "undefined") {
50
- return undefined;
51
- }
52
-
53
- return `${HEADER_SECTION_SUB_LEVEL} ${typeNameLink}${MARKDOWN_EOL}> ${description}${MARKDOWN_EOL}> `;
54
- }
55
-
56
- function getCustomTags(type, options) {
57
- const constDirectiveMap = getConstDirectiveMap(type, options);
58
-
59
- if (
60
- typeof constDirectiveMap !== "object" ||
61
- !Object.keys(constDirectiveMap).length
62
- ) {
63
- return [];
64
- }
65
-
66
- return Object.values(constDirectiveMap)
67
- .map((constDirectiveOption) =>
68
- getCustomDirectiveResolver("tag", type, constDirectiveOption),
69
- )
70
- .filter((value) => typeof value !== "undefined");
71
- }
72
-
73
- const printCustomTags = (type, options) => {
74
- const badges = getCustomTags(type, options);
75
-
76
- if (badges.length === 0) {
77
- return "";
78
- }
79
-
80
- return badges.map((badge) => printBadge(badge)).join(" ");
81
- };
82
-
83
- function getCustomDirectiveResolver(
84
- resolver,
85
- type,
86
- constDirectiveOption,
87
- fallback = undefined,
88
- ) {
89
- if (
90
- typeof constDirectiveOption === "undefined" ||
91
- typeof constDirectiveOption[resolver] !== "function"
92
- ) {
93
- return fallback;
94
- }
95
-
96
- return constDirectiveOption[resolver](constDirectiveOption.type, type);
97
- }
98
-
99
- module.exports = {
100
- getCustomDirectiveResolver,
101
- getCustomTags,
102
- printCustomDirective,
103
- printCustomDirectives,
104
- printCustomTags,
105
- };
@@ -1,47 +0,0 @@
1
- const {
2
- object: { hasProperty },
3
- graphql: { getTypeName },
4
- } = require("@graphql-markdown/utils");
5
-
6
- const { printMetadataSection } = require("../section");
7
- const { printCodeArguments } = require("../code");
8
-
9
- const printCodeDirectiveLocation = (type) => {
10
- if (
11
- typeof type.locations === "undefined" ||
12
- type.locations == null ||
13
- type.locations.length === 0
14
- ) {
15
- return "";
16
- }
17
-
18
- let code = ` on `;
19
- const separator = `\r\n | `;
20
- if (type.locations.length > 1) {
21
- code += separator;
22
- }
23
- code += type.locations.join(separator).trim();
24
-
25
- return code;
26
- };
27
-
28
- const printDirectiveMetadata = (type, options) => {
29
- if (hasProperty(type, "args") === false) {
30
- return "";
31
- }
32
-
33
- return printMetadataSection(type, type.args, "Arguments", options);
34
- };
35
-
36
- const printCodeDirective = (type) => {
37
- let code = `directive @${getTypeName(type)}`;
38
- code += printCodeArguments(type);
39
- code += printCodeDirectiveLocation(type);
40
-
41
- return code;
42
- };
43
-
44
- module.exports = {
45
- printDirectiveMetadata,
46
- printCodeDirective,
47
- };
@@ -1,47 +0,0 @@
1
- const {
2
- object: { hasProperty },
3
- graphql: { isEnumType, getTypeName, isDeprecated, hasDirective },
4
- } = require("@graphql-markdown/utils");
5
-
6
- const { MARKDOWN_EOL, DEPRECATED } = require("../const/strings");
7
- const { OPTION_DEPRECATED } = require("../const/options");
8
- const { printMetadataSection } = require("../section");
9
-
10
- const printEnumMetadata = (type, options) => {
11
- return printMetadataSection(type, type.getValues(), "Values", options);
12
- };
13
-
14
- const printCodeEnum = (type, options) => {
15
- if (!isEnumType(type)) {
16
- return "";
17
- }
18
-
19
- let code = `enum ${getTypeName(type)} {${MARKDOWN_EOL}`;
20
- code += type
21
- .getValues()
22
- .map((value) => {
23
- const skipDirective =
24
- hasProperty(options, "skipDocDirective") &&
25
- hasDirective(value, options.skipDocDirective) === true;
26
- const skipDeprecated =
27
- hasProperty(options, "printDeprecated") &&
28
- options.printDeprecated === OPTION_DEPRECATED.SKIP &&
29
- isDeprecated(value) === true;
30
- if (skipDirective === true || skipDeprecated === true) {
31
- return "";
32
- }
33
- const v = getTypeName(value);
34
- const d = isDeprecated(value) === true ? ` @${DEPRECATED}` : "";
35
- return ` ${v}${d}`;
36
- })
37
- .filter((value) => value.length > 0)
38
- .join(MARKDOWN_EOL);
39
- code += `${MARKDOWN_EOL}}`;
40
-
41
- return code;
42
- };
43
-
44
- module.exports = {
45
- printCodeEnum,
46
- printEnumMetadata,
47
- };
@@ -1,10 +0,0 @@
1
- module.exports = {
2
- ...require("./directive"),
3
- ...require("./enum"),
4
- ...require("./input"),
5
- ...require("./interface"),
6
- ...require("./object"),
7
- ...require("./operation"),
8
- ...require("./scalar"),
9
- ...require("./union"),
10
- };
@@ -1,10 +0,0 @@
1
- const { printObjectMetadata, printCodeType } = require("./object");
2
-
3
- const printInputMetadata = printObjectMetadata;
4
-
5
- const printCodeInput = (type, options) => printCodeType(type, "input", options);
6
-
7
- module.exports = {
8
- printInputMetadata,
9
- printCodeInput,
10
- };
@@ -1,10 +0,0 @@
1
- const { printObjectMetadata, printCodeType } = require("./object");
2
-
3
- const printInterfaceMetadata = printObjectMetadata;
4
-
5
- const printCodeInterface = (type) => printCodeType(type, "interface");
6
-
7
- module.exports = {
8
- printInterfaceMetadata,
9
- printCodeInterface,
10
- };
@@ -1,56 +0,0 @@
1
- const {
2
- object: { hasMethod },
3
- graphql: { getTypeName, getFields },
4
- } = require("@graphql-markdown/utils");
5
-
6
- const { printSection, printMetadataSection } = require("../section");
7
- const { printCodeField } = require("../code");
8
- const { MARKDOWN_EOL, MARKDOWN_CODE_INDENTATION } = require("../const/strings");
9
-
10
- const printInterfaceMetadata = (type, options) => {
11
- if (hasMethod(type, "getInterfaces") === false) {
12
- return "";
13
- }
14
-
15
- return printSection(type.getInterfaces(), "Interfaces", options);
16
- };
17
-
18
- const printObjectMetadata = (type, options) => {
19
- const interfaceMeta = printInterfaceMetadata(type, options);
20
- const metadata = printMetadataSection(
21
- type,
22
- getFields(type),
23
- "Fields",
24
- options,
25
- );
26
-
27
- return `${metadata}${interfaceMeta}`;
28
- };
29
-
30
- const printCodeType = (type, entity, options) => {
31
- const name = getTypeName(type);
32
- const extendsInterface =
33
- hasMethod(type, "getInterfaces") && type.getInterfaces().length > 0
34
- ? ` implements ${type
35
- .getInterfaces()
36
- .map((field) => getTypeName(field))
37
- .join(", ")}`
38
- : "";
39
- const typeFields = getFields(type)
40
- .map((field) => {
41
- const f = printCodeField(field, options, 1);
42
- return f.length > 0 ? `${MARKDOWN_CODE_INDENTATION}${f}` : "";
43
- })
44
- .filter((field) => field.length > 0)
45
- .join("");
46
-
47
- return `${entity} ${name}${extendsInterface} {${MARKDOWN_EOL}${typeFields}}`;
48
- };
49
-
50
- const printCodeObject = (type, options) => printCodeType(type, "type", options);
51
-
52
- module.exports = {
53
- printObjectMetadata,
54
- printCodeObject,
55
- printCodeType,
56
- };
@@ -1,28 +0,0 @@
1
- const {
2
- graphql: { getTypeName },
3
- } = require("@graphql-markdown/utils");
4
-
5
- const { printSection, printMetadataSection } = require("../section");
6
- const { printCodeField } = require("../code");
7
-
8
- const printOperationType = (type, options) => {
9
- const queryType = getTypeName(type.type).replace(/[![\]]*/g, "");
10
- return printSection([options.schema.getType(queryType)], "Type", {
11
- ...options,
12
- parentTypePrefix: false,
13
- });
14
- };
15
-
16
- const printOperationMetadata = (type, options) => {
17
- const response = printOperationType(type, options);
18
- const metadata = printMetadataSection(type, type.args, "Arguments", options);
19
-
20
- return `${metadata}${response}`;
21
- };
22
-
23
- const printCodeOperation = printCodeField;
24
-
25
- module.exports = {
26
- printOperationMetadata,
27
- printCodeOperation,
28
- };