@graphql-markdown/core 1.3.0 → 1.4.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.
@@ -2,7 +2,7 @@
2
2
  "schemaSidebar": [
3
3
  {
4
4
  "type": "autogenerated",
5
- "dirName": "schema"
5
+ "dirName": "."
6
6
  }
7
7
  ]
8
8
  }
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.3.0",
8
+ "version": "1.4.0",
9
9
  "license": "MIT",
10
10
  "main": "src/index.js",
11
11
  "repository": {
@@ -29,11 +29,11 @@
29
29
  "stryker": "stryker run"
30
30
  },
31
31
  "dependencies": {
32
- "@graphql-markdown/utils": "^1.3.0"
32
+ "@graphql-markdown/utils": "^1.4.0"
33
33
  },
34
34
  "peerDependencies": {
35
- "@graphql-markdown/printer-legacy": "^1.2.3",
36
- "@graphql-markdown/diff": "^1.0.9",
35
+ "@graphql-markdown/printer-legacy": "^1.3.0",
36
+ "@graphql-markdown/diff": "^1.0.10",
37
37
  "prettier": "^2.8"
38
38
  },
39
39
  "peerDependenciesMeta": {
package/src/config.js CHANGED
@@ -31,6 +31,7 @@ const DEFAULT_OPTIONS = {
31
31
  deprecated: "default",
32
32
  },
33
33
  skipDocDirective: [],
34
+ customDirective: undefined,
34
35
  };
35
36
 
36
37
  function buildConfig(configFileOpts, cliOpts) {
@@ -45,6 +46,7 @@ function buildConfig(configFileOpts, cliOpts) {
45
46
  }
46
47
 
47
48
  const baseURL = cliOpts.base ?? config.baseURL;
49
+ const skipDocDirective = getSkipDocDirectives(cliOpts, config);
48
50
 
49
51
  return {
50
52
  baseURL,
@@ -61,10 +63,41 @@ function buildConfig(configFileOpts, cliOpts) {
61
63
  docOptions: getDocOptions(cliOpts, config.docOptions),
62
64
  printTypeOptions: gePrintTypeOptions(cliOpts, config.printTypeOptions),
63
65
  printer: config.printer,
64
- skipDocDirective: getSkipDocDirectives(cliOpts, config),
66
+ skipDocDirective,
67
+ customDirective: getCustomDirectives(
68
+ config.customDirective,
69
+ skipDocDirective,
70
+ ),
65
71
  };
66
72
  }
67
73
 
74
+ function getCustomDirectives(customDirectiveOptions, skipDocDirective = []) {
75
+ if (
76
+ typeof customDirectiveOptions === "undefined" ||
77
+ (typeof customDirectiveOptions === "object" &&
78
+ Object.keys(customDirectiveOptions).length == 0)
79
+ ) {
80
+ return undefined;
81
+ }
82
+
83
+ for (const [name, option] of Object.entries(customDirectiveOptions)) {
84
+ if (skipDocDirective.includes(name)) {
85
+ delete customDirectiveOptions[name];
86
+ } else if (
87
+ hasProperty(option, "descriptor") === false ||
88
+ typeof option.descriptor !== "function"
89
+ ) {
90
+ throw new Error(
91
+ `Wrong format for plugin custom directive "${name}", it should be {descriptor: (directiveType, constDirectiveType) => String}`,
92
+ );
93
+ }
94
+ }
95
+
96
+ return Object.keys(customDirectiveOptions).length === 0
97
+ ? undefined
98
+ : customDirectiveOptions;
99
+ }
100
+
68
101
  function getDiffMethod(diff, force) {
69
102
  return force ? "FORCE" : diff;
70
103
  }
@@ -152,6 +185,7 @@ module.exports = {
152
185
  getSkipDocDirectives,
153
186
  getSkipDocDirective,
154
187
  parseGroupByOption,
188
+ getCustomDirectives,
155
189
  DEFAULT_OPTIONS,
156
190
  ASSETS_LOCATION,
157
191
  };
package/src/generator.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const {
2
2
  graphql: { getSchemaMap, loadSchema, getDocumentLoaders },
3
3
  group: { getGroups },
4
+ directive: { getCustomDirectives },
4
5
  } = require("@graphql-markdown/utils");
5
6
  const Renderer = require("./renderer");
6
7
 
@@ -34,15 +35,7 @@ const hasChanges = async (
34
35
  return true;
35
36
  };
36
37
 
37
- const getPrinter = (
38
- schema,
39
- baseURL,
40
- linkRoot,
41
- groups,
42
- printTypeOptions,
43
- printerModule,
44
- skipDocDirective,
45
- ) => {
38
+ const getPrinter = (printerModule, config, options) => {
46
39
  let Printer = undefined;
47
40
 
48
41
  if (typeof printerModule !== "string") {
@@ -59,11 +52,8 @@ const getPrinter = (
59
52
  );
60
53
  }
61
54
 
62
- Printer.init(schema, baseURL, linkRoot, {
63
- groups,
64
- printTypeOptions,
65
- skipDocDirective,
66
- });
55
+ const { schema, baseURL, linkRoot } = config;
56
+ Printer.init(schema, baseURL, linkRoot, { ...options });
67
57
 
68
58
  return Printer;
69
59
  };
@@ -83,6 +73,7 @@ const generateDocFromSchema = async ({
83
73
  printTypeOptions,
84
74
  printer: printerModule,
85
75
  skipDocDirective,
76
+ customDirective,
86
77
  }) => {
87
78
  const start = process.hrtime.bigint();
88
79
 
@@ -95,15 +86,26 @@ const generateDocFromSchema = async ({
95
86
  }
96
87
 
97
88
  const rootTypes = getSchemaMap(schema);
89
+ const customDirectives = getCustomDirectives(rootTypes, customDirective);
98
90
  const groups = new getGroups(rootTypes, groupByDirective);
99
91
  const printer = getPrinter(
100
- schema,
101
- baseURL,
102
- linkRoot,
103
- groups,
104
- printTypeOptions,
92
+ // module mandatory
105
93
  printerModule,
106
- skipDocDirective,
94
+
95
+ // config mandatory
96
+ {
97
+ schema,
98
+ baseURL,
99
+ linkRoot,
100
+ },
101
+
102
+ // options
103
+ {
104
+ groups,
105
+ printTypeOptions,
106
+ skipDocDirective,
107
+ customDirectives,
108
+ },
107
109
  );
108
110
  const renderer = new Renderer(printer, outputDir, baseURL, groups, prettify, {
109
111
  ...docOptions,