@graphql-markdown/printer-legacy 1.8.0 → 1.8.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/README.md +5 -2
- package/dist/example.d.ts +3 -2
- package/dist/example.js +49 -8
- package/dist/printer.js +1 -15
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
# @graphql-markdown/printer-legacy
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@graphql-markdown/printer-legacy)
|
|
4
|
+
[](https://raw.githubusercontent.com/graphql-markdown/graphql-markdown/main/LICENSE)
|
|
5
|
+
[](https://sonarcloud.io/summary/new_code?id=graphql-markdown_printer-legacy)
|
|
6
|
+
[](https://sonarcloud.io/summary/new_code?id=graphql-markdown_printer-legacy)
|
|
7
|
+
[](https://dashboard.stryker-mutator.io/reports/github.com/graphql-markdown/graphql-markdown/main?module=printer-legacy)
|
package/dist/example.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type { Maybe, TypeDirectiveExample } from "@graphql-markdown/types";
|
|
2
|
-
export declare const
|
|
1
|
+
import type { Maybe, PrintTypeOptions, TypeDirectiveExample } from "@graphql-markdown/types";
|
|
2
|
+
export declare const getDirectiveExampleOption: (options: PrintTypeOptions) => Maybe<TypeDirectiveExample>;
|
|
3
|
+
export declare const printExample: (type: unknown, options: PrintTypeOptions) => Maybe<string>;
|
package/dist/example.js
CHANGED
|
@@ -1,19 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.printExample = void 0;
|
|
3
|
+
exports.printExample = exports.getDirectiveExampleOption = void 0;
|
|
4
4
|
const graphql_1 = require("@graphql-markdown/graphql");
|
|
5
|
-
const
|
|
5
|
+
const utils_1 = require("@graphql-markdown/utils");
|
|
6
|
+
const common_1 = require("./common");
|
|
7
|
+
const getDirectiveExampleOption = (options) => {
|
|
8
|
+
let directiveName = "example", argName = "value", parserFunc = undefined;
|
|
9
|
+
if (options.exampleSection && typeof options.exampleSection === "object") {
|
|
10
|
+
if ("directive" in options.exampleSection &&
|
|
11
|
+
options.exampleSection.directive) {
|
|
12
|
+
directiveName = options.exampleSection.directive;
|
|
13
|
+
}
|
|
14
|
+
if ("field" in options.exampleSection && options.exampleSection.field) {
|
|
15
|
+
argName = options.exampleSection.field;
|
|
16
|
+
}
|
|
17
|
+
if ("parser" in options.exampleSection && options.exampleSection.parser) {
|
|
18
|
+
parserFunc = options.exampleSection.parser;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const directive = options.schema && !(0, utils_1.isEmpty)(options.schema)
|
|
22
|
+
? options.schema.getDirective(directiveName)
|
|
23
|
+
: undefined;
|
|
24
|
+
if (!directive) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
directive,
|
|
29
|
+
field: argName,
|
|
30
|
+
parser: parserFunc,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
exports.getDirectiveExampleOption = getDirectiveExampleOption;
|
|
34
|
+
const parseTypeFields = (type, options) => {
|
|
35
|
+
const directiveExample = (0, exports.getDirectiveExampleOption)(options);
|
|
36
|
+
if (!directiveExample) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
6
39
|
const fields = (0, graphql_1.getFields)(type);
|
|
7
40
|
if (fields.length === 0) {
|
|
8
41
|
return undefined;
|
|
9
42
|
}
|
|
10
43
|
let example = {};
|
|
11
|
-
fields
|
|
44
|
+
fields
|
|
45
|
+
.filter((field) => {
|
|
46
|
+
return (0, common_1.hasPrintableDirective)(field, options);
|
|
47
|
+
})
|
|
48
|
+
.forEach((field) => {
|
|
12
49
|
const fieldType = (0, graphql_1.hasDirective)(field, [directiveExample.directive])
|
|
13
50
|
? field
|
|
14
51
|
: field.type;
|
|
15
52
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
16
|
-
const value = parseExampleDirective(fieldType,
|
|
53
|
+
const value = parseExampleDirective(fieldType, options);
|
|
17
54
|
example = {
|
|
18
55
|
...example,
|
|
19
56
|
[field.name]: (0, graphql_1.isListType)((0, graphql_1.getNullableType)(fieldType))
|
|
@@ -44,7 +81,11 @@ type) => {
|
|
|
44
81
|
}
|
|
45
82
|
return value;
|
|
46
83
|
};
|
|
47
|
-
const parseExampleDirective = (type,
|
|
84
|
+
const parseExampleDirective = (type, options) => {
|
|
85
|
+
const directiveExample = (0, exports.getDirectiveExampleOption)(options);
|
|
86
|
+
if (!directiveExample || !(0, common_1.hasPrintableDirective)(type, options)) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
48
89
|
const parser = typeof directiveExample.parser === "function"
|
|
49
90
|
? directiveExample.parser
|
|
50
91
|
: parseExampleValue;
|
|
@@ -59,17 +100,17 @@ const parseExampleDirective = (type, directiveExample) => {
|
|
|
59
100
|
catch (err) {
|
|
60
101
|
if (err instanceof graphql_1.IntrospectionError) {
|
|
61
102
|
return (0, graphql_1.isType)(namedType)
|
|
62
|
-
? parseTypeFields(namedType,
|
|
103
|
+
? parseTypeFields(namedType, options)
|
|
63
104
|
: undefined;
|
|
64
105
|
}
|
|
65
106
|
throw err;
|
|
66
107
|
}
|
|
67
108
|
};
|
|
68
|
-
const printExample = (type,
|
|
109
|
+
const printExample = (type, options) => {
|
|
69
110
|
if (!(0, graphql_1.isType)(type) && !(0, graphql_1.isOperation)(type)) {
|
|
70
111
|
return undefined;
|
|
71
112
|
}
|
|
72
|
-
const example = parseExampleDirective(type,
|
|
113
|
+
const example = parseExampleDirective(type, options);
|
|
73
114
|
if (!example) {
|
|
74
115
|
return undefined;
|
|
75
116
|
}
|
package/dist/printer.js
CHANGED
|
@@ -91,21 +91,7 @@ class Printer {
|
|
|
91
91
|
options.exampleSection === false) {
|
|
92
92
|
return "";
|
|
93
93
|
}
|
|
94
|
-
|
|
95
|
-
if (typeof options.exampleSection === "object") {
|
|
96
|
-
if ("directive" in options.exampleSection &&
|
|
97
|
-
options.exampleSection.directive) {
|
|
98
|
-
directiveName = options.exampleSection.directive;
|
|
99
|
-
}
|
|
100
|
-
if ("field" in options.exampleSection && options.exampleSection.field) {
|
|
101
|
-
argName = options.exampleSection.field;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
const directive = options.schema?.getDirective(directiveName);
|
|
105
|
-
if (!directive) {
|
|
106
|
-
return "";
|
|
107
|
-
}
|
|
108
|
-
const example = (0, example_1.printExample)(type, { directive, field: argName });
|
|
94
|
+
const example = (0, example_1.printExample)(type, options);
|
|
109
95
|
if (!example) {
|
|
110
96
|
return "";
|
|
111
97
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-markdown/printer-legacy",
|
|
3
|
-
"homepage": "https://graphql-markdown.
|
|
3
|
+
"homepage": "https://graphql-markdown.dev",
|
|
4
4
|
"description": "GraphQL-Markdown legacy Docusaurus printer.",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/graphql-markdown/graphql-markdown/issues"
|
|
7
7
|
},
|
|
8
|
-
"version": "1.8.
|
|
8
|
+
"version": "1.8.1",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -55,12 +55,12 @@
|
|
|
55
55
|
"clean": "rm -rf ./dist"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@docusaurus/utils": ">=2.0
|
|
59
|
-
"@graphql-markdown/graphql": "^1.1.
|
|
60
|
-
"@graphql-markdown/utils": "^1.6.
|
|
58
|
+
"@docusaurus/utils": ">=3.2.0",
|
|
59
|
+
"@graphql-markdown/graphql": "^1.1.2",
|
|
60
|
+
"@graphql-markdown/utils": "^1.6.4"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@graphql-markdown/types": "^1.3.
|
|
63
|
+
"@graphql-markdown/types": "^1.3.1"
|
|
64
64
|
},
|
|
65
65
|
"directories": {
|
|
66
66
|
"test": "tests"
|