@graphql-markdown/printer-legacy 1.5.0-next.0 → 1.5.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.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Badge, MDXString, Maybe, PrintTypeOptions, SchemaEntitiesGroupMap } from "@graphql-markdown/types";
2
2
  export declare const DEFAULT_CSS_CLASSNAME: "badge--secondary";
3
3
  export declare const getTypeBadges: (type: unknown, groups?: Maybe<SchemaEntitiesGroupMap>) => Badge[];
4
- export declare const printBadges: (type: unknown, options: PrintTypeOptions) => MDXString | string;
5
4
  export declare const printBadge: ({ text, classname }: Badge) => MDXString;
5
+ export declare const printBadges: (type: unknown, options: PrintTypeOptions) => MDXString | string;
package/dist/badge.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.printBadge = exports.printBadges = exports.getTypeBadges = exports.DEFAULT_CSS_CLASSNAME = void 0;
3
+ exports.printBadges = exports.printBadge = exports.getTypeBadges = exports.DEFAULT_CSS_CLASSNAME = void 0;
4
4
  const utils_1 = require("@graphql-markdown/utils");
5
5
  const graphql_1 = require("@graphql-markdown/graphql");
6
6
  const link_1 = require("./link");
@@ -41,6 +41,12 @@ const getTypeBadges = (type, groups) => {
41
41
  return badges;
42
42
  };
43
43
  exports.getTypeBadges = getTypeBadges;
44
+ const printBadge = ({ text, classname }) => {
45
+ const textString = typeof text === "string" ? text : text.singular;
46
+ const formattedText = (0, utils_1.escapeMDX)(textString);
47
+ return `<Badge class="badge ${classname}" text="${formattedText}"/>`;
48
+ };
49
+ exports.printBadge = printBadge;
44
50
  const printBadges = (type, options) => {
45
51
  if (!("typeBadges" in options) ||
46
52
  typeof options.typeBadges !== "boolean" ||
@@ -52,13 +58,9 @@ const printBadges = (type, options) => {
52
58
  return "";
53
59
  }
54
60
  return badges
55
- .map((badge) => (0, exports.printBadge)(badge))
61
+ .map((badge) => {
62
+ return (0, exports.printBadge)(badge);
63
+ })
56
64
  .join(" ");
57
65
  };
58
66
  exports.printBadges = printBadges;
59
- const printBadge = ({ text, classname }) => {
60
- const textString = typeof text === "string" ? text : text.singular;
61
- const formattedText = (0, utils_1.escapeMDX)(textString);
62
- return `<Badge class="badge ${classname}" text="${formattedText}"/>`;
63
- };
64
- exports.printBadge = printBadge;
package/dist/code.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import type { MDXString, PrintTypeOptions } from "@graphql-markdown/types";
2
- export declare const printCodeField: (type: unknown, options?: PrintTypeOptions, indentationLevel?: number) => MDXString | string;
3
2
  export declare const printCodeArguments: (type: unknown, indentationLevel?: number) => string;
3
+ export declare const printCodeField: (type: unknown, options?: PrintTypeOptions, indentationLevel?: number) => MDXString | string;
package/dist/code.js CHANGED
@@ -1,30 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.printCodeArguments = exports.printCodeField = void 0;
3
+ exports.printCodeField = exports.printCodeArguments = void 0;
4
4
  const graphql_1 = require("@graphql-markdown/graphql");
5
5
  const strings_1 = require("./const/strings");
6
- const printCodeField = (type, options, indentationLevel = 0) => {
7
- if (typeof type !== "object" || type === null || !("type" in type)) {
8
- return "";
9
- }
10
- const skipDirective = options &&
11
- "skipDocDirective" in options &&
12
- (0, graphql_1.hasDirective)(type, options.skipDocDirective);
13
- const skipDeprecated = options &&
14
- "deprecated" in options &&
15
- options.deprecated === "skip" &&
16
- (0, graphql_1.isDeprecated)(type);
17
- if (skipDirective || skipDeprecated) {
18
- return "";
19
- }
20
- let code = `${(0, graphql_1.getTypeName)(type)}`;
21
- code += (0, exports.printCodeArguments)(type, indentationLevel + 1);
22
- code += `: ${(0, graphql_1.getTypeName)(type.type)}`;
23
- code += (0, graphql_1.isDeprecated)(type) ? ` @${strings_1.DEPRECATED}` : "";
24
- code += strings_1.MARKDOWN_EOL;
25
- return code;
26
- };
27
- exports.printCodeField = printCodeField;
6
+ const common_1 = require("./common");
28
7
  const printCodeArguments = (type, indentationLevel = 1) => {
29
8
  if (typeof type !== "object" ||
30
9
  type === null ||
@@ -50,3 +29,18 @@ const printCodeArguments = (type, indentationLevel = 1) => {
50
29
  return code;
51
30
  };
52
31
  exports.printCodeArguments = printCodeArguments;
32
+ const printCodeField = (type, options, indentationLevel = 0) => {
33
+ if (typeof type !== "object" || type === null || !("type" in type)) {
34
+ return "";
35
+ }
36
+ if (!(0, common_1.hasPrintableDirective)(type, options)) {
37
+ return "";
38
+ }
39
+ let code = `${(0, graphql_1.getTypeName)(type)}`;
40
+ code += (0, exports.printCodeArguments)(type, indentationLevel + 1);
41
+ code += `: ${(0, graphql_1.getTypeName)(type.type)}`;
42
+ code += (0, graphql_1.isDeprecated)(type) ? ` @${strings_1.DEPRECATED}` : "";
43
+ code += strings_1.MARKDOWN_EOL;
44
+ return code;
45
+ };
46
+ exports.printCodeField = printCodeField;
package/dist/common.d.ts CHANGED
@@ -3,3 +3,4 @@ export declare const printCustomDirectives: (type: unknown, options?: PrintTypeO
3
3
  export declare const formatDescription: (type: unknown, replacement?: Maybe<string>) => MDXString | string;
4
4
  export declare const printDeprecation: (type: unknown) => string;
5
5
  export declare const printDescription: (type: unknown, options?: PrintTypeOptions, noText?: string) => MDXString | string;
6
+ export declare const hasPrintableDirective: (type: unknown, options?: Pick<PrintTypeOptions, "deprecated" | "onlyDocDirectives" | "skipDocDirectives">) => boolean;
package/dist/common.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.printDescription = exports.printDeprecation = exports.formatDescription = exports.printCustomDirectives = void 0;
3
+ exports.hasPrintableDirective = exports.printDescription = exports.printDeprecation = exports.formatDescription = exports.printCustomDirectives = void 0;
4
4
  const utils_1 = require("@graphql-markdown/utils");
5
5
  const graphql_1 = require("@graphql-markdown/graphql");
6
6
  const directive_1 = require("./directive");
@@ -11,8 +11,12 @@ const printCustomDirectives = (type, options) => {
11
11
  return "";
12
12
  }
13
13
  const content = Object.values(constDirectiveMap)
14
- .map((constDirectiveOption) => (0, directive_1.getCustomDirectiveResolver)("descriptor", type, constDirectiveOption, ""))
15
- .filter((text) => typeof text === "string" && text.length > 0)
14
+ .map((constDirectiveOption) => {
15
+ return (0, directive_1.getCustomDirectiveResolver)("descriptor", type, constDirectiveOption, "");
16
+ })
17
+ .filter((text) => {
18
+ return typeof text === "string" && text.length > 0;
19
+ })
16
20
  .join(strings_1.MARKDOWN_EOP);
17
21
  return `${strings_1.MARKDOWN_EOP}${content}`;
18
22
  };
@@ -44,3 +48,22 @@ const printDescription = (type, options, noText) => {
44
48
  return `${deprecation}${description}${customDirectives}`;
45
49
  };
46
50
  exports.printDescription = printDescription;
51
+ const hasPrintableDirective = (type, options) => {
52
+ if (!type) {
53
+ return false;
54
+ }
55
+ if (!options) {
56
+ return true;
57
+ }
58
+ const skipDirective = "skipDocDirectives" in options && options.skipDocDirectives
59
+ ? (0, graphql_1.hasDirective)(type, options.skipDocDirectives)
60
+ : false;
61
+ const skipDeprecated = "deprecated" in options &&
62
+ options.deprecated === "skip" &&
63
+ (0, graphql_1.isDeprecated)(type);
64
+ const onlyDirective = "onlyDocDirectives" in options && options.onlyDocDirectives
65
+ ? (0, graphql_1.hasDirective)(type, options.onlyDocDirectives, true)
66
+ : true;
67
+ return !(skipDirective || skipDeprecated) && onlyDirective;
68
+ };
69
+ exports.hasPrintableDirective = hasPrintableDirective;
@@ -1,4 +1,4 @@
1
- import type { CollapsibleOption, DirectiveName, GraphQLSchema, Maybe, PrintTypeOptions, PrinterConfigPrintTypeOptions, SchemaEntitiesGroupMap, SectionLevelValue } from "@graphql-markdown/types";
1
+ import type { CollapsibleOption, GraphQLDirective, GraphQLSchema, Maybe, PrintTypeOptions, PrinterConfigPrintTypeOptions, SchemaEntitiesGroupMap, SectionLevelValue } from "@graphql-markdown/types";
2
2
  export declare enum SectionLevels {
3
3
  NONE = "",
4
4
  LEVEL_3 = "###",
@@ -6,11 +6,12 @@ export declare enum SectionLevels {
6
6
  LEVEL_5 = "#####"
7
7
  }
8
8
  export declare const PRINT_TYPE_DEFAULT_OPTIONS: Required<PrinterConfigPrintTypeOptions>;
9
- export declare const DEFAULT_OPTIONS: Required<Omit<PrintTypeOptions, "collapsible" | "groups" | "level" | "parentType" | "schema" | "skipDocDirective">> & {
10
- schema: Maybe<GraphQLSchema>;
11
- skipDocDirective: Maybe<DirectiveName[]>;
9
+ export declare const DEFAULT_OPTIONS: Required<Omit<PrintTypeOptions, "collapsible" | "groups" | "level" | "onlyDocDirectives" | "parentType" | "schema" | "skipDocDirectives">> & {
12
10
  collapsible: Maybe<CollapsibleOption>;
13
- parentType: Maybe<string>;
14
11
  groups: Maybe<SchemaEntitiesGroupMap>;
15
12
  level: Maybe<SectionLevelValue>;
13
+ onlyDocDirectives: GraphQLDirective[];
14
+ parentType: Maybe<string>;
15
+ schema: Maybe<GraphQLSchema>;
16
+ skipDocDirectives: GraphQLDirective[];
16
17
  };
@@ -11,6 +11,7 @@ var SectionLevels;
11
11
  exports.PRINT_TYPE_DEFAULT_OPTIONS = {
12
12
  codeSection: true,
13
13
  deprecated: "default",
14
+ metatags: [],
14
15
  parentTypePrefix: true,
15
16
  relatedTypeSection: true,
16
17
  typeBadges: true,
@@ -23,8 +24,10 @@ exports.DEFAULT_OPTIONS = {
23
24
  groups: undefined,
24
25
  header: { toc: true, pagination: true },
25
26
  level: undefined,
27
+ metatags: [],
28
+ onlyDocDirectives: [],
26
29
  parentType: undefined,
27
30
  schema: undefined,
28
- skipDocDirective: undefined,
31
+ skipDocDirectives: [],
29
32
  withAttributes: false,
30
33
  };
@@ -1,6 +1,6 @@
1
1
  import type { Badge, PrintTypeOptions, MDXString, CustomDirectiveMapItem, CustomDirectiveResolver, Maybe } from "@graphql-markdown/types";
2
- export declare const printCustomDirectives: (type: unknown, options: PrintTypeOptions) => string;
2
+ export declare const getCustomDirectiveResolver: (resolver: CustomDirectiveResolver, type: unknown, constDirectiveOption: CustomDirectiveMapItem, fallback?: Maybe<string>) => Maybe<string>;
3
3
  export declare const printCustomDirective: (type: unknown, constDirectiveOption: CustomDirectiveMapItem, options: PrintTypeOptions) => Maybe<string>;
4
+ export declare const printCustomDirectives: (type: unknown, options: PrintTypeOptions) => string;
4
5
  export declare const getCustomTags: (type: unknown, options: PrintTypeOptions) => Badge[];
5
6
  export declare const printCustomTags: (type: unknown, options: PrintTypeOptions) => MDXString | string;
6
- export declare const getCustomDirectiveResolver: (resolver: CustomDirectiveResolver, type: unknown, constDirectiveOption: CustomDirectiveMapItem, fallback?: Maybe<string>) => Maybe<string>;
package/dist/directive.js CHANGED
@@ -1,26 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCustomDirectiveResolver = exports.printCustomTags = exports.getCustomTags = exports.printCustomDirective = exports.printCustomDirectives = void 0;
3
+ exports.printCustomTags = exports.getCustomTags = exports.printCustomDirectives = exports.printCustomDirective = exports.getCustomDirectiveResolver = void 0;
4
4
  const graphql_1 = require("@graphql-markdown/graphql");
5
5
  const strings_1 = require("./const/strings");
6
6
  const options_1 = require("./const/options");
7
7
  const link_1 = require("./link");
8
8
  const badge_1 = require("./badge");
9
- const printCustomDirectives = (type, options) => {
10
- const constDirectiveMap = (0, graphql_1.getConstDirectiveMap)(type, options.customDirectives);
11
- if (!constDirectiveMap || Object.keys(constDirectiveMap).length < 1) {
12
- return "";
13
- }
14
- const directives = Object.values(constDirectiveMap)
15
- .map((constDirectiveOption) => (0, exports.printCustomDirective)(type, constDirectiveOption, options))
16
- .filter((value) => typeof value !== "undefined");
17
- if (directives.length === 0) {
18
- return "";
9
+ const getCustomDirectiveResolver = (resolver, type, constDirectiveOption, fallback) => {
10
+ if (typeof constDirectiveOption === "undefined" ||
11
+ typeof constDirectiveOption.type !== "object" ||
12
+ typeof constDirectiveOption[resolver] !== "function") {
13
+ return fallback;
19
14
  }
20
- const content = directives.join(strings_1.MARKDOWN_EOP);
21
- return `${options_1.SectionLevels.LEVEL_3} Directives${strings_1.MARKDOWN_EOP}${content}${strings_1.MARKDOWN_EOP}`;
15
+ return constDirectiveOption[resolver](constDirectiveOption.type, type);
22
16
  };
23
- exports.printCustomDirectives = printCustomDirectives;
17
+ exports.getCustomDirectiveResolver = getCustomDirectiveResolver;
24
18
  const printCustomDirective = (type, constDirectiveOption, options) => {
25
19
  const typeNameLink = (0, link_1.printLink)(constDirectiveOption.type, {
26
20
  ...options,
@@ -33,6 +27,25 @@ const printCustomDirective = (type, constDirectiveOption, options) => {
33
27
  return `${options_1.SectionLevels.LEVEL_4} ${typeNameLink}${strings_1.MARKDOWN_EOL}> ${description}${strings_1.MARKDOWN_EOL}> `;
34
28
  };
35
29
  exports.printCustomDirective = printCustomDirective;
30
+ const printCustomDirectives = (type, options) => {
31
+ const constDirectiveMap = (0, graphql_1.getConstDirectiveMap)(type, options.customDirectives);
32
+ if (!constDirectiveMap || Object.keys(constDirectiveMap).length < 1) {
33
+ return "";
34
+ }
35
+ const directives = Object.values(constDirectiveMap)
36
+ .map((constDirectiveOption) => {
37
+ return (0, exports.printCustomDirective)(type, constDirectiveOption, options);
38
+ })
39
+ .filter((value) => {
40
+ return typeof value !== "undefined";
41
+ });
42
+ if (directives.length === 0) {
43
+ return "";
44
+ }
45
+ const content = directives.join(strings_1.MARKDOWN_EOP);
46
+ return `${options_1.SectionLevels.LEVEL_3} Directives${strings_1.MARKDOWN_EOP}${content}${strings_1.MARKDOWN_EOP}`;
47
+ };
48
+ exports.printCustomDirectives = printCustomDirectives;
36
49
  const getCustomTags = (type, options) => {
37
50
  const constDirectiveMap = (0, graphql_1.getConstDirectiveMap)(type, options.customDirectives);
38
51
  if (typeof constDirectiveMap !== "object" ||
@@ -41,8 +54,12 @@ const getCustomTags = (type, options) => {
41
54
  return [];
42
55
  }
43
56
  return Object.values(constDirectiveMap)
44
- .map((constDirectiveOption) => (0, exports.getCustomDirectiveResolver)("tag", type, constDirectiveOption))
45
- .filter((value) => typeof value !== "undefined");
57
+ .map((constDirectiveOption) => {
58
+ return (0, exports.getCustomDirectiveResolver)("tag", type, constDirectiveOption);
59
+ })
60
+ .filter((value) => {
61
+ return typeof value !== "undefined";
62
+ });
46
63
  };
47
64
  exports.getCustomTags = getCustomTags;
48
65
  const printCustomTags = (type, options) => {
@@ -51,16 +68,9 @@ const printCustomTags = (type, options) => {
51
68
  return "";
52
69
  }
53
70
  return badges
54
- .map((badge) => (0, badge_1.printBadge)(badge))
71
+ .map((badge) => {
72
+ return (0, badge_1.printBadge)(badge);
73
+ })
55
74
  .join(" ");
56
75
  };
57
76
  exports.printCustomTags = printCustomTags;
58
- const getCustomDirectiveResolver = (resolver, type, constDirectiveOption, fallback) => {
59
- if (typeof constDirectiveOption === "undefined" ||
60
- typeof constDirectiveOption.type !== "object" ||
61
- typeof constDirectiveOption[resolver] !== "function") {
62
- return fallback;
63
- }
64
- return constDirectiveOption[resolver](constDirectiveOption.type, type);
65
- };
66
- exports.getCustomDirectiveResolver = getCustomDirectiveResolver;
@@ -1,3 +1,3 @@
1
1
  import type { MDXString, PrintTypeOptions } from "@graphql-markdown/types";
2
2
  export declare const printEnumMetadata: (type: unknown, options: PrintTypeOptions) => MDXString | string;
3
- export declare const printCodeEnum: (type: unknown, options: PrintTypeOptions) => string;
3
+ export declare const printCodeEnum: (type: unknown, options?: PrintTypeOptions) => string;
@@ -4,6 +4,7 @@ exports.printCodeEnum = exports.printEnumMetadata = void 0;
4
4
  const graphql_1 = require("@graphql-markdown/graphql");
5
5
  const strings_1 = require("../const/strings");
6
6
  const section_1 = require("../section");
7
+ const common_1 = require("../common");
7
8
  const printEnumMetadata = (type, options) => {
8
9
  if (!(0, graphql_1.isEnumType)(type)) {
9
10
  return "";
@@ -19,19 +20,16 @@ const printCodeEnum = (type, options) => {
19
20
  code += type
20
21
  .getValues()
21
22
  .map((value) => {
22
- const skipDirective = "skipDocDirective" in options &&
23
- (0, graphql_1.hasDirective)(value, options.skipDocDirective);
24
- const skipDeprecated = "deprecated" in options &&
25
- options.deprecated === "skip" &&
26
- (0, graphql_1.isDeprecated)(value);
27
- if (skipDirective || skipDeprecated) {
23
+ if (!(0, common_1.hasPrintableDirective)(value, options)) {
28
24
  return "";
29
25
  }
30
26
  const v = (0, graphql_1.getTypeName)(value);
31
27
  const d = (0, graphql_1.isDeprecated)(value) ? ` @${strings_1.DEPRECATED}` : "";
32
28
  return ` ${v}${d}`;
33
29
  })
34
- .filter((value) => value.length > 0)
30
+ .filter((value) => {
31
+ return value.length > 0;
32
+ })
35
33
  .join(strings_1.MARKDOWN_EOL);
36
34
  code += `${strings_1.MARKDOWN_EOL}}`;
37
35
  return code;
package/dist/link.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import type { MDXString, Maybe, PrintLinkOptions, TypeLink, TypeLocale } from "@graphql-markdown/types";
2
2
  export declare const getLinkCategory: (type: unknown) => Maybe<TypeLocale>;
3
- export declare const toLink: (type: unknown, name: string, operation: Maybe<TypeLocale>, options: PrintLinkOptions) => TypeLink;
4
- export declare const getRelationLink: (category: Maybe<TypeLocale>, type: unknown, options: PrintLinkOptions) => Maybe<TypeLink>;
5
- export declare const printParentLink: (type: unknown, options: PrintLinkOptions) => MDXString | string;
6
3
  export declare const hasOptionWithAttributes: (options: PrintLinkOptions) => boolean;
7
4
  export declare const hasOptionParentType: (options: PrintLinkOptions) => boolean;
8
- export declare const printLink: (type: unknown, options: PrintLinkOptions) => string;
5
+ export declare const toLink: (type: unknown, name: string, operation: Maybe<TypeLocale>, options: PrintLinkOptions) => TypeLink;
6
+ export declare const getRelationLink: (category: Maybe<TypeLocale>, type: unknown, options: PrintLinkOptions) => Maybe<TypeLink>;
9
7
  export declare const printLinkAttributes: (type: unknown, text?: Maybe<string>) => string;
8
+ export declare const printLink: (type: unknown, options: PrintLinkOptions) => string;
9
+ export declare const printParentLink: (type: unknown, options: PrintLinkOptions) => MDXString | string;
package/dist/link.js CHANGED
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.printLinkAttributes = exports.printLink = exports.hasOptionParentType = exports.hasOptionWithAttributes = exports.printParentLink = exports.getRelationLink = exports.toLink = exports.getLinkCategory = void 0;
3
+ exports.printParentLink = exports.printLink = exports.printLinkAttributes = exports.getRelationLink = exports.toLink = exports.hasOptionParentType = exports.hasOptionWithAttributes = exports.getLinkCategory = 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
+ const common_1 = require("./common");
8
9
  const getLinkCategory = (type) => {
9
10
  switch (true) {
10
11
  case (0, graphql_1.isDirectiveType)(type):
@@ -27,6 +28,17 @@ const getLinkCategory = (type) => {
27
28
  return undefined;
28
29
  };
29
30
  exports.getLinkCategory = getLinkCategory;
31
+ const hasOptionWithAttributes = (options) => {
32
+ return "withAttributes" in options && options.withAttributes === true;
33
+ };
34
+ exports.hasOptionWithAttributes = hasOptionWithAttributes;
35
+ const hasOptionParentType = (options) => {
36
+ return ("parentTypePrefix" in options &&
37
+ options.parentTypePrefix === true &&
38
+ "parentType" in options &&
39
+ typeof options.parentType !== "undefined");
40
+ };
41
+ exports.hasOptionParentType = hasOptionParentType;
30
42
  const toLink = (type, name, operation, options) => {
31
43
  const fallback = {
32
44
  text: name,
@@ -35,10 +47,8 @@ const toLink = (type, name, operation, options) => {
35
47
  if (typeof type !== "object") {
36
48
  return fallback;
37
49
  }
38
- if (typeof options !== "undefined" && "skipDocDirective" in options) {
39
- if ((0, graphql_1.hasDirective)(type, options.skipDocDirective)) {
40
- return fallback;
41
- }
50
+ if (typeof options !== "undefined" && !(0, common_1.hasPrintableDirective)(type, options)) {
51
+ return fallback;
42
52
  }
43
53
  const graphQLNamedType = (0, graphql_1.getNamedType)(type);
44
54
  let category = (0, exports.getLinkCategory)(graphQLNamedType);
@@ -82,23 +92,24 @@ const getRelationLink = (category, type, options) => {
82
92
  return (0, exports.toLink)(type, type.name, category, options);
83
93
  };
84
94
  exports.getRelationLink = getRelationLink;
85
- const printParentLink = (type, options) => {
86
- if (typeof type !== "object" || type === null || !("type" in type)) {
87
- return "";
95
+ const printLinkAttributes = (type, text = "") => {
96
+ if (typeof type !== "object" || type === null) {
97
+ return text ?? "";
88
98
  }
89
- return `<Bullet />${(0, exports.printLink)(type.type, {
90
- ...options,
91
- withAttributes: true,
92
- })}`;
99
+ if (!(0, graphql_1.isLeafType)(type) &&
100
+ "ofType" in type &&
101
+ typeof type.ofType !== "undefined") {
102
+ text = (0, exports.printLinkAttributes)(type.ofType, text);
103
+ }
104
+ if ((0, graphql_1.isListType)(type)) {
105
+ return `[${text}]`;
106
+ }
107
+ if ((0, graphql_1.isNonNullType)(type)) {
108
+ return `${text}!`;
109
+ }
110
+ return text ?? "";
93
111
  };
94
- exports.printParentLink = printParentLink;
95
- const hasOptionWithAttributes = (options) => "withAttributes" in options && options.withAttributes === true;
96
- exports.hasOptionWithAttributes = hasOptionWithAttributes;
97
- const hasOptionParentType = (options) => "parentTypePrefix" in options &&
98
- options.parentTypePrefix === true &&
99
- "parentType" in options &&
100
- typeof options.parentType !== "undefined";
101
- exports.hasOptionParentType = hasOptionParentType;
112
+ exports.printLinkAttributes = printLinkAttributes;
102
113
  const printLink = (type, options) => {
103
114
  if (typeof type !== "object" || type === null) {
104
115
  return "";
@@ -114,21 +125,13 @@ const printLink = (type, options) => {
114
125
  return `[\`${text}\`](${link.url})`;
115
126
  };
116
127
  exports.printLink = printLink;
117
- const printLinkAttributes = (type, text = "") => {
118
- if (typeof type !== "object" || type === null) {
119
- return text ?? "";
120
- }
121
- if (!(0, graphql_1.isLeafType)(type) &&
122
- "ofType" in type &&
123
- typeof type.ofType != "undefined") {
124
- text = (0, exports.printLinkAttributes)(type.ofType, text);
125
- }
126
- if ((0, graphql_1.isListType)(type)) {
127
- return `[${text}]`;
128
- }
129
- if ((0, graphql_1.isNonNullType)(type)) {
130
- return `${text}!`;
128
+ const printParentLink = (type, options) => {
129
+ if (typeof type !== "object" || type === null || !("type" in type)) {
130
+ return "";
131
131
  }
132
- return text ?? "";
132
+ return `<Bullet />${(0, exports.printLink)(type.type, {
133
+ ...options,
134
+ withAttributes: true,
135
+ })}`;
133
136
  };
134
- exports.printLinkAttributes = printLinkAttributes;
137
+ exports.printParentLink = printParentLink;
package/dist/printer.d.ts CHANGED
@@ -1,19 +1,21 @@
1
- import type { CustomDirectiveMap, DirectiveName, GraphQLSchema, IPrinter, MDXString, Maybe, PrintTypeOptions, PrinterConfigPrintTypeOptions, SchemaEntitiesGroupMap, TypeDeprecatedOption } from "@graphql-markdown/types";
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
3
  static options: Maybe<PrintTypeOptions>;
4
- static init(schema: Maybe<GraphQLSchema>, baseURL?: Maybe<string>, linkRoot?: Maybe<string>, { customDirectives, groups, printTypeOptions, skipDocDirective, }?: {
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;
7
+ static init(schema: Maybe<GraphQLSchema>, baseURL?: Maybe<string>, linkRoot?: Maybe<string>, { customDirectives, groups, onlyDocDirectives, printTypeOptions, skipDocDirectives, }?: {
5
8
  customDirectives?: CustomDirectiveMap;
6
9
  deprecated?: TypeDeprecatedOption;
7
10
  groups?: SchemaEntitiesGroupMap;
11
+ onlyDocDirectives?: GraphQLDirective[];
8
12
  printTypeOptions?: PrinterConfigPrintTypeOptions;
9
- skipDocDirective?: DirectiveName[];
13
+ skipDocDirectives?: GraphQLDirective[];
10
14
  }): void;
11
15
  static printHeader: (id: string, title: string, options: PrintTypeOptions) => string;
12
- static printDescription: (type: unknown, options?: PrintTypeOptions | undefined, noText?: string | undefined) => string | MDXString;
13
16
  static printCode: (type: unknown, options: PrintTypeOptions) => string;
14
- static printCustomDirectives: (type: unknown, options: PrintTypeOptions) => string;
15
- static printCustomTags: (type: unknown, options: PrintTypeOptions) => string | MDXString;
16
17
  static printTypeMetadata: (type: unknown, options: PrintTypeOptions) => MDXString | string;
17
18
  static printRelations: (type: unknown, options: PrintTypeOptions) => MDXString | string;
19
+ static printMetaTags: (_type: unknown, { metatags }: PrintTypeOptions) => MDXString | string;
18
20
  static printType: (name: Maybe<string>, type: unknown, options?: Maybe<Partial<PrintTypeOptions>>) => Maybe<MDXString>;
19
21
  }
package/dist/printer.js CHANGED
@@ -12,11 +12,15 @@ const mdx_1 = require("./const/mdx");
12
12
  const options_1 = require("./const/options");
13
13
  class Printer {
14
14
  static options;
15
- static init(schema, baseURL = "schema", linkRoot = "/", { customDirectives, groups, printTypeOptions, skipDocDirective, } = {
15
+ static printDescription = common_1.printDescription;
16
+ static printCustomDirectives = directive_1.printCustomDirectives;
17
+ static printCustomTags = directive_1.printCustomTags;
18
+ static init(schema, baseURL = "schema", linkRoot = "/", { customDirectives, groups, onlyDocDirectives, printTypeOptions, skipDocDirectives, } = {
16
19
  customDirectives: undefined,
17
20
  groups: undefined,
21
+ onlyDocDirectives: [],
18
22
  printTypeOptions: options_1.PRINT_TYPE_DEFAULT_OPTIONS,
19
- skipDocDirective: undefined,
23
+ skipDocDirectives: [],
20
24
  }) {
21
25
  if (typeof Printer.options !== "undefined") {
22
26
  return;
@@ -33,13 +37,14 @@ class Printer {
33
37
  relatedTypeSection: printTypeOptions?.relatedTypeSection ??
34
38
  options_1.PRINT_TYPE_DEFAULT_OPTIONS.relatedTypeSection,
35
39
  schema,
36
- skipDocDirective: skipDocDirective ?? undefined,
40
+ onlyDocDirectives: onlyDocDirectives ?? [],
41
+ skipDocDirectives: skipDocDirectives ?? [],
37
42
  typeBadges: printTypeOptions?.typeBadges ?? options_1.PRINT_TYPE_DEFAULT_OPTIONS.typeBadges,
38
43
  };
39
44
  }
40
45
  static printHeader = (id, title, options) => {
41
46
  const { toc, pagination } = options.header ?? options_1.DEFAULT_OPTIONS.header;
42
- const pagination_buttons = pagination
47
+ const paginationButtons = pagination
43
48
  ? []
44
49
  : ["pagination_next: null", "pagination_prev: null"];
45
50
  const header = [
@@ -47,12 +52,11 @@ class Printer {
47
52
  `id: ${id}`,
48
53
  `title: ${title}`,
49
54
  `hide_table_of_contents: ${!toc}`,
50
- ...pagination_buttons,
55
+ ...paginationButtons,
51
56
  strings_1.FRONT_MATTER,
52
57
  ];
53
58
  return header.join(strings_1.MARKDOWN_EOL);
54
59
  };
55
- static printDescription = common_1.printDescription;
56
60
  static printCode = (type, options) => {
57
61
  let code = "";
58
62
  if (typeof options.codeSection === "undefined" ||
@@ -89,8 +93,6 @@ class Printer {
89
93
  }
90
94
  return strings_1.MARKDOWN_SOC + code.trim() + strings_1.MARKDOWN_EOC;
91
95
  };
92
- static printCustomDirectives = directive_1.printCustomDirectives;
93
- static printCustomTags = directive_1.printCustomTags;
94
96
  static printTypeMetadata = (type, options) => {
95
97
  switch (true) {
96
98
  case (0, graphql_1.isScalarType)(type):
@@ -119,18 +121,29 @@ class Printer {
119
121
  }
120
122
  return (0, relation_1.printRelations)(type, options);
121
123
  };
124
+ static printMetaTags = (_type, { metatags }) => {
125
+ if (!metatags || metatags.length < 1) {
126
+ return "";
127
+ }
128
+ const meta = metatags.map((tag) => {
129
+ const props = Object.entries(tag).map(([name, value]) => {
130
+ return `${name}="${value}"`;
131
+ });
132
+ return `<meta ${props.join(" ")} />`;
133
+ });
134
+ return ["<head>", ...meta, "</head>"].join(strings_1.MARKDOWN_EOL);
135
+ };
122
136
  static printType = (name, type, options) => {
123
137
  const printTypeOptions = {
124
138
  ...options_1.DEFAULT_OPTIONS,
125
139
  ...Printer.options,
126
140
  ...options,
127
141
  };
128
- if (!type ||
129
- !name ||
130
- (0, graphql_1.hasDirective)(type, printTypeOptions.skipDocDirective)) {
142
+ if (!name || !(0, common_1.hasPrintableDirective)(type, printTypeOptions)) {
131
143
  return undefined;
132
144
  }
133
145
  const header = Printer.printHeader(name, (0, graphql_1.getTypeName)(type), printTypeOptions);
146
+ const metatags = Printer.printMetaTags(type, printTypeOptions);
134
147
  const description = Printer.printDescription(type, printTypeOptions);
135
148
  const code = Printer.printCode(type, printTypeOptions);
136
149
  const customDirectives = Printer.printCustomDirectives(type, printTypeOptions);
@@ -140,6 +153,7 @@ class Printer {
140
153
  return [
141
154
  header,
142
155
  mdx_1.mdx,
156
+ metatags,
143
157
  tags,
144
158
  description,
145
159
  code,
package/dist/relation.js CHANGED
@@ -46,19 +46,24 @@ const printRelationOf = (type, section, getRelation, options) => {
46
46
  return "";
47
47
  }
48
48
  const content = [...data]
49
- .sort((a, b) => a.localeCompare(b))
49
+ .sort((a, b) => {
50
+ return a.localeCompare(b);
51
+ })
50
52
  .join("<Bullet />");
51
53
  return `${options_1.SectionLevels.LEVEL_3} ${section}${strings_1.MARKDOWN_EOP}${content}${strings_1.MARKDOWN_EOP}`;
52
54
  };
53
55
  exports.printRelationOf = printRelationOf;
54
56
  const printRelations = (type, options) => {
55
57
  const relations = {
56
- "Returned by": graphql_1.getRelationOfReturn,
57
- "Member of": graphql_1.getRelationOfField,
58
- "Implemented by": graphql_1.getRelationOfImplementation,
58
+ returnedBy: { section: "Returned by", getRelation: graphql_1.getRelationOfReturn },
59
+ memberOf: { section: "Member Of", getRelation: graphql_1.getRelationOfField },
60
+ implementedBy: {
61
+ section: "Implemented By",
62
+ getRelation: graphql_1.getRelationOfImplementation,
63
+ },
59
64
  };
60
65
  let data = "";
61
- for (const [section, getRelation] of Object.entries(relations)) {
66
+ for (const { section, getRelation } of Object.values(relations)) {
62
67
  data += (0, exports.printRelationOf)(type, section, getRelation, options);
63
68
  }
64
69
  return data;
package/dist/section.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { MDXString, PrintTypeOptions, SectionLevel } from "@graphql-markdown/types";
2
2
  export declare const sectionLevels: SectionLevel[];
3
- export declare const printMetadataSection: (type: unknown, values: unknown, section: string, options: PrintTypeOptions) => MDXString | string;
4
- export declare const printSection: (values: unknown, section: string, options: PrintTypeOptions) => MDXString | string;
5
- export declare const printSectionItems: (values: unknown, options: PrintTypeOptions) => MDXString | string;
6
- export declare const printSectionItem: (type: unknown, options: PrintTypeOptions) => MDXString | string;
3
+ export declare const printSectionItem: <T>(type: T, options: PrintTypeOptions) => MDXString | string;
4
+ export declare const printSectionItems: <V>(values: V | V[], options: PrintTypeOptions) => MDXString | string;
5
+ export declare const printSection: <V>(values: V[] | readonly V[], section: string, options: PrintTypeOptions) => MDXString | string;
6
+ export declare const printMetadataSection: <T, V>(type: T, values: V | V[] | readonly V[], section: string, options: PrintTypeOptions) => MDXString | string;
package/dist/section.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.printSectionItem = exports.printSectionItems = exports.printSection = exports.printMetadataSection = exports.sectionLevels = void 0;
3
+ exports.printMetadataSection = exports.printSection = exports.printSectionItems = exports.printSectionItem = exports.sectionLevels = void 0;
4
4
  const graphql_1 = require("@graphql-markdown/graphql");
5
5
  const common_1 = require("./common");
6
6
  const badge_1 = require("./badge");
@@ -13,44 +13,53 @@ exports.sectionLevels = [
13
13
  options_1.SectionLevels.LEVEL_4,
14
14
  options_1.SectionLevels.LEVEL_5,
15
15
  ];
16
- const printMetadataSection = (type, values, section, options) => {
17
- if (typeof type !== "object" ||
18
- type === null ||
19
- !("name" in type) ||
20
- !Array.isArray(values) ||
21
- values.length === 0) {
16
+ const printSectionItem = (type, options) => {
17
+ const level = "level" in options && typeof options.level === "string"
18
+ ? options.level
19
+ : options_1.SectionLevels.LEVEL_4;
20
+ if (!(0, common_1.hasPrintableDirective)(type, options)) {
22
21
  return "";
23
22
  }
24
- switch (options.deprecated) {
25
- case "group": {
26
- const { fields, deprecated } = values.reduce((res, arg) => {
27
- (0, graphql_1.isDeprecated)(arg) ? res.deprecated.push(arg) : res.fields.push(arg);
28
- return res;
29
- }, { fields: [], deprecated: [] });
30
- const meta = (0, exports.printSection)(fields, section, {
31
- ...options,
32
- parentType: type.name,
33
- });
34
- const deprecatedMeta = (0, exports.printSection)(deprecated, "", {
35
- ...options,
36
- parentType: type.name,
37
- level: options_1.SectionLevels.NONE,
38
- collapsible: {
39
- dataOpen: strings_1.HIDE_DEPRECATED,
40
- dataClose: strings_1.SHOW_DEPRECATED,
41
- },
42
- });
43
- return `${meta}${deprecatedMeta}`;
44
- }
45
- case "default":
46
- default:
47
- return (0, exports.printSection)(values, section, {
48
- ...options,
49
- parentType: type.name,
50
- });
23
+ const typeNameLink = (0, link_1.printLink)(type, {
24
+ ...options,
25
+ withAttributes: false,
26
+ });
27
+ const description = (0, common_1.printDescription)(type, options, "").replaceAll("\n", `${strings_1.MARKDOWN_EOL}> `);
28
+ const badges = (0, badge_1.printBadges)(type, options);
29
+ const tags = (0, directive_1.printCustomTags)(type, options);
30
+ const parentTypeLink = (0, link_1.printParentLink)(type, options);
31
+ let section = `${level} ${typeNameLink}${parentTypeLink} ${badges} ${tags}${strings_1.MARKDOWN_EOL}> ${description}${strings_1.MARKDOWN_EOL}> `;
32
+ if ((0, graphql_1.isGraphQLFieldType)(type)) {
33
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
34
+ section += (0, exports.printSectionItems)(type.args, {
35
+ ...options,
36
+ level: options_1.SectionLevels.LEVEL_5,
37
+ parentType: typeof options.parentType === "undefined"
38
+ ? type.name
39
+ : `${options.parentType}.${type.name}`,
40
+ });
51
41
  }
42
+ return section;
52
43
  };
53
- exports.printMetadataSection = printMetadataSection;
44
+ exports.printSectionItem = printSectionItem;
45
+ const printSectionItems = (values, options) => {
46
+ if (!Array.isArray(values) || values.length === 0) {
47
+ return "";
48
+ }
49
+ const level = ("level" in options && typeof options.level === "string"
50
+ ? options.level
51
+ : options_1.SectionLevels.LEVEL_4);
52
+ return values
53
+ .map((v) => {
54
+ return (v &&
55
+ (0, exports.printSectionItem)(v, {
56
+ ...options,
57
+ level,
58
+ }));
59
+ })
60
+ .join(strings_1.MARKDOWN_EOP);
61
+ };
62
+ exports.printSectionItems = printSectionItems;
54
63
  const printSection = (values, section, options) => {
55
64
  if (!Array.isArray(values) || values.length === 0) {
56
65
  return "";
@@ -82,49 +91,46 @@ const printSection = (values, section, options) => {
82
91
  return `${level} ${section}${openSection}${items}${closeSection}`;
83
92
  };
84
93
  exports.printSection = printSection;
85
- const printSectionItems = (values, options) => {
86
- if (!Array.isArray(values) || values.length === 0) {
87
- return "";
88
- }
89
- const level = ("level" in options && typeof options.level === "string"
90
- ? options.level
91
- : options_1.SectionLevels.LEVEL_4);
92
- return values
93
- .map((v) => v &&
94
- (0, exports.printSectionItem)(v, {
95
- ...options,
96
- level,
97
- }))
98
- .join(strings_1.MARKDOWN_EOP);
99
- };
100
- exports.printSectionItems = printSectionItems;
101
- const printSectionItem = (type, options) => {
102
- const level = "level" in options && typeof options.level === "string"
103
- ? options.level
104
- : options_1.SectionLevels.LEVEL_4;
105
- const skipDirective = (0, graphql_1.hasDirective)(type, options.skipDocDirective);
106
- const skipDeprecated = options.deprecated === "skip" && (0, graphql_1.isDeprecated)(type);
107
- if (!type || skipDirective || skipDeprecated) {
94
+ const printMetadataSection = (type, values, section, options) => {
95
+ if (typeof type !== "object" ||
96
+ type === null ||
97
+ !("name" in type) ||
98
+ !Array.isArray(values) ||
99
+ values.length === 0) {
108
100
  return "";
109
101
  }
110
- const typeNameLink = (0, link_1.printLink)(type, {
111
- ...options,
112
- withAttributes: false,
113
- });
114
- const description = (0, common_1.printDescription)(type, options, "").replaceAll("\n", `${strings_1.MARKDOWN_EOL}> `);
115
- const badges = (0, badge_1.printBadges)(type, options);
116
- const tags = (0, directive_1.printCustomTags)(type, options);
117
- const parentTypeLink = (0, link_1.printParentLink)(type, options);
118
- let section = `${level} ${typeNameLink}${parentTypeLink} ${badges} ${tags}${strings_1.MARKDOWN_EOL}> ${description}${strings_1.MARKDOWN_EOL}> `;
119
- if ((0, graphql_1.isGraphQLFieldType)(type)) {
120
- section += (0, exports.printSectionItems)(type.args, {
121
- ...options,
122
- level: options_1.SectionLevels.LEVEL_5,
123
- parentType: typeof options.parentType === "undefined"
124
- ? type.name
125
- : `${options.parentType}.${type.name}`,
126
- });
102
+ switch (options.deprecated) {
103
+ case "group": {
104
+ const { fields, deprecated } = values.reduce((res, arg) => {
105
+ if ((0, graphql_1.isDeprecated)(arg)) {
106
+ res.deprecated.push(arg);
107
+ }
108
+ else {
109
+ res.fields.push(arg);
110
+ }
111
+ return res;
112
+ }, { fields: [], deprecated: [] });
113
+ const meta = (0, exports.printSection)(fields, section, {
114
+ ...options,
115
+ parentType: type.name,
116
+ });
117
+ const deprecatedMeta = (0, exports.printSection)(deprecated, "", {
118
+ ...options,
119
+ parentType: type.name,
120
+ level: options_1.SectionLevels.NONE,
121
+ collapsible: {
122
+ dataOpen: strings_1.HIDE_DEPRECATED,
123
+ dataClose: strings_1.SHOW_DEPRECATED,
124
+ },
125
+ });
126
+ return `${meta}${deprecatedMeta}`;
127
+ }
128
+ case "default":
129
+ default:
130
+ return (0, exports.printSection)(values, section, {
131
+ ...options,
132
+ parentType: type.name,
133
+ });
127
134
  }
128
- return section;
129
135
  };
130
- exports.printSectionItem = printSectionItem;
136
+ exports.printMetadataSection = printMetadataSection;
package/package.json CHANGED
@@ -5,11 +5,11 @@
5
5
  "bugs": {
6
6
  "url": "https://github.com/graphql-markdown/graphql-markdown/issues"
7
7
  },
8
- "version": "1.5.0-next.0",
8
+ "version": "1.5.0",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "graphql-markdown/graphql-markdown",
12
+ "url": "git+https://github.com/graphql-markdown/graphql-markdown.git",
13
13
  "directory": "packages/utils"
14
14
  },
15
15
  "author": {
@@ -55,11 +55,11 @@
55
55
  "clean": "rm -rf ./dist"
56
56
  },
57
57
  "dependencies": {
58
- "@graphql-markdown/graphql": "^1.0.0-next.0",
59
- "@graphql-markdown/utils": "^1.6.0-next.0"
58
+ "@graphql-markdown/graphql": "^1.0.0",
59
+ "@graphql-markdown/utils": "^1.6.0"
60
60
  },
61
61
  "devDependencies": {
62
- "@graphql-markdown/types": "^1.0.0-next.0"
62
+ "@graphql-markdown/types": "^1.0.0"
63
63
  },
64
64
  "directories": {
65
65
  "test": "tests"