@graphcommerce/graphql-codegen-markdown-docs 7.1.0-canary.38 → 7.1.0-canary.41

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## 7.1.0-canary.41
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
+
3
9
  ## 7.1.0-canary.38
4
10
 
5
11
  ## 7.1.0-canary.37
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 = ['Boolean', 'String', 'Int', 'Float', 'ID'];
21
- const content = (0, graphql_1.visit)(astNode, {
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.includes(node.name) ? node.name : `[${node.name}](#${node.name})`,
35
+ leave: (node) => possibleScalars[node.name] ?? `[${node.name}](#${node.name})`,
30
36
  },
31
37
  StringValue: { leave: (node) => node.value },
32
- BooleanValue: { leave: (node) => node.value },
33
- EnumValue: { leave: (node) => node.value },
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: { leave: (node) => `[${node.type}]` },
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 ? ` (default: ${node.defaultValue})` : '';
43
- return `\`${node.name}: ${node.type}${defaultValue}\`${descriptionText(node)}`;
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) => a.type.kind === 'NonNullType' && b.type.kind !== 'NonNullType' ? -1 : 1),
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 title = descriptionText(node).trimStart().startsWith('#')
54
- ? `${descriptionText(node).trimStart()}\n\n### ${node.name}`
55
- : `### ${node.name}${descriptionText(node)}`;
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
- enumStings.set(node.name, node.values?.join('\n') || '');
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": "7.1.0-canary.38",
5
+ "version": "7.1.0-canary.41",
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.38",
25
- "@graphcommerce/prettier-config-pwa": "7.1.0-canary.38",
26
- "@graphcommerce/typescript-config-pwa": "7.1.0-canary.38"
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.1",
33
- "@types/parse-filepath": "^1.0.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": "7.1.0-canary.41",
33
+ "@graphcommerce/prettier-config-pwa": "7.1.0-canary.41",
34
+ "@graphcommerce/typescript-config-pwa": "7.1.0-canary.41",
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 = ['Boolean', 'String', 'Int', 'Float', 'ID']
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
- const content = visit<string>(astNode, {
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: { leave: (node) => node.value },
44
- EnumValue: { leave: (node) => node.value },
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: { leave: (node) => `[${node.type}]` },
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 ? ` (default: ${node.defaultValue})` : ''
54
- return `\`${node.name}: ${node.type}${defaultValue}\`${descriptionText(node)}`
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 title = descriptionText(node).trimStart().startsWith('#')
67
- ? `${descriptionText(node).trimStart()}\n\n### ${node.name}`
68
- : `### ${node.name}${descriptionText(node)}`
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
- enumStings.set(node.name, node.values?.join('\n') || '')
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
  }