@graphql-markdown/printer-legacy 1.6.0 → 1.7.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/badge.js CHANGED
@@ -27,7 +27,7 @@ const getTypeBadges = (type, groups) => {
27
27
  if ((0, graphql_1.isListType)(rootType)) {
28
28
  badges.push({ text: "list", classname: exports.DEFAULT_CSS_CLASSNAME });
29
29
  }
30
- const category = (0, link_1.getLinkCategory)((0, graphql_1.getNamedType)(rootType));
30
+ const category = (0, link_1.getCategoryLocale)((0, graphql_1.getNamedType)(rootType));
31
31
  if (category) {
32
32
  badges.push({ text: category, classname: exports.DEFAULT_CSS_CLASSNAME });
33
33
  }
@@ -15,6 +15,7 @@ exports.PRINT_TYPE_DEFAULT_OPTIONS = {
15
15
  parentTypePrefix: true,
16
16
  relatedTypeSection: true,
17
17
  typeBadges: true,
18
+ useApiGroup: true,
18
19
  };
19
20
  exports.DEFAULT_OPTIONS = {
20
21
  ...exports.PRINT_TYPE_DEFAULT_OPTIONS,
package/dist/group.js CHANGED
@@ -4,7 +4,11 @@ exports.getGroup = void 0;
4
4
  const graphql_1 = require("@graphql-markdown/graphql");
5
5
  const utils_1 = require("@graphql-markdown/utils");
6
6
  const getGroup = (type, groups, typeCategory) => {
7
- if (typeof type !== "object" || type === null || !groups || !typeCategory) {
7
+ if (typeof type !== "object" ||
8
+ type === null ||
9
+ typeof groups !== "object" ||
10
+ groups === null ||
11
+ !typeCategory) {
8
12
  return "";
9
13
  }
10
14
  const graphQLNamedType = (0, graphql_1.getNamedType)(type);
package/dist/link.d.ts CHANGED
@@ -1,7 +1,10 @@
1
- import type { MDXString, Maybe, PrintLinkOptions, TypeLink, TypeLocale } from "@graphql-markdown/types";
2
- export declare const getLinkCategory: (type: unknown) => Maybe<TypeLocale>;
1
+ import type { MDXString, Maybe, PrintLinkOptions, TypeDeprecatedOption, TypeLink, TypeLocale } from "@graphql-markdown/types";
2
+ export declare const getCategoryLocale: (type: unknown) => Maybe<TypeLocale>;
3
+ export declare const getLinkCategoryFolder: (type: unknown, operationLocale?: Maybe<TypeLocale>) => Maybe<string>;
3
4
  export declare const hasOptionWithAttributes: (options: PrintLinkOptions) => boolean;
4
5
  export declare const hasOptionParentType: (options: PrintLinkOptions) => boolean;
6
+ export declare const getLinkApiGroupFolder: (type: unknown) => string;
7
+ export declare const getLinkDeprecatedFolder: (type: unknown, option: Maybe<TypeDeprecatedOption>) => string;
5
8
  export declare const toLink: (type: unknown, name: string, operation: Maybe<TypeLocale>, options: PrintLinkOptions) => TypeLink;
6
9
  export declare const getRelationLink: (category: Maybe<TypeLocale>, type: unknown, options: PrintLinkOptions) => Maybe<TypeLink>;
7
10
  export declare const printLinkAttributes: (type: unknown, text?: Maybe<string>) => string;
package/dist/link.js CHANGED
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.printParentLink = exports.printLink = exports.printLinkAttributes = exports.getRelationLink = exports.toLink = exports.hasOptionParentType = exports.hasOptionWithAttributes = exports.getLinkCategory = void 0;
3
+ exports.printParentLink = exports.printLink = exports.printLinkAttributes = exports.getRelationLink = exports.toLink = exports.getLinkDeprecatedFolder = exports.getLinkApiGroupFolder = exports.hasOptionParentType = exports.hasOptionWithAttributes = exports.getLinkCategoryFolder = exports.getCategoryLocale = void 0;
4
4
  const graphql_1 = require("@graphql-markdown/graphql");
5
5
  const utils_1 = require("@graphql-markdown/utils");
6
6
  const group_1 = require("./group");
7
7
  const strings_1 = require("./const/strings");
8
8
  const common_1 = require("./common");
9
- const getLinkCategory = (type) => {
9
+ const getCategoryLocale = (type) => {
10
10
  switch (true) {
11
11
  case (0, graphql_1.isDirectiveType)(type):
12
12
  return strings_1.ROOT_TYPE_LOCALE.DIRECTIVE;
@@ -27,7 +27,26 @@ const getLinkCategory = (type) => {
27
27
  }
28
28
  return undefined;
29
29
  };
30
- exports.getLinkCategory = getLinkCategory;
30
+ exports.getCategoryLocale = getCategoryLocale;
31
+ const getLinkCategoryFolder = (type, operationLocale) => {
32
+ const categoryLocale = (0, exports.getCategoryLocale)(type);
33
+ if (!categoryLocale) {
34
+ return undefined;
35
+ }
36
+ // special case for relation map
37
+ if (categoryLocale === strings_1.ROOT_TYPE_LOCALE.OPERATION) {
38
+ if (!operationLocale) {
39
+ return undefined;
40
+ }
41
+ return typeof operationLocale === "object"
42
+ ? operationLocale.plural
43
+ : operationLocale;
44
+ }
45
+ return typeof categoryLocale === "object"
46
+ ? categoryLocale.plural
47
+ : categoryLocale;
48
+ };
49
+ exports.getLinkCategoryFolder = getLinkCategoryFolder;
31
50
  const hasOptionWithAttributes = (options) => {
32
51
  return "withAttributes" in options && options.withAttributes === true;
33
52
  };
@@ -39,46 +58,40 @@ const hasOptionParentType = (options) => {
39
58
  typeof options.parentType !== "undefined");
40
59
  };
41
60
  exports.hasOptionParentType = hasOptionParentType;
61
+ const getLinkApiGroupFolder = (type) => {
62
+ return (0, graphql_1.isApiType)(type) ? "api" : "types";
63
+ };
64
+ exports.getLinkApiGroupFolder = getLinkApiGroupFolder;
65
+ const getLinkDeprecatedFolder = (type, option) => {
66
+ return option === "group" && (0, graphql_1.isDeprecated)(type) ? strings_1.DEPRECATED : "";
67
+ };
68
+ exports.getLinkDeprecatedFolder = getLinkDeprecatedFolder;
42
69
  const toLink = (type, name, operation, options) => {
43
70
  const fallback = {
44
71
  text: name,
45
72
  url: "#",
46
73
  };
47
- if (typeof type !== "object") {
48
- return fallback;
49
- }
50
- if (typeof options !== "undefined" && !(0, common_1.hasPrintableDirective)(type, options)) {
74
+ if (typeof type !== "object" ||
75
+ (typeof options !== "undefined" && !(0, common_1.hasPrintableDirective)(type, options))) {
51
76
  return fallback;
52
77
  }
53
78
  const graphQLNamedType = (0, graphql_1.getNamedType)(type);
54
- let category = (0, exports.getLinkCategory)(graphQLNamedType);
79
+ const category = (0, exports.getLinkCategoryFolder)(graphQLNamedType, operation);
55
80
  if (!category || !graphQLNamedType) {
56
81
  return fallback;
57
82
  }
58
- // special case for relation map
59
- if (category === strings_1.ROOT_TYPE_LOCALE.OPERATION) {
60
- if (!operation) {
61
- return fallback;
62
- }
63
- category = operation;
64
- }
65
- if (typeof category === "object") {
66
- category = category.plural;
67
- }
68
83
  const text = graphQLNamedType.name || graphQLNamedType.toString();
69
- const deprecated = typeof options !== "undefined" &&
70
- "deprecated" in options &&
71
- options.deprecated === "group" &&
72
- (0, graphql_1.isDeprecated)(type)
73
- ? strings_1.DEPRECATED
84
+ const deprecatedFolder = options.deprecated
85
+ ? (0, exports.getLinkDeprecatedFolder)(type, options.deprecated)
74
86
  : "";
75
- const group = "groups" in options && options.groups
87
+ const groupFolder = options.groups
76
88
  ? (0, group_1.getGroup)(type, options.groups, category)
77
89
  : "";
78
- const url = utils_1.pathUrl.join(options.basePath, deprecated, group, category, (0, utils_1.slugify)(text));
90
+ const apiGroupFolder = options.useApiGroup ? (0, exports.getLinkApiGroupFolder)(type) : "";
91
+ const url = utils_1.pathUrl.join(options.basePath, deprecatedFolder, apiGroupFolder, groupFolder, category, (0, utils_1.slugify)(text));
79
92
  return {
80
- text: text,
81
- url: url,
93
+ text,
94
+ url,
82
95
  };
83
96
  };
84
97
  exports.toLink = toLink;
package/dist/printer.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import type { CustomDirectiveMap, GraphQLDirective, GraphQLSchema, IPrinter, MDXString, Maybe, PrintTypeOptions, PrinterConfigPrintTypeOptions, SchemaEntitiesGroupMap, TypeDeprecatedOption } from "@graphql-markdown/types";
2
2
  export declare class Printer implements IPrinter {
3
- static options: Maybe<PrintTypeOptions>;
4
- static printDescription: (type: unknown, options?: PrintTypeOptions | undefined, noText?: string | undefined) => string | MDXString;
5
- static printCustomDirectives: (type: unknown, options: PrintTypeOptions) => string;
6
- static printCustomTags: (type: unknown, options: PrintTypeOptions) => string | MDXString;
3
+ static options: Readonly<Maybe<PrintTypeOptions>>;
4
+ static readonly printDescription: (type: unknown, options?: PrintTypeOptions | undefined, noText?: string | undefined) => string | MDXString;
5
+ static readonly printCustomDirectives: (type: unknown, options: PrintTypeOptions) => string;
6
+ static readonly printCustomTags: (type: unknown, options: PrintTypeOptions) => string | MDXString;
7
7
  static init(schema: Maybe<GraphQLSchema>, baseURL?: Maybe<string>, linkRoot?: Maybe<string>, { customDirectives, groups, onlyDocDirectives, printTypeOptions, skipDocDirectives, metatags, }?: {
8
8
  customDirectives?: CustomDirectiveMap;
9
9
  deprecated?: TypeDeprecatedOption;
@@ -13,10 +13,10 @@ export declare class Printer implements IPrinter {
13
13
  skipDocDirectives?: GraphQLDirective[];
14
14
  metatags?: Record<string, string>[];
15
15
  }): void;
16
- static printHeader: (id: string, title: string, options: PrintTypeOptions) => string;
17
- static printCode: (type: unknown, options: PrintTypeOptions) => string;
18
- static printTypeMetadata: (type: unknown, options: PrintTypeOptions) => MDXString | string;
19
- static printRelations: (type: unknown, options: PrintTypeOptions) => MDXString | string;
20
- static printMetaTags: (_type: unknown, { metatags }: PrintTypeOptions) => MDXString | string;
21
- static printType: (name: Maybe<string>, type: unknown, options?: Maybe<Partial<PrintTypeOptions>>) => Maybe<MDXString>;
16
+ static readonly printHeader: (id: string, title: string, options: PrintTypeOptions) => string;
17
+ static readonly printCode: (type: unknown, options: PrintTypeOptions) => string;
18
+ static readonly printTypeMetadata: (type: unknown, options: PrintTypeOptions) => MDXString | string;
19
+ static readonly printRelations: (type: unknown, options: PrintTypeOptions) => MDXString | string;
20
+ static readonly printMetaTags: (_type: unknown, { metatags }: PrintTypeOptions) => MDXString | string;
21
+ static readonly printType: (name: Maybe<string>, type: unknown, options?: Maybe<Partial<PrintTypeOptions>>) => Maybe<MDXString>;
22
22
  }
package/dist/printer.js CHANGED
@@ -43,6 +43,7 @@ class Printer {
43
43
  skipDocDirectives: skipDocDirectives ?? [],
44
44
  typeBadges: printTypeOptions?.typeBadges ?? options_1.PRINT_TYPE_DEFAULT_OPTIONS.typeBadges,
45
45
  metatags: metatags ?? [],
46
+ useApiGroup: printTypeOptions?.useApiGroup ?? options_1.PRINT_TYPE_DEFAULT_OPTIONS.useApiGroup,
46
47
  };
47
48
  }
48
49
  static printHeader = (id, title, options) => {
package/dist/relation.js CHANGED
@@ -55,7 +55,7 @@ const printRelationOf = (type, section, getRelation, options) => {
55
55
  exports.printRelationOf = printRelationOf;
56
56
  const printRelations = (type, options) => {
57
57
  const relations = {
58
- returnedBy: { section: "Returned by", getRelation: graphql_1.getRelationOfReturn },
58
+ returnedBy: { section: "Returned By", getRelation: graphql_1.getRelationOfReturn },
59
59
  memberOf: { section: "Member Of", getRelation: graphql_1.getRelationOfField },
60
60
  implementedBy: {
61
61
  section: "Implemented By",
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.6.0",
8
+ "version": "1.7.0",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
@@ -56,11 +56,11 @@
56
56
  },
57
57
  "dependencies": {
58
58
  "@docusaurus/utils": ">=2.0.0",
59
- "@graphql-markdown/graphql": "^1.0.2",
60
- "@graphql-markdown/utils": "^1.6.2"
59
+ "@graphql-markdown/graphql": "^1.1.0",
60
+ "@graphql-markdown/utils": "^1.6.3"
61
61
  },
62
62
  "devDependencies": {
63
- "@graphql-markdown/types": "^1.0.1"
63
+ "@graphql-markdown/types": "^1.2.0"
64
64
  },
65
65
  "directories": {
66
66
  "test": "tests"