@graphql-markdown/core 1.10.4 → 1.12.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.
package/dist/config.d.ts CHANGED
@@ -1,4 +1,9 @@
1
- import type { CliOptions, ConfigDocOptions, ConfigOptions, ConfigPrintTypeOptions, CustomDirective, DeprecatedCliOptions, DeprecatedConfigDocOptions, DirectiveName, GroupByDirectiveOptions, Maybe, Options, TypeDiffMethod } from "@graphql-markdown/types";
1
+ import type { CliOptions, ConfigDocOptions, ConfigOptions, ConfigPrintTypeOptions, CustomDirective, DeprecatedCliOptions, DeprecatedConfigDocOptions, DeprecatedConfigPrintTypeOptions, DirectiveName, GroupByDirectiveOptions, Maybe, Options, TypeDiffMethod, TypeHierarchyObjectType, TypeHierarchyType, TypeHierarchyValueType } from "@graphql-markdown/types";
2
+ export declare enum TypeHierarchy {
3
+ API = "api",
4
+ ENTITY = "entity",
5
+ FLAT = "flat"
6
+ }
2
7
  export declare enum DiffMethod {
3
8
  NONE = "NONE",
4
9
  FORCE = "FORCE"
@@ -11,7 +16,11 @@ export declare enum DeprecatedOption {
11
16
  export declare const DOCS_URL: "https://graphql-markdown.dev/docs";
12
17
  export declare const PACKAGE_NAME: "@graphql-markdown/docusaurus";
13
18
  export declare const ASSET_HOMEPAGE_LOCATION: string;
14
- export declare const DEFAULT_OPTIONS: Readonly<Pick<ConfigOptions, "customDirective" | "groupByDirective" | "loaders"> & Required<Omit<ConfigOptions, "customDirective" | "groupByDirective" | "loaders">>>;
19
+ export declare const DEFAULT_OPTIONS: Readonly<Pick<ConfigOptions, "customDirective" | "groupByDirective" | "loaders"> & Required<Omit<ConfigOptions, "customDirective" | "groupByDirective" | "loaders" | "printTypeOptions">>> & {
20
+ printTypeOptions: Required<Omit<ConfigPrintTypeOptions, "hierarchy">> & {
21
+ hierarchy: Required<Pick<TypeHierarchyObjectType, TypeHierarchy.API>>;
22
+ };
23
+ };
15
24
  export declare const getDocDirective: (name: Maybe<DirectiveName>) => DirectiveName;
16
25
  export declare const getOnlyDocDirectives: (cliOpts: Maybe<CliOptions>, configFileOpts: Maybe<Pick<ConfigOptions, "onlyDocDirective">>) => DirectiveName[];
17
26
  export declare const getSkipDocDirectives: (cliOpts: Maybe<CliOptions>, configFileOpts: Maybe<Pick<ConfigOptions, "printTypeOptions" | "skipDocDirective">>) => DirectiveName[];
@@ -27,6 +36,10 @@ export declare const parseDeprecatedDocOptions: (cliOpts: Maybe<DeprecatedCliOpt
27
36
  hide_table_of_contents: boolean;
28
37
  }>;
29
38
  export declare const getDocOptions: (cliOpts?: Maybe<CliOptions & DeprecatedCliOptions>, configOptions?: Maybe<ConfigDocOptions & DeprecatedConfigDocOptions>) => Required<ConfigDocOptions>;
30
- export declare const getPrintTypeOptions: (cliOpts: Maybe<CliOptions>, configOptions: Maybe<ConfigPrintTypeOptions>) => Required<ConfigPrintTypeOptions>;
39
+ export declare const getTypeHierarchyOption: (cliOption?: Maybe<TypeHierarchyValueType>, configOption?: Maybe<TypeHierarchyType>) => Maybe<TypeHierarchyObjectType>;
40
+ export declare const parseDeprecatedPrintTypeOptions: (cliOpts: Maybe<DeprecatedCliOptions>, configOptions: Maybe<DeprecatedConfigPrintTypeOptions>) => Partial<{
41
+ hierarchy: TypeHierarchyType;
42
+ }>;
43
+ export declare const getPrintTypeOptions: (cliOpts: Maybe<CliOptions & DeprecatedCliOptions>, configOptions: Maybe<ConfigPrintTypeOptions & DeprecatedConfigPrintTypeOptions>) => Required<ConfigPrintTypeOptions>;
31
44
  export declare const parseGroupByOption: (groupOptions: unknown) => Maybe<GroupByDirectiveOptions>;
32
- export declare const buildConfig: (configFileOpts: Maybe<ConfigOptions>, cliOpts: Maybe<CliOptions>, id?: Maybe<string>) => Promise<Options>;
45
+ export declare const buildConfig: (configFileOpts: Maybe<ConfigOptions>, cliOpts?: Maybe<CliOptions>, id?: Maybe<string>) => Promise<Options>;
package/dist/config.js CHANGED
@@ -1,10 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildConfig = exports.parseGroupByOption = exports.getPrintTypeOptions = exports.getDocOptions = exports.parseDeprecatedDocOptions = exports.getDiffMethod = exports.getCustomDirectives = exports.getVisibilityDirectives = exports.getSkipDocDirectives = exports.getOnlyDocDirectives = exports.getDocDirective = exports.DEFAULT_OPTIONS = exports.ASSET_HOMEPAGE_LOCATION = exports.PACKAGE_NAME = exports.DOCS_URL = exports.DeprecatedOption = exports.DiffMethod = void 0;
3
+ exports.buildConfig = exports.parseGroupByOption = exports.getPrintTypeOptions = exports.parseDeprecatedPrintTypeOptions = exports.getTypeHierarchyOption = exports.getDocOptions = exports.parseDeprecatedDocOptions = exports.getDiffMethod = exports.getCustomDirectives = exports.getVisibilityDirectives = exports.getSkipDocDirectives = exports.getOnlyDocDirectives = exports.getDocDirective = exports.DEFAULT_OPTIONS = exports.ASSET_HOMEPAGE_LOCATION = exports.PACKAGE_NAME = exports.DOCS_URL = exports.DeprecatedOption = exports.DiffMethod = exports.TypeHierarchy = void 0;
4
4
  const node_path_1 = require("node:path");
5
5
  const node_os_1 = require("node:os");
6
6
  const graphql_config_1 = require("./graphql-config");
7
7
  const logger_1 = require("@graphql-markdown/logger");
8
+ var TypeHierarchy;
9
+ (function (TypeHierarchy) {
10
+ TypeHierarchy["API"] = "api";
11
+ TypeHierarchy["ENTITY"] = "entity";
12
+ TypeHierarchy["FLAT"] = "flat";
13
+ })(TypeHierarchy || (exports.TypeHierarchy = TypeHierarchy = {}));
8
14
  var DiffMethod;
9
15
  (function (DiffMethod) {
10
16
  DiffMethod["NONE"] = "NONE";
@@ -25,9 +31,10 @@ exports.DEFAULT_OPTIONS = {
25
31
  customDirective: undefined,
26
32
  diffMethod: DiffMethod.NONE,
27
33
  docOptions: {
28
- index: false,
29
34
  frontMatter: {},
35
+ index: false,
30
36
  },
37
+ force: false,
31
38
  groupByDirective: undefined,
32
39
  homepage: exports.ASSET_HOMEPAGE_LOCATION,
33
40
  linkRoot: "/",
@@ -42,7 +49,7 @@ exports.DEFAULT_OPTIONS = {
42
49
  parentTypePrefix: true,
43
50
  relatedTypeSection: true,
44
51
  typeBadges: true,
45
- useApiGroup: true,
52
+ hierarchy: { [TypeHierarchy.API]: {} },
46
53
  },
47
54
  rootPath: "./docs",
48
55
  schema: "./schema.graphql",
@@ -143,19 +150,77 @@ exports.parseDeprecatedDocOptions = parseDeprecatedDocOptions;
143
150
  const getDocOptions = (cliOpts, configOptions) => {
144
151
  const deprecated = (0, exports.parseDeprecatedDocOptions)(cliOpts, configOptions);
145
152
  return {
146
- index:
147
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
148
- (cliOpts?.index || configOptions?.index) ??
149
- exports.DEFAULT_OPTIONS.docOptions.index,
150
153
  frontMatter: {
151
154
  ...deprecated,
152
155
  ...configOptions?.frontMatter,
153
156
  },
157
+ index:
158
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
159
+ (cliOpts?.index || configOptions?.index) ??
160
+ exports.DEFAULT_OPTIONS.docOptions.index,
154
161
  };
155
162
  };
156
163
  exports.getDocOptions = getDocOptions;
164
+ const getTypeHierarchyOption = (cliOption, configOption) => {
165
+ const parseValue = (config) => {
166
+ if (typeof config === "string") {
167
+ switch (true) {
168
+ case new RegExp(`^${TypeHierarchy.ENTITY}$`, "i").test(config):
169
+ return { [TypeHierarchy.ENTITY]: {} };
170
+ case new RegExp(`^${TypeHierarchy.FLAT}$`, "i").test(config):
171
+ return { [TypeHierarchy.FLAT]: {} };
172
+ case new RegExp(`^${TypeHierarchy.API}$`, "i").test(config):
173
+ return { [TypeHierarchy.API]: {} };
174
+ default:
175
+ return undefined;
176
+ }
177
+ }
178
+ return config;
179
+ };
180
+ const toStringHierarchy = (hierarchy) => {
181
+ return hierarchy && Object.keys(hierarchy)[0];
182
+ };
183
+ const cliHierarchy = parseValue(cliOption);
184
+ const configHierarchy = parseValue(configOption);
185
+ if (cliHierarchy && configHierarchy) {
186
+ const strCliHierarchy = toStringHierarchy(cliHierarchy);
187
+ const strConfigHierarchy = toStringHierarchy(configHierarchy);
188
+ if (strCliHierarchy !== strConfigHierarchy) {
189
+ throw new Error(`Hierarchy option mismatch in CLI flag '${strCliHierarchy}' and config '${strConfigHierarchy}'`);
190
+ }
191
+ }
192
+ return (cliHierarchy ??
193
+ configHierarchy ??
194
+ exports.DEFAULT_OPTIONS.printTypeOptions.hierarchy);
195
+ };
196
+ exports.getTypeHierarchyOption = getTypeHierarchyOption;
197
+ const parseDeprecatedPrintTypeOptions = (cliOpts, configOptions) => {
198
+ // deprecated, replaced by hierarchy
199
+ let option;
200
+ if (typeof cliOpts?.noApiGroup !== "undefined" && cliOpts.noApiGroup) {
201
+ option = { hierarchy: TypeHierarchy.ENTITY };
202
+ (0, logger_1.log)("Type option `noApiGroup` is deprecated. Use `hierarchy: 'entity'` instead.", "warn");
203
+ }
204
+ else if (typeof configOptions?.useApiGroup !== "undefined") {
205
+ if (typeof configOptions.useApiGroup === "object") {
206
+ option = {
207
+ hierarchy: { [TypeHierarchy.API]: { ...configOptions.useApiGroup } },
208
+ };
209
+ }
210
+ else {
211
+ option = configOptions.useApiGroup
212
+ ? { hierarchy: TypeHierarchy.API }
213
+ : { hierarchy: TypeHierarchy.ENTITY };
214
+ }
215
+ (0, logger_1.log)("Type option `useApiGroup` is deprecated. Use `hierarchy: 'api'` instead.", "warn");
216
+ }
217
+ return { ...option };
218
+ };
219
+ exports.parseDeprecatedPrintTypeOptions = parseDeprecatedPrintTypeOptions;
157
220
  const getPrintTypeOptions = (cliOpts, configOptions) => {
221
+ const deprecated = (0, exports.parseDeprecatedPrintTypeOptions)(cliOpts, configOptions);
158
222
  return {
223
+ ...deprecated,
159
224
  codeSection: (!cliOpts?.noCode && configOptions?.codeSection) ??
160
225
  exports.DEFAULT_OPTIONS.printTypeOptions.codeSection,
161
226
  deprecated: (cliOpts?.deprecated ??
@@ -169,8 +234,7 @@ const getPrintTypeOptions = (cliOpts, configOptions) => {
169
234
  exports.DEFAULT_OPTIONS.printTypeOptions.relatedTypeSection,
170
235
  typeBadges: (!cliOpts?.noTypeBadges && configOptions?.typeBadges) ??
171
236
  exports.DEFAULT_OPTIONS.printTypeOptions.typeBadges,
172
- useApiGroup: (!cliOpts?.noApiGroup && configOptions?.useApiGroup) ??
173
- exports.DEFAULT_OPTIONS.printTypeOptions.useApiGroup,
237
+ hierarchy: (0, exports.getTypeHierarchyOption)(cliOpts?.hierarchy, configOptions?.hierarchy),
174
238
  };
175
239
  };
176
240
  exports.getPrintTypeOptions = getPrintTypeOptions;
@@ -203,11 +267,13 @@ const buildConfig = async (configFileOpts, cliOpts, id = "default") => {
203
267
  };
204
268
  const baseURL = cliOpts.base ?? config.baseURL;
205
269
  const { onlyDocDirective, skipDocDirective } = (0, exports.getVisibilityDirectives)(cliOpts, config);
270
+ const force = cliOpts.force ?? config.force ?? exports.DEFAULT_OPTIONS.force;
206
271
  return {
207
272
  baseURL,
208
273
  customDirective: (0, exports.getCustomDirectives)(config.customDirective, skipDocDirective),
209
- diffMethod: (0, exports.getDiffMethod)(cliOpts.diff ?? config.diffMethod, cliOpts.force),
274
+ diffMethod: (0, exports.getDiffMethod)(cliOpts.diff ?? config.diffMethod, force),
210
275
  docOptions: (0, exports.getDocOptions)(cliOpts, config.docOptions),
276
+ force,
211
277
  groupByDirective: (0, exports.parseGroupByOption)(cliOpts.groupByDirective) ?? config.groupByDirective,
212
278
  homepageLocation: cliOpts.homepage ?? config.homepage ?? exports.DEFAULT_OPTIONS.homepage,
213
279
  id: id ?? exports.DEFAULT_OPTIONS.id,
package/dist/diff.js CHANGED
@@ -33,7 +33,7 @@ const hasChanges = async (schema, tmpDir, diffMethod, diffModule = "@graphql-mar
33
33
  const { checkSchemaChanges, } = await Promise.resolve(`${diffModule}`).then(s => __importStar(require(s)));
34
34
  return await checkSchemaChanges(schema, tmpDir, diffMethod);
35
35
  }
36
- catch (error) {
36
+ catch {
37
37
  (0, logger_1.log)(`Cannot find module '${diffModule}' from @graphql-markdown/core!`, logger_1.LogLevel.warn);
38
38
  return true;
39
39
  }
@@ -1,2 +1,2 @@
1
1
  import type { GeneratorOptions } from "@graphql-markdown/types";
2
- export declare const generateDocFromSchema: ({ baseURL, customDirective, diffMethod, docOptions, groupByDirective, homepageLocation, linkRoot, loaders: loadersList, loggerModule, metatags, onlyDocDirective, outputDir, prettify, printer: printerModule, printTypeOptions, schemaLocation, skipDocDirective, tmpDir, }: GeneratorOptions) => Promise<void>;
2
+ export declare const generateDocFromSchema: ({ baseURL, customDirective, diffMethod, docOptions, force, groupByDirective, homepageLocation, linkRoot, loaders: loadersList, loggerModule, metatags, onlyDocDirective, outputDir, prettify, printer: printerModule, printTypeOptions, schemaLocation, skipDocDirective, tmpDir, }: GeneratorOptions) => Promise<void>;
package/dist/generator.js CHANGED
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateDocFromSchema = void 0;
4
4
  const logger_1 = require("@graphql-markdown/logger");
5
5
  const graphql_1 = require("@graphql-markdown/graphql");
6
- const renderer_1 = require("./renderer");
6
+ const config_1 = require("./config");
7
7
  const diff_1 = require("./diff");
8
8
  const printer_1 = require("./printer");
9
- const config_1 = require("./config");
9
+ const renderer_1 = require("./renderer");
10
10
  const NS_PER_SEC = 1e9;
11
11
  const SEC_DECIMALS = 3;
12
- const generateDocFromSchema = async ({ baseURL, customDirective, diffMethod, docOptions, groupByDirective, homepageLocation, linkRoot, loaders: loadersList, loggerModule, metatags, onlyDocDirective, outputDir, prettify, printer: printerModule, printTypeOptions, schemaLocation, skipDocDirective, tmpDir, }) => {
12
+ const generateDocFromSchema = async ({ baseURL, customDirective, diffMethod, docOptions, force, groupByDirective, homepageLocation, linkRoot, loaders: loadersList, loggerModule, metatags, onlyDocDirective, outputDir, prettify, printer: printerModule, printTypeOptions, schemaLocation, skipDocDirective, tmpDir, }) => {
13
13
  const start = process.hrtime.bigint();
14
14
  (0, logger_1.Logger)(loggerModule);
15
15
  const loaders = await (0, graphql_1.getDocumentLoaders)(loadersList);
@@ -57,19 +57,19 @@ const generateDocFromSchema = async ({ baseURL, customDirective, diffMethod, doc
57
57
  skipDocDirectives,
58
58
  metatags,
59
59
  });
60
- const renderer = new renderer_1.Renderer(printer, outputDir, baseURL, groups, prettify, {
60
+ const renderer = await (0, renderer_1.getRenderer)(printer, outputDir, baseURL, groups, prettify, {
61
61
  ...docOptions,
62
62
  deprecated: printTypeOptions?.deprecated,
63
- useApiGroup: printTypeOptions?.useApiGroup,
63
+ force,
64
+ hierarchy: printTypeOptions?.hierarchy,
64
65
  });
65
- const pages = await Promise.all(Object.keys(rootTypes).map(async (typeName) => {
66
+ const pages = await Promise.all(Object.keys(rootTypes).map(async (name) => {
67
+ const typeName = name;
66
68
  return renderer.renderRootTypes(typeName, rootTypes[typeName]);
67
69
  }));
68
70
  await renderer.renderHomepage(homepageLocation);
69
- const sidebarPath = await renderer.renderSidebar();
70
71
  const duration = (Number(process.hrtime.bigint() - start) / NS_PER_SEC).toFixed(SEC_DECIMALS);
71
72
  (0, logger_1.log)(`Documentation successfully generated in "${outputDir}" with base URL "${baseURL}".`, "success");
72
73
  (0, logger_1.log)(`${pages.flat().length} pages generated in ${duration}s from schema "${String(schemaLocation)}".`);
73
- (0, logger_1.log)(`Remember to update your Docusaurus site's sidebars with "${sidebarPath}".`);
74
74
  };
75
75
  exports.generateDocFromSchema = generateDocFromSchema;
@@ -59,7 +59,7 @@ const loadConfiguration = async (id, options, { throwOnMissing, throwOnEmpty } =
59
59
  try {
60
60
  graphQLConfig = await Promise.resolve().then(() => __importStar(require("graphql-config")));
61
61
  }
62
- catch (error) {
62
+ catch {
63
63
  (0, logger_1.log)("Cannot find module 'graphql-config'!");
64
64
  return undefined;
65
65
  }
@@ -90,7 +90,7 @@ const loadConfiguration = async (id, options, { throwOnMissing, throwOnEmpty } =
90
90
  }
91
91
  return projectConfig;
92
92
  }
93
- catch (error) {
93
+ catch {
94
94
  return undefined;
95
95
  }
96
96
  };
package/dist/printer.js CHANGED
@@ -37,7 +37,7 @@ const getPrinter = async (printerModule, config, options) => {
37
37
  Printer.init(schema, baseURL, linkRoot, { ...options });
38
38
  return Printer;
39
39
  }
40
- catch (error) {
40
+ catch {
41
41
  throw new Error(`Cannot find module '${printerModule}'.`);
42
42
  }
43
43
  };
@@ -1,4 +1,6 @@
1
- import type { Category, Maybe, Printer, RendererDocOptions, SchemaEntitiesGroupMap, SchemaEntity } from "@graphql-markdown/types";
1
+ import type { ApiGroupOverrideType, Category, Maybe, Printer, RendererDocOptions, SchemaEntitiesGroupMap, SchemaEntity } from "@graphql-markdown/types";
2
+ export declare const API_GROUPS: Required<ApiGroupOverrideType>;
3
+ export declare const getApiGroupFolder: (type: unknown, groups?: Maybe<ApiGroupOverrideType | boolean>) => string;
2
4
  export declare class Renderer {
3
5
  group: Maybe<SchemaEntitiesGroupMap>;
4
6
  outputDir: string;
@@ -14,6 +16,6 @@ export declare class Renderer {
14
16
  generateCategoryMetafileType(type: unknown, name: string, rootTypeName: SchemaEntity): Promise<string>;
15
17
  renderRootTypes(rootTypeName: SchemaEntity, type: unknown): Promise<Maybe<Maybe<Category>[]>>;
16
18
  renderTypeEntities(dirPath: string, name: string, type: unknown): Promise<Maybe<Category>>;
17
- renderSidebar(): Promise<string>;
18
19
  renderHomepage(homepageLocation: string): Promise<void>;
19
20
  }
21
+ export declare const getRenderer: (printer: Printer, outputDir: string, baseURL: string, group: Maybe<SchemaEntitiesGroupMap>, prettify: boolean, docOptions: Maybe<RendererDocOptions>) => Promise<InstanceType<typeof Renderer>>;
package/dist/renderer.js CHANGED
@@ -1,17 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Renderer = void 0;
3
+ exports.getRenderer = exports.Renderer = exports.getApiGroupFolder = exports.API_GROUPS = void 0;
4
4
  const node_path_1 = require("node:path");
5
5
  const graphql_1 = require("@graphql-markdown/graphql");
6
6
  const utils_1 = require("@graphql-markdown/utils");
7
7
  const logger_1 = require("@graphql-markdown/logger");
8
- const SIDEBAR = "sidebar-schema.js";
8
+ const config_1 = require("./config");
9
+ const DEPRECATED = "deprecated";
9
10
  const CATEGORY_YAML = "_category_.yml";
11
+ const CATEGORY_STYLE_CLASS = "graphql-markdown-api-section";
10
12
  var SidebarPosition;
11
13
  (function (SidebarPosition) {
12
14
  SidebarPosition[SidebarPosition["FIRST"] = 1] = "FIRST";
13
15
  SidebarPosition[SidebarPosition["LAST"] = 999] = "LAST";
14
16
  })(SidebarPosition || (SidebarPosition = {}));
17
+ exports.API_GROUPS = {
18
+ operations: "operations",
19
+ types: "types",
20
+ };
21
+ const getApiGroupFolder = (type, groups) => {
22
+ let folderNames = exports.API_GROUPS;
23
+ if (groups && typeof groups === "object") {
24
+ folderNames = { ...exports.API_GROUPS, ...groups };
25
+ }
26
+ return (0, graphql_1.isApiType)(type) ? folderNames.operations : folderNames.types;
27
+ };
28
+ exports.getApiGroupFolder = getApiGroupFolder;
29
+ const isHierarchy = (options, hierarchy) => {
30
+ return (options?.hierarchy?.[hierarchy] && true);
31
+ };
15
32
  class Renderer {
16
33
  group;
17
34
  outputDir;
@@ -48,14 +65,20 @@ class Renderer {
48
65
  }
49
66
  async generateCategoryMetafileType(type, name, rootTypeName) {
50
67
  let dirPath = this.outputDir;
51
- if (this.options?.useApiGroup === true) {
52
- const typeCat = (0, graphql_1.isApiType)(type) ? "api" : "types";
68
+ if (isHierarchy(this.options, config_1.TypeHierarchy.FLAT)) {
69
+ return dirPath;
70
+ }
71
+ const useApiGroup = isHierarchy(this.options, config_1.TypeHierarchy.API)
72
+ ? this.options.hierarchy[config_1.TypeHierarchy.API]
73
+ : !this.options?.hierarchy;
74
+ if (useApiGroup) {
75
+ const typeCat = (0, exports.getApiGroupFolder)(type, useApiGroup);
53
76
  dirPath = (0, node_path_1.join)(dirPath, (0, utils_1.slugify)(typeCat));
54
- await this.generateCategoryMetafile(typeCat, dirPath, undefined, "graphql-markdown-api-section", { collapsible: false, collapsed: false });
77
+ await this.generateCategoryMetafile(typeCat, dirPath, undefined, CATEGORY_STYLE_CLASS, { collapsible: false, collapsed: false });
55
78
  }
56
79
  if (this.options?.deprecated === "group" && (0, graphql_1.isDeprecated)(type)) {
57
- dirPath = (0, node_path_1.join)(dirPath, (0, utils_1.slugify)("deprecated"));
58
- await this.generateCategoryMetafile("deprecated", dirPath, SidebarPosition.LAST, "deprecated");
80
+ dirPath = (0, node_path_1.join)(dirPath, (0, utils_1.slugify)(DEPRECATED));
81
+ await this.generateCategoryMetafile(DEPRECATED, dirPath, SidebarPosition.LAST, DEPRECATED);
59
82
  }
60
83
  if (this.group &&
61
84
  rootTypeName in this.group &&
@@ -71,9 +94,13 @@ class Renderer {
71
94
  if (typeof type !== "object" || type === null) {
72
95
  return undefined;
73
96
  }
97
+ const isFlat = isHierarchy(this.options, config_1.TypeHierarchy.FLAT);
74
98
  return Promise.all(Object.keys(type)
75
99
  .map(async (name) => {
76
- const dirPath = await this.generateCategoryMetafileType(type[name], name, rootTypeName);
100
+ let dirPath = this.outputDir;
101
+ if (!isFlat) {
102
+ dirPath = await this.generateCategoryMetafileType(type[name], name, rootTypeName);
103
+ }
77
104
  return this.renderTypeEntities(dirPath, name, type[name]);
78
105
  })
79
106
  .filter((res) => {
@@ -82,6 +109,7 @@ class Renderer {
82
109
  }
83
110
  async renderTypeEntities(dirPath, name, type) {
84
111
  const PageRegex = /(?<category>[A-Za-z0-9-]+)[\\/]+(?<pageId>[A-Za-z0-9-]+).mdx$/;
112
+ const PageRegexFlat = /(?<pageId>[A-Za-z0-9-]+).mdx$/;
85
113
  const fileName = (0, utils_1.slugify)(name);
86
114
  const filePath = (0, node_path_1.join)((0, node_path_1.normalize)(dirPath), `${fileName}.mdx`);
87
115
  let content;
@@ -91,40 +119,28 @@ class Renderer {
91
119
  return undefined;
92
120
  }
93
121
  }
94
- catch (error) {
122
+ catch {
95
123
  (0, logger_1.log)(`An error occurred while processing "${type}"`, logger_1.LogLevel.warn);
96
124
  return undefined;
97
125
  }
98
126
  await (0, utils_1.saveFile)(filePath, content, this.prettify ? utils_1.prettifyMarkdown : undefined);
99
127
  const pagePath = (0, node_path_1.relative)(this.outputDir, filePath);
100
- const page = PageRegex.exec(pagePath);
128
+ const isFlat = isHierarchy(this.options, config_1.TypeHierarchy.FLAT);
129
+ const page = isFlat
130
+ ? PageRegexFlat.exec(pagePath)
131
+ : PageRegex.exec(pagePath);
101
132
  if (!page?.groups) {
102
133
  (0, logger_1.log)(`An error occurred while processing file ${filePath} for type "${type}"`, logger_1.LogLevel.warn);
103
134
  return undefined;
104
135
  }
105
- const slug = utils_1.pathUrl.join(page.groups.category, page.groups.pageId);
136
+ const slug = isFlat
137
+ ? page.groups.pageId
138
+ : utils_1.pathUrl.join(page.groups.category, page.groups.pageId);
139
+ const category = isFlat ? "schema" : (0, utils_1.startCase)(page.groups.category);
106
140
  return {
107
- category: (0, utils_1.startCase)(page.groups.category),
108
- slug: slug,
109
- };
110
- }
111
- async renderSidebar() {
112
- const sidebar = {
113
- schemaSidebar: [
114
- {
115
- type: "autogenerated",
116
- dirName: this.baseURL,
117
- },
118
- ],
141
+ category,
142
+ slug,
119
143
  };
120
- const jsonSidebar = `
121
- /** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
122
-
123
- module.exports = ${JSON.stringify(sidebar, null, 2)};
124
- `;
125
- const filePath = (0, node_path_1.join)(this.outputDir, SIDEBAR);
126
- await (0, utils_1.saveFile)(filePath, jsonSidebar, this.prettify ? utils_1.prettifyJavascript : undefined);
127
- return filePath;
128
144
  }
129
145
  async renderHomepage(homepageLocation) {
130
146
  const homePage = (0, node_path_1.basename)(homepageLocation);
@@ -140,3 +156,8 @@ module.exports = ${JSON.stringify(sidebar, null, 2)};
140
156
  }
141
157
  }
142
158
  exports.Renderer = Renderer;
159
+ const getRenderer = async (printer, outputDir, baseURL, group, prettify, docOptions) => {
160
+ await (0, utils_1.ensureDir)(outputDir, { forceEmpty: docOptions?.force });
161
+ return new Renderer(printer, outputDir, baseURL, group, prettify, docOptions);
162
+ };
163
+ exports.getRenderer = getRenderer;
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.10.4",
8
+ "version": "1.12.0",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
@@ -63,18 +63,18 @@
63
63
  "docs": "typedoc"
64
64
  },
65
65
  "dependencies": {
66
- "@graphql-markdown/graphql": "^1.1.3",
67
- "@graphql-markdown/logger": "^1.0.3",
68
- "@graphql-markdown/utils": "^1.6.5"
66
+ "@graphql-markdown/graphql": "^1.1.4",
67
+ "@graphql-markdown/logger": "^1.0.4",
68
+ "@graphql-markdown/utils": "^1.7.0"
69
69
  },
70
70
  "peerDependencies": {
71
- "@graphql-markdown/diff": "^1.1.6",
72
- "@graphql-markdown/helpers": "^1.0.6",
73
- "@graphql-markdown/printer-legacy": "^1.8.4",
74
- "graphql-config": "^5.0.3"
71
+ "@graphql-markdown/diff": "^1.1.8",
72
+ "@graphql-markdown/helpers": "^1.0.7",
73
+ "@graphql-markdown/printer-legacy": "^1.9.0",
74
+ "graphql-config": "^5.1.0"
75
75
  },
76
76
  "devDependencies": {
77
- "@graphql-markdown/types": "^1.3.1"
77
+ "@graphql-markdown/types": "^1.4.0"
78
78
  },
79
79
  "peerDependenciesMeta": {
80
80
  "@graphql-markdown/printer-legacy": {