@graphql-markdown/printer-legacy 1.2.0 → 1.2.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 +2 -2
- package/src/code.js +18 -4
- package/src/const/options.js +1 -0
- package/src/graphql/enum.js +21 -4
- package/src/graphql/input.js +1 -1
- package/src/graphql/object.js +7 -3
- package/src/printer.js +12 -12
- package/src/section.js +10 -2
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.2.
|
|
8
|
+
"version": "1.2.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.2.
|
|
25
|
+
"@graphql-markdown/utils": "^1.2.1"
|
|
26
26
|
},
|
|
27
27
|
"directories": {
|
|
28
28
|
"test": "tests"
|
package/src/code.js
CHANGED
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
const {
|
|
2
2
|
object: { hasProperty },
|
|
3
|
-
graphql: { getDefaultValue, getTypeName },
|
|
3
|
+
graphql: { getDefaultValue, getTypeName, isDeprecated, hasDirective },
|
|
4
4
|
} = require("@graphql-markdown/utils");
|
|
5
5
|
|
|
6
|
-
const { MARKDOWN_EOL } = require("./const/strings");
|
|
6
|
+
const { MARKDOWN_EOL, DEPRECATED } = require("./const/strings");
|
|
7
|
+
const { OPTION_DEPRECATED } = require("./const/options");
|
|
8
|
+
|
|
9
|
+
const printCodeField = (type, options = {}) => {
|
|
10
|
+
const skipDirective =
|
|
11
|
+
hasProperty(options, "skipDocDirective") &&
|
|
12
|
+
hasDirective(type, options.skipDocDirective) === true;
|
|
13
|
+
const skipDeprecated =
|
|
14
|
+
hasProperty(options, "printDeprecated") &&
|
|
15
|
+
options.printDeprecated === OPTION_DEPRECATED.SKIP &&
|
|
16
|
+
isDeprecated(type) === true;
|
|
17
|
+
if (skipDirective === true || skipDeprecated === true) {
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
7
20
|
|
|
8
|
-
const printCodeField = (type) => {
|
|
9
21
|
let code = `${getTypeName(type)}`;
|
|
10
22
|
code += printCodeArguments(type);
|
|
11
|
-
code += `: ${getTypeName(type.type)}
|
|
23
|
+
code += `: ${getTypeName(type.type)}`;
|
|
24
|
+
code += isDeprecated(type) ? ` @${DEPRECATED}` : "";
|
|
25
|
+
code += MARKDOWN_EOL;
|
|
12
26
|
|
|
13
27
|
return code;
|
|
14
28
|
};
|
package/src/const/options.js
CHANGED
package/src/graphql/enum.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
const {
|
|
2
|
-
|
|
2
|
+
object: { hasProperty },
|
|
3
|
+
graphql: { isEnumType, getTypeName, isDeprecated, hasDirective },
|
|
3
4
|
} = require("@graphql-markdown/utils");
|
|
4
5
|
|
|
5
|
-
const { MARKDOWN_EOL } = require("../const/strings");
|
|
6
|
+
const { MARKDOWN_EOL, DEPRECATED } = require("../const/strings");
|
|
7
|
+
const { OPTION_DEPRECATED } = require("../const/options");
|
|
6
8
|
const { printMetadataSection } = require("../section");
|
|
7
9
|
|
|
8
10
|
const printEnumMetadata = (type, options) => {
|
|
9
11
|
return printMetadataSection(type, type.getValues(), "Values", options);
|
|
10
12
|
};
|
|
11
13
|
|
|
12
|
-
const printCodeEnum = (type) => {
|
|
14
|
+
const printCodeEnum = (type, options) => {
|
|
13
15
|
if (!isEnumType(type)) {
|
|
14
16
|
return "";
|
|
15
17
|
}
|
|
@@ -17,7 +19,22 @@ const printCodeEnum = (type) => {
|
|
|
17
19
|
let code = `enum ${getTypeName(type)} {${MARKDOWN_EOL}`;
|
|
18
20
|
code += type
|
|
19
21
|
.getValues()
|
|
20
|
-
.map((
|
|
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)
|
|
21
38
|
.join(MARKDOWN_EOL);
|
|
22
39
|
code += `${MARKDOWN_EOL}}`;
|
|
23
40
|
|
package/src/graphql/input.js
CHANGED
|
@@ -2,7 +2,7 @@ const { printObjectMetadata, printCodeType } = require("./object");
|
|
|
2
2
|
|
|
3
3
|
const printInputMetadata = printObjectMetadata;
|
|
4
4
|
|
|
5
|
-
const printCodeInput = (type) => printCodeType(type, "input");
|
|
5
|
+
const printCodeInput = (type, options) => printCodeType(type, "input", options);
|
|
6
6
|
|
|
7
7
|
module.exports = {
|
|
8
8
|
printInputMetadata,
|
package/src/graphql/object.js
CHANGED
|
@@ -27,7 +27,7 @@ const printObjectMetadata = (type, options) => {
|
|
|
27
27
|
return `${metadata}${interfaceMeta}`;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
const printCodeType = (type, entity) => {
|
|
30
|
+
const printCodeType = (type, entity, options) => {
|
|
31
31
|
const name = getTypeName(type);
|
|
32
32
|
const extendsInterface =
|
|
33
33
|
hasMethod(type, "getInterfaces") && type.getInterfaces().length > 0
|
|
@@ -37,13 +37,17 @@ const printCodeType = (type, entity) => {
|
|
|
37
37
|
.join(", ")}`
|
|
38
38
|
: "";
|
|
39
39
|
const typeFields = getFields(type)
|
|
40
|
-
.map((
|
|
40
|
+
.map((field) => {
|
|
41
|
+
const f = printCodeField(field, options);
|
|
42
|
+
return f.length > 0 ? ` ${f}` : "";
|
|
43
|
+
})
|
|
44
|
+
.filter((field) => field.length > 0)
|
|
41
45
|
.join("");
|
|
42
46
|
|
|
43
47
|
return `${entity} ${name}${extendsInterface} {${MARKDOWN_EOL}${typeFields}}`;
|
|
44
48
|
};
|
|
45
49
|
|
|
46
|
-
const printCodeObject = (type) => printCodeType(type, "type");
|
|
50
|
+
const printCodeObject = (type, options) => printCodeType(type, "type", options);
|
|
47
51
|
|
|
48
52
|
module.exports = {
|
|
49
53
|
printObjectMetadata,
|
package/src/printer.js
CHANGED
|
@@ -103,33 +103,33 @@ class Printer {
|
|
|
103
103
|
|
|
104
104
|
static printDescription = printDescription;
|
|
105
105
|
|
|
106
|
-
static printCode = (type) => {
|
|
106
|
+
static printCode = (type, options) => {
|
|
107
107
|
let code = "";
|
|
108
108
|
|
|
109
109
|
switch (true) {
|
|
110
110
|
case isOperation(type):
|
|
111
|
-
code += printCodeOperation(type);
|
|
111
|
+
code += printCodeOperation(type, options);
|
|
112
112
|
break;
|
|
113
113
|
case isEnumType(type):
|
|
114
|
-
code += printCodeEnum(type);
|
|
114
|
+
code += printCodeEnum(type, options);
|
|
115
115
|
break;
|
|
116
|
-
case isUnionType(type):
|
|
117
|
-
code += printCodeUnion(type);
|
|
116
|
+
case isUnionType(type, options):
|
|
117
|
+
code += printCodeUnion(type, options);
|
|
118
118
|
break;
|
|
119
|
-
case isInterfaceType(type):
|
|
120
|
-
code += printCodeInterface(type);
|
|
119
|
+
case isInterfaceType(type, options):
|
|
120
|
+
code += printCodeInterface(type, options);
|
|
121
121
|
break;
|
|
122
122
|
case isObjectType(type):
|
|
123
|
-
code += printCodeObject(type);
|
|
123
|
+
code += printCodeObject(type, options);
|
|
124
124
|
break;
|
|
125
125
|
case isInputType(type):
|
|
126
|
-
code += printCodeInput(type);
|
|
126
|
+
code += printCodeInput(type, options);
|
|
127
127
|
break;
|
|
128
128
|
case isScalarType(type):
|
|
129
|
-
code += printCodeScalar(type);
|
|
129
|
+
code += printCodeScalar(type, options);
|
|
130
130
|
break;
|
|
131
131
|
case isDirectiveType(type):
|
|
132
|
-
code += printCodeDirective(type);
|
|
132
|
+
code += printCodeDirective(type, options);
|
|
133
133
|
break;
|
|
134
134
|
default:
|
|
135
135
|
code += `"${getTypeName(type)}" not supported`;
|
|
@@ -192,7 +192,7 @@ class Printer {
|
|
|
192
192
|
header: options,
|
|
193
193
|
});
|
|
194
194
|
const description = Printer.printDescription(type);
|
|
195
|
-
const code = Printer.printCode(type);
|
|
195
|
+
const code = Printer.printCode(type, printTypeOptions);
|
|
196
196
|
const metadata = Printer.printTypeMetadata(type, printTypeOptions);
|
|
197
197
|
const relations = Printer.printRelations(type, printTypeOptions);
|
|
198
198
|
|
package/src/section.js
CHANGED
|
@@ -134,11 +134,19 @@ const printSectionItem = (type, options) => {
|
|
|
134
134
|
? options.level
|
|
135
135
|
: HEADER_SECTION_SUB_LEVEL;
|
|
136
136
|
|
|
137
|
+
const skipDirective =
|
|
138
|
+
hasProperty(options, "skipDocDirective") &&
|
|
139
|
+
hasDirective(type, options.skipDocDirective) === true;
|
|
140
|
+
const skipDeprecated =
|
|
141
|
+
hasProperty(options, "printDeprecated") &&
|
|
142
|
+
options.printDeprecated === OPTION_DEPRECATED.SKIP &&
|
|
143
|
+
isDeprecated(type) === true;
|
|
144
|
+
|
|
137
145
|
if (
|
|
138
146
|
typeof type === "undefined" ||
|
|
139
147
|
type === null ||
|
|
140
|
-
|
|
141
|
-
|
|
148
|
+
skipDirective === true ||
|
|
149
|
+
skipDeprecated === true
|
|
142
150
|
) {
|
|
143
151
|
return "";
|
|
144
152
|
}
|