@graphcommerce/graphql-codegen-markdown-docs 6.0.0-canary.27 → 6.0.0-canary.28

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,7 @@
1
1
  # Change Log
2
2
 
3
+ ## 6.0.0-canary.28
4
+
3
5
  ## 6.0.0-canary.27
4
6
 
5
7
  ## 6.0.0-canary.26
package/dist/index.js CHANGED
@@ -13,20 +13,24 @@ const plugin = (schema, _documents, config) => {
13
13
  }
14
14
  return node.description ? `\n\n${node.description}` : '';
15
15
  };
16
- const res = (0, graphql_1.visit)(astNode, {
16
+ const possibleScalars = ['Boolean', 'String', 'Int', 'Float', 'ID'];
17
+ const content = (0, graphql_1.visit)(astNode, {
17
18
  Document: {
18
- leave: (node) => `<!-- auto generated -->${node.definitions.filter(Boolean).join('\n')}`,
19
+ leave: (node) => `<!-- Automatically generated from Config.graphqls -->${node.definitions
20
+ .filter(Boolean)
21
+ .join('\n')}`,
19
22
  },
20
23
  Name: { leave: (node) => node.value },
21
- NamedType: { leave: (node) => node.name },
24
+ NamedType: {
25
+ leave: (node) => possibleScalars.includes(node.name) ? node.name : `[${node.name}](#${node.name})`,
26
+ },
22
27
  StringValue: { leave: (node) => node.value },
23
28
  ListType: { leave: (node) => `[${node.type}]` },
24
- NonNullType: { leave: (node) => `${node.type}!` },
29
+ NonNullType: {
30
+ leave: (node) => `${node.type}!`,
31
+ },
25
32
  InputValueDefinition: {
26
- leave: (node) => {
27
- const { type } = node;
28
- return `\`${node.name}: ${type}\`${descriptionText(node)}`;
29
- },
33
+ leave: (node) => `\`${node.name}: ${node.type}\`${descriptionText(node)}`,
30
34
  },
31
35
  InputObjectTypeDefinition: {
32
36
  enter: (node) => ({
@@ -34,8 +38,12 @@ const plugin = (schema, _documents, config) => {
34
38
  // Move required fields to the top.
35
39
  fields: [...(node.fields ?? [])].sort((a, b) => a.type.kind === 'NonNullType' && b.type.kind !== 'NonNullType' ? -1 : 1),
36
40
  }),
37
- leave: (node) => `\n## ${node.name}${descriptionText(node)}
38
- ${node.fields?.map((f) => `\n### ${f}`).join('\n')}`,
41
+ leave: (node) => {
42
+ const title = descriptionText(node).trimStart().startsWith('#')
43
+ ? `${descriptionText(node).trimStart()}\n\n### ${node.name}`
44
+ : `### ${node.name}${descriptionText(node)}`;
45
+ return `\n${title}\n${node.fields?.map((f) => `\n#### ${f}`).join('\n')}`;
46
+ },
39
47
  },
40
48
  EnumValueDefinition: {
41
49
  leave: (node) => `${node.name} # ${node.description}`,
@@ -47,9 +55,6 @@ ${node.fields?.map((f) => `\n### ${f}`).join('\n')}`,
47
55
  },
48
56
  },
49
57
  });
50
- return {
51
- // prepend: buildImports(),
52
- content: [res].join('\n'),
53
- };
58
+ return { content };
54
59
  };
55
60
  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": "6.0.0-canary.27",
5
+ "version": "6.0.0-canary.28",
6
6
  "sideEffects": false,
7
7
  "type": "commonjs",
8
8
  "main": "dist/index.js",
@@ -21,9 +21,9 @@
21
21
  }
22
22
  },
23
23
  "devDependencies": {
24
- "@graphcommerce/eslint-config-pwa": "6.0.0-canary.27",
25
- "@graphcommerce/prettier-config-pwa": "6.0.0-canary.27",
26
- "@graphcommerce/typescript-config-pwa": "6.0.0-canary.27"
24
+ "@graphcommerce/eslint-config-pwa": "6.0.0-canary.28",
25
+ "@graphcommerce/prettier-config-pwa": "6.0.0-canary.28",
26
+ "@graphcommerce/typescript-config-pwa": "6.0.0-canary.28"
27
27
  },
28
28
  "dependencies": {
29
29
  "@graphql-codegen/add": "4.0.1",
package/src/index.ts CHANGED
@@ -20,20 +20,27 @@ export const plugin: PluginFunction<MarkdownDocsPluginConfig, Types.ComplexPlugi
20
20
  return node.description ? `\n\n${node.description}` : ''
21
21
  }
22
22
 
23
- const res = visit<string>(astNode, {
23
+ const possibleScalars = ['Boolean', 'String', 'Int', 'Float', 'ID']
24
+
25
+ const content = visit<string>(astNode, {
24
26
  Document: {
25
- leave: (node) => `<!-- auto generated -->${node.definitions.filter(Boolean).join('\n')}`,
27
+ leave: (node) =>
28
+ `<!-- Automatically generated from Config.graphqls -->${node.definitions
29
+ .filter(Boolean)
30
+ .join('\n')}`,
26
31
  },
27
32
  Name: { leave: (node) => node.value },
28
- NamedType: { leave: (node) => node.name }, // String, Boolean, GraphCommerceDebugConfig, etc.
33
+ NamedType: {
34
+ leave: (node) =>
35
+ possibleScalars.includes(node.name) ? node.name : `[${node.name}](#${node.name})`,
36
+ }, // String, Boolean, GraphCommerceDebugConfig, etc.
29
37
  StringValue: { leave: (node) => node.value },
30
38
  ListType: { leave: (node) => `[${node.type}]` },
31
- NonNullType: { leave: (node) => `${node.type}!` },
39
+ NonNullType: {
40
+ leave: (node) => `${node.type}!`,
41
+ },
32
42
  InputValueDefinition: {
33
- leave: (node) => {
34
- const { type } = node
35
- return `\`${node.name}: ${type}\`${descriptionText(node)}`
36
- },
43
+ leave: (node) => `\`${node.name}: ${node.type}\`${descriptionText(node)}`,
37
44
  },
38
45
  InputObjectTypeDefinition: {
39
46
  enter: (node) => ({
@@ -43,8 +50,13 @@ export const plugin: PluginFunction<MarkdownDocsPluginConfig, Types.ComplexPlugi
43
50
  a.type.kind === 'NonNullType' && b.type.kind !== 'NonNullType' ? -1 : 1,
44
51
  ),
45
52
  }),
46
- leave: (node) => `\n## ${node.name}${descriptionText(node)}
47
- ${node.fields?.map((f) => `\n### ${f}`).join('\n')}`,
53
+ leave: (node) => {
54
+ const title = descriptionText(node).trimStart().startsWith('#')
55
+ ? `${descriptionText(node).trimStart()}\n\n### ${node.name}`
56
+ : `### ${node.name}${descriptionText(node)}`
57
+
58
+ return `\n${title}\n${node.fields?.map((f) => `\n#### ${f}`).join('\n')}`
59
+ },
48
60
  },
49
61
  EnumValueDefinition: {
50
62
  leave: (node) => `${node.name} # ${node.description}`,
@@ -57,8 +69,5 @@ ${node.fields?.map((f) => `\n### ${f}`).join('\n')}`,
57
69
  },
58
70
  })
59
71
 
60
- return {
61
- // prepend: buildImports(),
62
- content: [res].join('\n'),
63
- }
72
+ return { content }
64
73
  }