@graphql-markdown/printer-legacy 1.1.6 → 1.1.7

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.1.6",
8
+ "version": "1.1.7",
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.1.3"
25
+ "@graphql-markdown/utils": "^1.1.4"
26
26
  },
27
27
  "directories": {
28
28
  "test": "tests"
package/src/badge.js ADDED
@@ -0,0 +1,63 @@
1
+ const {
2
+ object: { hasProperty },
3
+ graphql: { isNonNullType, isListType, getNamedType },
4
+ } = require("@graphql-markdown/utils");
5
+
6
+ const { getLinkCategory } = require("./link");
7
+ const { getGroup } = require("./group");
8
+
9
+ const getTypeBadges = (type) => {
10
+ const rootType = hasProperty(type, "type") ? type.type : type;
11
+
12
+ const badges = [];
13
+
14
+ if (hasProperty(type, "isDeprecated") && type.isDeprecated) {
15
+ badges.push("deprecated");
16
+ }
17
+
18
+ if (isNonNullType(rootType)) {
19
+ badges.push("non-null");
20
+ }
21
+
22
+ if (isListType(rootType)) {
23
+ badges.push("list");
24
+ }
25
+
26
+ const category = getLinkCategory(getNamedType(rootType));
27
+ if (typeof category !== "undefined") {
28
+ badges.push(category);
29
+ }
30
+
31
+ const group = getGroup(rootType);
32
+ if (typeof group !== "undefined" && group !== "") {
33
+ badges.push(group);
34
+ }
35
+
36
+ return badges;
37
+ };
38
+
39
+ const printBadges = (type, options) => {
40
+ if (!hasProperty(options, "typeBadges") || options.typeBadges !== true) {
41
+ return "";
42
+ }
43
+
44
+ const badges = getTypeBadges(type);
45
+
46
+ if (badges.length === 0) {
47
+ return "";
48
+ }
49
+
50
+ return badges
51
+ .map(
52
+ (badge) =>
53
+ `<Badge class="secondary" text="${
54
+ hasProperty(badge, "singular") ? badge.singular : badge
55
+ }"/>`,
56
+ )
57
+ .join(" ");
58
+ };
59
+
60
+ module.exports = {
61
+ printBadges,
62
+ getTypeBadges,
63
+ };
package/src/code.js ADDED
@@ -0,0 +1,39 @@
1
+ const {
2
+ object: { hasProperty },
3
+ graphql: { getDefaultValue, getTypeName },
4
+ } = require("@graphql-markdown/utils");
5
+
6
+ const { MARKDOWN_EOL } = require("./const/strings");
7
+
8
+ const printCodeField = (type) => {
9
+ let code = `${getTypeName(type)}`;
10
+ code += printCodeArguments(type);
11
+ code += `: ${getTypeName(type.type)}${MARKDOWN_EOL}`;
12
+
13
+ return code;
14
+ };
15
+
16
+ const printCodeArguments = (type) => {
17
+ if (!hasProperty(type, "args") || type.args.length === 0) {
18
+ return "";
19
+ }
20
+
21
+ let code = `(${MARKDOWN_EOL}`;
22
+ code += type.args.reduce((r, v) => {
23
+ const defaultValue = getDefaultValue(v);
24
+ const hasDefaultValue =
25
+ typeof defaultValue !== "undefined" && defaultValue !== null;
26
+ const printedDefault = hasDefaultValue ? ` = ${getDefaultValue(v)}` : "";
27
+ const propType = v.type.toString();
28
+ const propName = v.name.toString();
29
+ return `${r} ${propName}: ${propType}${printedDefault}${MARKDOWN_EOL}`;
30
+ }, "");
31
+ code += `)`;
32
+
33
+ return code;
34
+ };
35
+
36
+ module.exports = {
37
+ printCodeField,
38
+ printCodeArguments,
39
+ };
package/src/common.js ADDED
@@ -0,0 +1,37 @@
1
+ const {
2
+ string: { escapeMDX },
3
+ object: { hasProperty },
4
+ } = require("@graphql-markdown/utils");
5
+
6
+ const { MARKDOWN_EOP, NO_DESCRIPTION_TEXT } = require("./const/strings");
7
+
8
+ const printDeprecation = (type) => {
9
+ if (
10
+ hasProperty(type, "isDeprecated") === false ||
11
+ type.isDeprecated === false
12
+ ) {
13
+ return "";
14
+ }
15
+
16
+ const reason =
17
+ hasProperty(type, "deprecationReason") &&
18
+ typeof type.deprecationReason === "string"
19
+ ? ": " + escapeMDX(type.deprecationReason)
20
+ : "";
21
+ return `<Badge class="warning" text="DEPRECATED${reason}"/>${MARKDOWN_EOP}`;
22
+ };
23
+
24
+ const printDescription = (type, noText = NO_DESCRIPTION_TEXT) => {
25
+ const replacement = typeof noText === "string" ? noText : NO_DESCRIPTION_TEXT;
26
+ const description =
27
+ hasProperty(type, "description") && typeof type.description === "string"
28
+ ? escapeMDX(type.description)
29
+ : replacement;
30
+ const deprecation = printDeprecation(type);
31
+ return `${deprecation}${description}`;
32
+ };
33
+
34
+ module.exports = {
35
+ printDeprecation,
36
+ printDescription,
37
+ };
@@ -18,6 +18,9 @@ const HEADER_SECTION_ITEM_LEVEL = "#####";
18
18
  const NO_DESCRIPTION_TEXT = "No description";
19
19
  const MARKDOWN_EOL = "\n";
20
20
  const MARKDOWN_EOP = "\n\n";
21
+ const MARKDOWN_SOC = `${MARKDOWN_EOL}\`\`\`graphql${MARKDOWN_EOL}`;
22
+ const MARKDOWN_EOC = `${MARKDOWN_EOL}\`\`\`${MARKDOWN_EOL}`;
23
+ const FRONT_MATTER = "---";
21
24
 
22
25
  module.exports = {
23
26
  ROOT_TYPE_LOCALE,
@@ -27,4 +30,7 @@ module.exports = {
27
30
  NO_DESCRIPTION_TEXT,
28
31
  MARKDOWN_EOL,
29
32
  MARKDOWN_EOP,
33
+ MARKDOWN_SOC,
34
+ MARKDOWN_EOC,
35
+ FRONT_MATTER,
30
36
  };
@@ -0,0 +1,45 @@
1
+ const {
2
+ graphql: { getTypeName },
3
+ } = require("@graphql-markdown/utils");
4
+
5
+ const { printSection } = require("../section");
6
+ const { printCodeArguments } = require("../code");
7
+
8
+ const printCodeDirectiveLocation = (type) => {
9
+ if (
10
+ typeof type.locations === "undefined" ||
11
+ type.locations == null ||
12
+ type.locations.length === 0
13
+ ) {
14
+ return "";
15
+ }
16
+
17
+ let code = ` on `;
18
+ const separator = `\r\n | `;
19
+ if (type.locations.length > 1) {
20
+ code += separator;
21
+ }
22
+ code += type.locations.join(separator).trim();
23
+
24
+ return code;
25
+ };
26
+
27
+ const printDirectiveMetadata = (type, options) => {
28
+ return printSection(type.args, "Arguments", {
29
+ ...options,
30
+ parentType: type.name,
31
+ });
32
+ };
33
+
34
+ const printCodeDirective = (type) => {
35
+ let code = `directive @${getTypeName(type)}`;
36
+ code += printCodeArguments(type);
37
+ code += printCodeDirectiveLocation(type);
38
+
39
+ return code;
40
+ };
41
+
42
+ module.exports = {
43
+ printDirectiveMetadata,
44
+ printCodeDirective,
45
+ };
@@ -0,0 +1,34 @@
1
+ const {
2
+ graphql: { isEnumType, getTypeName },
3
+ } = require("@graphql-markdown/utils");
4
+
5
+ const { MARKDOWN_EOL } = require("../const/strings");
6
+
7
+ const { printSection } = require("../section");
8
+
9
+ const printEnumMetadata = (type, options) => {
10
+ return printSection(type.getValues(), "Values", {
11
+ ...options,
12
+ parentType: type.name,
13
+ });
14
+ };
15
+
16
+ const printCodeEnum = (type) => {
17
+ if (!isEnumType(type)) {
18
+ return "";
19
+ }
20
+
21
+ let code = `enum ${getTypeName(type)} {${MARKDOWN_EOL}`;
22
+ code += type
23
+ .getValues()
24
+ .map((v) => ` ${getTypeName(v)}`)
25
+ .join(MARKDOWN_EOL);
26
+ code += `${MARKDOWN_EOL}}`;
27
+
28
+ return code;
29
+ };
30
+
31
+ module.exports = {
32
+ printCodeEnum,
33
+ printEnumMetadata,
34
+ };
@@ -0,0 +1,10 @@
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
+ };
@@ -0,0 +1,10 @@
1
+ const { printObjectMetadata, printCodeType } = require("./object");
2
+
3
+ const printInputMetadata = printObjectMetadata;
4
+
5
+ const printCodeInput = (type) => printCodeType(type, "input");
6
+
7
+ module.exports = {
8
+ printInputMetadata,
9
+ printCodeInput,
10
+ };
@@ -0,0 +1,10 @@
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
+ };
@@ -0,0 +1,43 @@
1
+ const {
2
+ object: { hasMethod },
3
+ graphql: { getTypeName, getFields },
4
+ } = require("@graphql-markdown/utils");
5
+
6
+ const { printSection } = require("../section");
7
+ const { printCodeField } = require("../code");
8
+ const { MARKDOWN_EOL } = require("../const/strings");
9
+
10
+ const printObjectMetadata = (type, options) => {
11
+ let metadata = printSection(getFields(type), "Fields", {
12
+ ...options,
13
+ parentType: type.name,
14
+ });
15
+ if (hasMethod(type, "getInterfaces")) {
16
+ metadata += printSection(type.getInterfaces(), "Interfaces", options);
17
+ }
18
+ return metadata;
19
+ };
20
+
21
+ const printCodeType = (type, entity) => {
22
+ const name = getTypeName(type);
23
+ const extendsInterface =
24
+ hasMethod(type, "getInterfaces") && type.getInterfaces().length > 0
25
+ ? ` implements ${type
26
+ .getInterfaces()
27
+ .map((field) => getTypeName(field))
28
+ .join(", ")}`
29
+ : "";
30
+ const typeFields = getFields(type)
31
+ .map((v) => ` ${printCodeField(v)}`)
32
+ .join("");
33
+
34
+ return `${entity} ${name}${extendsInterface} {${MARKDOWN_EOL}${typeFields}}`;
35
+ };
36
+
37
+ const printCodeObject = (type) => printCodeType(type, "type");
38
+
39
+ module.exports = {
40
+ printObjectMetadata,
41
+ printCodeObject,
42
+ printCodeType,
43
+ };
@@ -0,0 +1,29 @@
1
+ const {
2
+ graphql: { getTypeName },
3
+ } = require("@graphql-markdown/utils");
4
+
5
+ const { printSection } = require("../section");
6
+ const { printCodeField } = require("../code");
7
+
8
+ const printOperationMetadata = (type, options) => {
9
+ let metadata = printSection(type.args, "Arguments", {
10
+ ...options,
11
+ parentType: type.name,
12
+ parentTypePrefix: true,
13
+ });
14
+
15
+ const queryType = getTypeName(type.type).replace(/[![\]]*/g, "");
16
+ metadata += printSection([options.schema.getType(queryType)], "Type", {
17
+ ...options,
18
+ parentTypePrefix: false,
19
+ });
20
+
21
+ return metadata;
22
+ };
23
+
24
+ const printCodeOperation = printCodeField;
25
+
26
+ module.exports = {
27
+ printOperationMetadata,
28
+ printCodeOperation,
29
+ };
@@ -0,0 +1,30 @@
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
+ };
@@ -0,0 +1,31 @@
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 ADDED
@@ -0,0 +1,18 @@
1
+ const {
2
+ string: { toSlug },
3
+ object: { hasProperty },
4
+ graphql: { getNamedType },
5
+ } = require("@graphql-markdown/utils");
6
+
7
+ const getGroup = (type, groups) => {
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, typeName) ? toSlug(groups[typeName]) : "";
14
+ };
15
+
16
+ module.exports = {
17
+ getGroup,
18
+ };