@graphcommerce/graphql-codegen-markdown-docs 7.1.0-canary.8 → 8.0.0-canary.40
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/CHANGELOG.md +68 -0
- package/dist/index.js +39 -17
- package/package.json +6 -8
- package/src/index.ts +38 -17
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,73 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 8.0.0-canary.40
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- [#2077](https://github.com/graphcommerce-org/graphcommerce/pull/2077) [`2e46389ed`](https://github.com/graphcommerce-org/graphcommerce/commit/2e46389edcd506c490cd7273be384e5c42df4a9e) - Render framework/config.md more nicely, so that we follow a more typescript-esque style, inline enums. ([@bramvanderholst](https://github.com/bramvanderholst))
|
8
|
+
|
9
|
+
## 7.1.0-canary.39
|
10
|
+
|
11
|
+
## 7.1.0-canary.38
|
12
|
+
|
13
|
+
## 7.1.0-canary.37
|
14
|
+
|
15
|
+
## 7.1.0-canary.36
|
16
|
+
|
17
|
+
## 7.1.0-canary.35
|
18
|
+
|
19
|
+
## 7.1.0-canary.34
|
20
|
+
|
21
|
+
## 7.1.0-canary.33
|
22
|
+
|
23
|
+
## 7.1.0-canary.32
|
24
|
+
|
25
|
+
## 7.1.0-canary.31
|
26
|
+
|
27
|
+
## 7.1.0-canary.30
|
28
|
+
|
29
|
+
## 7.1.0-canary.29
|
30
|
+
|
31
|
+
## 7.1.0-canary.28
|
32
|
+
|
33
|
+
## 7.1.0-canary.27
|
34
|
+
|
35
|
+
## 7.1.0-canary.26
|
36
|
+
|
37
|
+
## 7.1.0-canary.25
|
38
|
+
|
39
|
+
## 7.1.0-canary.24
|
40
|
+
|
41
|
+
## 7.1.0-canary.23
|
42
|
+
|
43
|
+
## 7.1.0-canary.22
|
44
|
+
|
45
|
+
## 7.1.0-canary.21
|
46
|
+
|
47
|
+
## 7.1.0-canary.20
|
48
|
+
|
49
|
+
## 7.1.0-canary.19
|
50
|
+
|
51
|
+
## 7.1.0-canary.18
|
52
|
+
|
53
|
+
## 7.1.0-canary.17
|
54
|
+
|
55
|
+
## 7.1.0-canary.16
|
56
|
+
|
57
|
+
## 7.1.0-canary.15
|
58
|
+
|
59
|
+
## 7.1.0-canary.14
|
60
|
+
|
61
|
+
## 7.1.0-canary.13
|
62
|
+
|
63
|
+
## 7.1.0-canary.12
|
64
|
+
|
65
|
+
## 7.1.0-canary.11
|
66
|
+
|
67
|
+
## 7.1.0-canary.10
|
68
|
+
|
69
|
+
## 7.1.0-canary.9
|
70
|
+
|
3
71
|
## 7.1.0-canary.8
|
4
72
|
|
5
73
|
## 7.0.2-canary.7
|
package/dist/index.js
CHANGED
@@ -17,8 +17,14 @@ config) => {
|
|
17
17
|
}
|
18
18
|
return node.description ? `\n\n${node.description}` : '';
|
19
19
|
};
|
20
|
-
const possibleScalars =
|
21
|
-
|
20
|
+
const possibleScalars = {
|
21
|
+
Boolean: 'boolean',
|
22
|
+
String: 'string',
|
23
|
+
Int: 'number',
|
24
|
+
Float: 'number',
|
25
|
+
ID: 'string',
|
26
|
+
};
|
27
|
+
let content = (0, graphql_1.visit)(astNode, {
|
22
28
|
Document: {
|
23
29
|
leave: (node) => `<!-- Automatically generated from Config.graphqls -->${node.definitions
|
24
30
|
.filter(Boolean)
|
@@ -26,46 +32,62 @@ config) => {
|
|
26
32
|
},
|
27
33
|
Name: { leave: (node) => node.value },
|
28
34
|
NamedType: {
|
29
|
-
leave: (node) => possibleScalars
|
35
|
+
leave: (node) => possibleScalars[node.name] ?? `[${node.name}](#${node.name})`,
|
30
36
|
},
|
31
37
|
StringValue: { leave: (node) => node.value },
|
32
|
-
BooleanValue: {
|
33
|
-
|
38
|
+
BooleanValue: {
|
39
|
+
leave: (node) => (node.value ? 'true' : 'false'),
|
40
|
+
},
|
41
|
+
EnumValue: { leave: (node) => `'${node.value}'` },
|
34
42
|
IntValue: { leave: (node) => node.value },
|
43
|
+
ObjectValue: {
|
44
|
+
leave: (node) => {
|
45
|
+
const fields = node.fields.join(', ') ?? '';
|
46
|
+
return `{ ${fields} }`;
|
47
|
+
},
|
48
|
+
},
|
35
49
|
FloatValue: { leave: (node) => node.value },
|
36
|
-
ListType: {
|
50
|
+
ListType: {
|
51
|
+
leave: (node) => `${node.type.replace(' (required)', '')}[]`,
|
52
|
+
},
|
53
|
+
ObjectField: { leave: (node) => `${node.name}: ${node.value}` },
|
37
54
|
NonNullType: {
|
38
|
-
leave: (node) => `${node.type}
|
55
|
+
leave: (node) => `${node.type} (required)`,
|
39
56
|
},
|
40
57
|
InputValueDefinition: {
|
41
58
|
leave: (node) => {
|
42
|
-
const defaultValue = node.defaultValue ? `
|
43
|
-
return
|
59
|
+
const defaultValue = node.defaultValue ? ` = ${node.defaultValue}` : '';
|
60
|
+
return `${node.name}: ${node.type}${defaultValue}${descriptionText(node)}`;
|
44
61
|
},
|
45
62
|
},
|
46
63
|
InputObjectTypeDefinition: {
|
47
64
|
enter: (node) => ({
|
48
65
|
...node,
|
49
66
|
// Move required fields to the top.
|
50
|
-
fields: [...(node.fields ?? [])].sort((a, b) =>
|
67
|
+
fields: [...(node.fields ?? [])].sort((a, b) =>
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
69
|
+
a.type.kind === 'NonNullType' && b.type.kind !== 'NonNullType' ? -1 : 1),
|
51
70
|
}),
|
52
71
|
leave: (node) => {
|
53
|
-
const
|
54
|
-
|
55
|
-
|
72
|
+
const text = descriptionText(node);
|
73
|
+
const title = text.trimStart().startsWith('#')
|
74
|
+
? `${text.trimStart()}\n\n### ${node.name}`
|
75
|
+
: `### ${node.name}${text}`;
|
56
76
|
return `\n${title}\n${node.fields?.map((f) => `\n#### ${f}`).join('\n')}`;
|
57
77
|
},
|
58
78
|
},
|
59
|
-
EnumValueDefinition: {
|
60
|
-
leave: (node) => `${node.name} # ${node.description}`,
|
61
|
-
},
|
79
|
+
EnumValueDefinition: { leave: (node) => node.name },
|
62
80
|
EnumTypeDefinition: {
|
63
81
|
leave: (node) => {
|
64
|
-
|
82
|
+
if (node.values)
|
83
|
+
enumStings.set(node.name, node.values.map((v) => `'${v.trim()}'`).join(' | '));
|
65
84
|
return '';
|
66
85
|
},
|
67
86
|
},
|
68
87
|
});
|
88
|
+
enumStings.forEach((value, key) => {
|
89
|
+
content = content.replaceAll(`[${key}](#${key})`, value);
|
90
|
+
});
|
69
91
|
return { content };
|
70
92
|
};
|
71
93
|
exports.plugin = plugin;
|
package/package.json
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
"name": "@graphcommerce/graphql-codegen-markdown-docs",
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
5
|
-
"version": "
|
5
|
+
"version": "8.0.0-canary.40",
|
6
6
|
"sideEffects": false,
|
7
7
|
"type": "commonjs",
|
8
8
|
"main": "dist/index.js",
|
@@ -20,20 +20,18 @@
|
|
20
20
|
"project": "./tsconfig.json"
|
21
21
|
}
|
22
22
|
},
|
23
|
-
"devDependencies": {
|
24
|
-
"@graphcommerce/eslint-config-pwa": "7.1.0-canary.8",
|
25
|
-
"@graphcommerce/prettier-config-pwa": "7.1.0-canary.8",
|
26
|
-
"@graphcommerce/typescript-config-pwa": "7.1.0-canary.8"
|
27
|
-
},
|
28
23
|
"dependencies": {
|
29
24
|
"@graphql-codegen/add": "5.0.0",
|
30
25
|
"@graphql-codegen/plugin-helpers": "5.0.1",
|
31
26
|
"@graphql-codegen/visitor-plugin-common": "4.0.1",
|
32
|
-
"@graphql-tools/utils": "^10.0.
|
33
|
-
"@types/parse-filepath": "^1.0.
|
27
|
+
"@graphql-tools/utils": "^10.0.8",
|
28
|
+
"@types/parse-filepath": "^1.0.2",
|
34
29
|
"parse-filepath": "^1.0.2"
|
35
30
|
},
|
36
31
|
"peerDependencies": {
|
32
|
+
"@graphcommerce/eslint-config-pwa": "8.0.0-canary.40",
|
33
|
+
"@graphcommerce/prettier-config-pwa": "8.0.0-canary.40",
|
34
|
+
"@graphcommerce/typescript-config-pwa": "8.0.0-canary.40",
|
37
35
|
"graphql": "^16.7.1"
|
38
36
|
}
|
39
37
|
}
|
package/src/index.ts
CHANGED
@@ -25,9 +25,15 @@ export const plugin: PluginFunction<MarkdownDocsPluginConfig, Types.ComplexPlugi
|
|
25
25
|
return node.description ? `\n\n${node.description}` : ''
|
26
26
|
}
|
27
27
|
|
28
|
-
const possibleScalars
|
28
|
+
const possibleScalars: Record<string, string> = {
|
29
|
+
Boolean: 'boolean',
|
30
|
+
String: 'string',
|
31
|
+
Int: 'number',
|
32
|
+
Float: 'number',
|
33
|
+
ID: 'string',
|
34
|
+
}
|
29
35
|
|
30
|
-
|
36
|
+
let content = visit<string>(astNode, {
|
31
37
|
Document: {
|
32
38
|
leave: (node) =>
|
33
39
|
`<!-- Automatically generated from Config.graphqls -->${node.definitions
|
@@ -36,22 +42,32 @@ export const plugin: PluginFunction<MarkdownDocsPluginConfig, Types.ComplexPlugi
|
|
36
42
|
},
|
37
43
|
Name: { leave: (node) => node.value },
|
38
44
|
NamedType: {
|
39
|
-
leave: (node) =>
|
40
|
-
possibleScalars.includes(node.name) ? node.name : `[${node.name}](#${node.name})`,
|
45
|
+
leave: (node) => possibleScalars[node.name] ?? `[${node.name}](#${node.name})`,
|
41
46
|
}, // String, Boolean, GraphCommerceDebugConfig, etc.
|
42
47
|
StringValue: { leave: (node) => node.value },
|
43
|
-
BooleanValue: {
|
44
|
-
|
48
|
+
BooleanValue: {
|
49
|
+
leave: (node) => (node.value ? 'true' : 'false'),
|
50
|
+
},
|
51
|
+
EnumValue: { leave: (node) => `'${node.value}'` },
|
45
52
|
IntValue: { leave: (node) => node.value },
|
53
|
+
ObjectValue: {
|
54
|
+
leave: (node) => {
|
55
|
+
const fields = node.fields.join(', ') ?? ''
|
56
|
+
return `{ ${fields} }`
|
57
|
+
},
|
58
|
+
},
|
46
59
|
FloatValue: { leave: (node) => node.value },
|
47
|
-
ListType: {
|
60
|
+
ListType: {
|
61
|
+
leave: (node) => `${node.type.replace(' (required)', '')}[]`,
|
62
|
+
},
|
63
|
+
ObjectField: { leave: (node) => `${node.name}: ${node.value}` },
|
48
64
|
NonNullType: {
|
49
|
-
leave: (node) => `${node.type}
|
65
|
+
leave: (node) => `${node.type} (required)`,
|
50
66
|
},
|
51
67
|
InputValueDefinition: {
|
52
68
|
leave: (node) => {
|
53
|
-
const defaultValue = node.defaultValue ? `
|
54
|
-
return
|
69
|
+
const defaultValue = node.defaultValue ? ` = ${node.defaultValue}` : ''
|
70
|
+
return `${node.name}: ${node.type}${defaultValue}${descriptionText(node)}`
|
55
71
|
},
|
56
72
|
},
|
57
73
|
InputObjectTypeDefinition: {
|
@@ -59,27 +75,32 @@ export const plugin: PluginFunction<MarkdownDocsPluginConfig, Types.ComplexPlugi
|
|
59
75
|
...node,
|
60
76
|
// Move required fields to the top.
|
61
77
|
fields: [...(node.fields ?? [])].sort((a, b) =>
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
62
79
|
a.type.kind === 'NonNullType' && b.type.kind !== 'NonNullType' ? -1 : 1,
|
63
80
|
),
|
64
81
|
}),
|
65
82
|
leave: (node) => {
|
66
|
-
const
|
67
|
-
|
68
|
-
|
83
|
+
const text = descriptionText(node)
|
84
|
+
const title = text.trimStart().startsWith('#')
|
85
|
+
? `${text.trimStart()}\n\n### ${node.name}`
|
86
|
+
: `### ${node.name}${text}`
|
69
87
|
|
70
88
|
return `\n${title}\n${node.fields?.map((f) => `\n#### ${f}`).join('\n')}`
|
71
89
|
},
|
72
90
|
},
|
73
|
-
EnumValueDefinition: {
|
74
|
-
leave: (node) => `${node.name} # ${node.description}`,
|
75
|
-
},
|
91
|
+
EnumValueDefinition: { leave: (node) => node.name },
|
76
92
|
EnumTypeDefinition: {
|
77
93
|
leave: (node) => {
|
78
|
-
|
94
|
+
if (node.values)
|
95
|
+
enumStings.set(node.name, node.values.map((v) => `'${v.trim()}'`).join(' | '))
|
79
96
|
return ''
|
80
97
|
},
|
81
98
|
},
|
82
99
|
})
|
83
100
|
|
101
|
+
enumStings.forEach((value, key) => {
|
102
|
+
content = content.replaceAll(`[${key}](#${key})`, value)
|
103
|
+
})
|
104
|
+
|
84
105
|
return { content }
|
85
106
|
}
|