@graphql-markdown/printer-legacy 1.0.0 → 1.1.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.
- package/package.json +2 -2
- package/src/index.js +66 -36
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.
|
|
8
|
+
"version": "1.1.0",
|
|
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.
|
|
25
|
+
"@graphql-markdown/utils": "1.1.0"
|
|
26
26
|
},
|
|
27
27
|
"directories": {
|
|
28
28
|
"test": "tests"
|
package/src/index.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
const {
|
|
2
|
-
isEnumType,
|
|
3
|
-
isUnionType,
|
|
4
|
-
isObjectType,
|
|
5
|
-
isScalarType,
|
|
6
|
-
isOperation,
|
|
7
|
-
getDefaultValue,
|
|
8
|
-
getTypeName,
|
|
9
|
-
getFields,
|
|
10
|
-
isDirectiveType,
|
|
11
|
-
isParametrizedField,
|
|
12
|
-
isInterfaceType,
|
|
13
|
-
getNamedType,
|
|
14
|
-
isInputType,
|
|
15
|
-
isListType,
|
|
16
|
-
isNonNullType,
|
|
17
|
-
isLeafType,
|
|
18
|
-
getRelationOfReturn,
|
|
19
|
-
getRelationOfField,
|
|
20
|
-
getRelationOfImplementation,
|
|
21
|
-
} = require("@graphql-markdown/utils").graphql;
|
|
22
|
-
|
|
23
1
|
const {
|
|
24
2
|
string: { toSlug, escapeMDX },
|
|
25
3
|
object: { hasProperty, hasMethod },
|
|
26
4
|
url: { pathUrl },
|
|
27
|
-
|
|
5
|
+
graphql: {
|
|
6
|
+
isEnumType,
|
|
7
|
+
isUnionType,
|
|
8
|
+
isObjectType,
|
|
9
|
+
isScalarType,
|
|
10
|
+
isOperation,
|
|
11
|
+
getDefaultValue,
|
|
12
|
+
getTypeName,
|
|
13
|
+
getFields,
|
|
14
|
+
isDirectiveType,
|
|
15
|
+
isParametrizedField,
|
|
16
|
+
isInterfaceType,
|
|
17
|
+
getNamedType,
|
|
18
|
+
isInputType,
|
|
19
|
+
isListType,
|
|
20
|
+
isNonNullType,
|
|
21
|
+
isLeafType,
|
|
22
|
+
getRelationOfReturn,
|
|
23
|
+
getRelationOfField,
|
|
24
|
+
getRelationOfImplementation,
|
|
25
|
+
hasDirective,
|
|
26
|
+
},
|
|
27
|
+
} = require("@graphql-markdown/utils");
|
|
28
28
|
|
|
29
29
|
const {
|
|
30
30
|
ROOT_TYPE_LOCALE,
|
|
@@ -42,9 +42,10 @@ module.exports = class Printer {
|
|
|
42
42
|
schema,
|
|
43
43
|
baseURL,
|
|
44
44
|
linkRoot = "/",
|
|
45
|
-
{ groups, printTypeOptions } = {
|
|
45
|
+
{ groups, printTypeOptions, skipDocDirective } = {
|
|
46
46
|
groups: undefined,
|
|
47
47
|
printTypeOptions: undefined,
|
|
48
|
+
skipDocDirective: undefined,
|
|
48
49
|
},
|
|
49
50
|
) {
|
|
50
51
|
this.schema = schema;
|
|
@@ -54,6 +55,7 @@ module.exports = class Printer {
|
|
|
54
55
|
this.parentTypePrefix = printTypeOptions?.parentTypePrefix ?? true;
|
|
55
56
|
this.relatedTypeSection = printTypeOptions?.relatedTypeSection ?? true;
|
|
56
57
|
this.typeBadges = printTypeOptions?.typeBadges ?? true;
|
|
58
|
+
this.skipDocDirective = skipDocDirective ?? undefined;
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
getRootTypeLocaleFromString(text) {
|
|
@@ -104,6 +106,10 @@ module.exports = class Printer {
|
|
|
104
106
|
url: "#",
|
|
105
107
|
};
|
|
106
108
|
|
|
109
|
+
if (hasDirective(type, this.skipDocDirective)) {
|
|
110
|
+
return fallback;
|
|
111
|
+
}
|
|
112
|
+
|
|
107
113
|
const graphLQLNamedType = getNamedType(type);
|
|
108
114
|
|
|
109
115
|
let category = this.getLinkCategory(graphLQLNamedType);
|
|
@@ -190,7 +196,7 @@ module.exports = class Printer {
|
|
|
190
196
|
}
|
|
191
197
|
|
|
192
198
|
printLinkAttributes(type, text) {
|
|
193
|
-
if (typeof type
|
|
199
|
+
if (typeof type === "undefined") {
|
|
194
200
|
return text ?? "";
|
|
195
201
|
}
|
|
196
202
|
|
|
@@ -376,9 +382,29 @@ module.exports = class Printer {
|
|
|
376
382
|
return code;
|
|
377
383
|
}
|
|
378
384
|
|
|
385
|
+
printCodeDirectiveLocation(type) {
|
|
386
|
+
if (
|
|
387
|
+
typeof type.locations === "undefined" ||
|
|
388
|
+
type.locations == null ||
|
|
389
|
+
type.locations.length === 0
|
|
390
|
+
) {
|
|
391
|
+
return "";
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
let code = ` on `;
|
|
395
|
+
const separator = `\r\n | `;
|
|
396
|
+
if (type.locations.length > 1) {
|
|
397
|
+
code += separator;
|
|
398
|
+
}
|
|
399
|
+
code += type.locations.join(separator).trim();
|
|
400
|
+
|
|
401
|
+
return code;
|
|
402
|
+
}
|
|
403
|
+
|
|
379
404
|
printCodeDirective(type) {
|
|
380
405
|
let code = `directive @${getTypeName(type)}`;
|
|
381
406
|
code += this.printCodeArguments(type);
|
|
407
|
+
code += this.printCodeDirectiveLocation(type);
|
|
382
408
|
|
|
383
409
|
return code;
|
|
384
410
|
}
|
|
@@ -479,6 +505,7 @@ module.exports = class Printer {
|
|
|
479
505
|
|
|
480
506
|
printTypeMetadata(type) {
|
|
481
507
|
let metadata;
|
|
508
|
+
|
|
482
509
|
switch (true) {
|
|
483
510
|
case isScalarType(type):
|
|
484
511
|
return this.printSpecification(type);
|
|
@@ -490,7 +517,7 @@ module.exports = class Printer {
|
|
|
490
517
|
return this.printSection(type.getTypes(), "Possible types");
|
|
491
518
|
case isObjectType(type):
|
|
492
519
|
case isInterfaceType(type):
|
|
493
|
-
case isInputType(type):
|
|
520
|
+
case isInputType(type): {
|
|
494
521
|
metadata = this.printSection(getFields(type), "Fields", {
|
|
495
522
|
parentType: type.name,
|
|
496
523
|
});
|
|
@@ -498,22 +525,25 @@ module.exports = class Printer {
|
|
|
498
525
|
metadata += this.printSection(type.getInterfaces(), "Interfaces");
|
|
499
526
|
}
|
|
500
527
|
return metadata;
|
|
501
|
-
|
|
502
|
-
case
|
|
528
|
+
}
|
|
529
|
+
case isDirectiveType(type): {
|
|
530
|
+
metadata = this.printSection(type.args, "Arguments", {
|
|
531
|
+
parentType: type.name,
|
|
532
|
+
});
|
|
533
|
+
return metadata;
|
|
534
|
+
}
|
|
535
|
+
case isOperation(type): {
|
|
503
536
|
metadata = this.printSection(type.args, "Arguments", {
|
|
504
537
|
parentType: type.name,
|
|
505
538
|
});
|
|
539
|
+
const queryType = getTypeName(type.type).replace(/[![\]]*/g, "");
|
|
540
|
+
metadata += this.printSection([this.schema.getType(queryType)], "Type");
|
|
506
541
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
[this.schema.getType(queryType)],
|
|
511
|
-
"Type",
|
|
512
|
-
);
|
|
513
|
-
}
|
|
542
|
+
return metadata;
|
|
543
|
+
}
|
|
544
|
+
default:
|
|
514
545
|
return metadata;
|
|
515
546
|
}
|
|
516
|
-
return metadata;
|
|
517
547
|
}
|
|
518
548
|
|
|
519
549
|
printRelations(type) {
|