Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@graphql-markdown/printer-legacy

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-markdown/printer-legacy - npm Package Compare versions

Comparing version 1.5.0-next.0 to 1.5.0

2

dist/badge.d.ts
import type { Badge, MDXString, Maybe, PrintTypeOptions, SchemaEntitiesGroupMap } from "@graphql-markdown/types";
export declare const DEFAULT_CSS_CLASSNAME: "badge--secondary";
export declare const getTypeBadges: (type: unknown, groups?: Maybe<SchemaEntitiesGroupMap>) => Badge[];
export declare const printBadge: ({ text, classname }: Badge) => MDXString;
export declare const printBadges: (type: unknown, options: PrintTypeOptions) => MDXString | string;
export declare const printBadge: ({ text, classname }: Badge) => MDXString;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.printBadge = exports.printBadges = exports.getTypeBadges = exports.DEFAULT_CSS_CLASSNAME = void 0;
exports.printBadges = exports.printBadge = exports.getTypeBadges = exports.DEFAULT_CSS_CLASSNAME = void 0;
const utils_1 = require("@graphql-markdown/utils");

@@ -44,2 +44,8 @@ const graphql_1 = require("@graphql-markdown/graphql");

exports.getTypeBadges = getTypeBadges;
const printBadge = ({ text, classname }) => {
const textString = typeof text === "string" ? text : text.singular;
const formattedText = (0, utils_1.escapeMDX)(textString);
return `<Badge class="badge ${classname}" text="${formattedText}"/>`;
};
exports.printBadge = printBadge;
const printBadges = (type, options) => {

@@ -56,11 +62,7 @@ if (!("typeBadges" in options) ||

return badges
.map((badge) => (0, exports.printBadge)(badge))
.map((badge) => {
return (0, exports.printBadge)(badge);
})
.join(" ");
};
exports.printBadges = printBadges;
const printBadge = ({ text, classname }) => {
const textString = typeof text === "string" ? text : text.singular;
const formattedText = (0, utils_1.escapeMDX)(textString);
return `<Badge class="badge ${classname}" text="${formattedText}"/>`;
};
exports.printBadge = printBadge;
import type { MDXString, PrintTypeOptions } from "@graphql-markdown/types";
export declare const printCodeArguments: (type: unknown, indentationLevel?: number) => string;
export declare const printCodeField: (type: unknown, options?: PrintTypeOptions, indentationLevel?: number) => MDXString | string;
export declare const printCodeArguments: (type: unknown, indentationLevel?: number) => string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.printCodeArguments = exports.printCodeField = void 0;
exports.printCodeField = exports.printCodeArguments = void 0;
const graphql_1 = require("@graphql-markdown/graphql");
const strings_1 = require("./const/strings");
const printCodeField = (type, options, indentationLevel = 0) => {
if (typeof type !== "object" || type === null || !("type" in type)) {
return "";
}
const skipDirective = options &&
"skipDocDirective" in options &&
(0, graphql_1.hasDirective)(type, options.skipDocDirective);
const skipDeprecated = options &&
"deprecated" in options &&
options.deprecated === "skip" &&
(0, graphql_1.isDeprecated)(type);
if (skipDirective || skipDeprecated) {
return "";
}
let code = `${(0, graphql_1.getTypeName)(type)}`;
code += (0, exports.printCodeArguments)(type, indentationLevel + 1);
code += `: ${(0, graphql_1.getTypeName)(type.type)}`;
code += (0, graphql_1.isDeprecated)(type) ? ` @${strings_1.DEPRECATED}` : "";
code += strings_1.MARKDOWN_EOL;
return code;
};
exports.printCodeField = printCodeField;
const common_1 = require("./common");
const printCodeArguments = (type, indentationLevel = 1) => {

@@ -53,1 +32,16 @@ if (typeof type !== "object" ||

exports.printCodeArguments = printCodeArguments;
const printCodeField = (type, options, indentationLevel = 0) => {
if (typeof type !== "object" || type === null || !("type" in type)) {
return "";
}
if (!(0, common_1.hasPrintableDirective)(type, options)) {
return "";
}
let code = `${(0, graphql_1.getTypeName)(type)}`;
code += (0, exports.printCodeArguments)(type, indentationLevel + 1);
code += `: ${(0, graphql_1.getTypeName)(type.type)}`;
code += (0, graphql_1.isDeprecated)(type) ? ` @${strings_1.DEPRECATED}` : "";
code += strings_1.MARKDOWN_EOL;
return code;
};
exports.printCodeField = printCodeField;

@@ -6,1 +6,2 @@ import type { PrintTypeOptions, MDXString, Maybe } from "@graphql-markdown/types";

export declare const printDescription: (type: unknown, options?: PrintTypeOptions, noText?: string) => MDXString | string;
export declare const hasPrintableDirective: (type: unknown, options?: Pick<PrintTypeOptions, "deprecated" | "onlyDocDirectives" | "skipDocDirectives">) => boolean;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.printDescription = exports.printDeprecation = exports.formatDescription = exports.printCustomDirectives = void 0;
exports.hasPrintableDirective = exports.printDescription = exports.printDeprecation = exports.formatDescription = exports.printCustomDirectives = void 0;
const utils_1 = require("@graphql-markdown/utils");

@@ -14,4 +14,8 @@ const graphql_1 = require("@graphql-markdown/graphql");

const content = Object.values(constDirectiveMap)
.map((constDirectiveOption) => (0, directive_1.getCustomDirectiveResolver)("descriptor", type, constDirectiveOption, ""))
.filter((text) => typeof text === "string" && text.length > 0)
.map((constDirectiveOption) => {
return (0, directive_1.getCustomDirectiveResolver)("descriptor", type, constDirectiveOption, "");
})
.filter((text) => {
return typeof text === "string" && text.length > 0;
})
.join(strings_1.MARKDOWN_EOP);

@@ -48,1 +52,20 @@ return `${strings_1.MARKDOWN_EOP}${content}`;

exports.printDescription = printDescription;
const hasPrintableDirective = (type, options) => {
if (!type) {
return false;
}
if (!options) {
return true;
}
const skipDirective = "skipDocDirectives" in options && options.skipDocDirectives
? (0, graphql_1.hasDirective)(type, options.skipDocDirectives)
: false;
const skipDeprecated = "deprecated" in options &&
options.deprecated === "skip" &&
(0, graphql_1.isDeprecated)(type);
const onlyDirective = "onlyDocDirectives" in options && options.onlyDocDirectives
? (0, graphql_1.hasDirective)(type, options.onlyDocDirectives, true)
: true;
return !(skipDirective || skipDeprecated) && onlyDirective;
};
exports.hasPrintableDirective = hasPrintableDirective;

@@ -1,2 +0,2 @@

import type { CollapsibleOption, DirectiveName, GraphQLSchema, Maybe, PrintTypeOptions, PrinterConfigPrintTypeOptions, SchemaEntitiesGroupMap, SectionLevelValue } from "@graphql-markdown/types";
import type { CollapsibleOption, GraphQLDirective, GraphQLSchema, Maybe, PrintTypeOptions, PrinterConfigPrintTypeOptions, SchemaEntitiesGroupMap, SectionLevelValue } from "@graphql-markdown/types";
export declare enum SectionLevels {

@@ -9,9 +9,10 @@ NONE = "",

export declare const PRINT_TYPE_DEFAULT_OPTIONS: Required<PrinterConfigPrintTypeOptions>;
export declare const DEFAULT_OPTIONS: Required<Omit<PrintTypeOptions, "collapsible" | "groups" | "level" | "parentType" | "schema" | "skipDocDirective">> & {
schema: Maybe<GraphQLSchema>;
skipDocDirective: Maybe<DirectiveName[]>;
export declare const DEFAULT_OPTIONS: Required<Omit<PrintTypeOptions, "collapsible" | "groups" | "level" | "onlyDocDirectives" | "parentType" | "schema" | "skipDocDirectives">> & {
collapsible: Maybe<CollapsibleOption>;
parentType: Maybe<string>;
groups: Maybe<SchemaEntitiesGroupMap>;
level: Maybe<SectionLevelValue>;
onlyDocDirectives: GraphQLDirective[];
parentType: Maybe<string>;
schema: Maybe<GraphQLSchema>;
skipDocDirectives: GraphQLDirective[];
};

@@ -14,2 +14,3 @@ "use strict";

deprecated: "default",
metatags: [],
parentTypePrefix: true,

@@ -27,6 +28,8 @@ relatedTypeSection: true,

level: undefined,
metatags: [],
onlyDocDirectives: [],
parentType: undefined,
schema: undefined,
skipDocDirective: undefined,
skipDocDirectives: [],
withAttributes: false,
};
import type { Badge, PrintTypeOptions, MDXString, CustomDirectiveMapItem, CustomDirectiveResolver, Maybe } from "@graphql-markdown/types";
export declare const getCustomDirectiveResolver: (resolver: CustomDirectiveResolver, type: unknown, constDirectiveOption: CustomDirectiveMapItem, fallback?: Maybe<string>) => Maybe<string>;
export declare const printCustomDirective: (type: unknown, constDirectiveOption: CustomDirectiveMapItem, options: PrintTypeOptions) => Maybe<string>;
export declare const printCustomDirectives: (type: unknown, options: PrintTypeOptions) => string;
export declare const printCustomDirective: (type: unknown, constDirectiveOption: CustomDirectiveMapItem, options: PrintTypeOptions) => Maybe<string>;
export declare const getCustomTags: (type: unknown, options: PrintTypeOptions) => Badge[];
export declare const printCustomTags: (type: unknown, options: PrintTypeOptions) => MDXString | string;
export declare const getCustomDirectiveResolver: (resolver: CustomDirectiveResolver, type: unknown, constDirectiveOption: CustomDirectiveMapItem, fallback?: Maybe<string>) => Maybe<string>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCustomDirectiveResolver = exports.printCustomTags = exports.getCustomTags = exports.printCustomDirective = exports.printCustomDirectives = void 0;
exports.printCustomTags = exports.getCustomTags = exports.printCustomDirectives = exports.printCustomDirective = exports.getCustomDirectiveResolver = void 0;
const graphql_1 = require("@graphql-markdown/graphql");

@@ -9,17 +9,11 @@ const strings_1 = require("./const/strings");

const badge_1 = require("./badge");
const printCustomDirectives = (type, options) => {
const constDirectiveMap = (0, graphql_1.getConstDirectiveMap)(type, options.customDirectives);
if (!constDirectiveMap || Object.keys(constDirectiveMap).length < 1) {
return "";
const getCustomDirectiveResolver = (resolver, type, constDirectiveOption, fallback) => {
if (typeof constDirectiveOption === "undefined" ||
typeof constDirectiveOption.type !== "object" ||
typeof constDirectiveOption[resolver] !== "function") {
return fallback;
}
const directives = Object.values(constDirectiveMap)
.map((constDirectiveOption) => (0, exports.printCustomDirective)(type, constDirectiveOption, options))
.filter((value) => typeof value !== "undefined");
if (directives.length === 0) {
return "";
}
const content = directives.join(strings_1.MARKDOWN_EOP);
return `${options_1.SectionLevels.LEVEL_3} Directives${strings_1.MARKDOWN_EOP}${content}${strings_1.MARKDOWN_EOP}`;
return constDirectiveOption[resolver](constDirectiveOption.type, type);
};
exports.printCustomDirectives = printCustomDirectives;
exports.getCustomDirectiveResolver = getCustomDirectiveResolver;
const printCustomDirective = (type, constDirectiveOption, options) => {

@@ -37,2 +31,21 @@ const typeNameLink = (0, link_1.printLink)(constDirectiveOption.type, {

exports.printCustomDirective = printCustomDirective;
const printCustomDirectives = (type, options) => {
const constDirectiveMap = (0, graphql_1.getConstDirectiveMap)(type, options.customDirectives);
if (!constDirectiveMap || Object.keys(constDirectiveMap).length < 1) {
return "";
}
const directives = Object.values(constDirectiveMap)
.map((constDirectiveOption) => {
return (0, exports.printCustomDirective)(type, constDirectiveOption, options);
})
.filter((value) => {
return typeof value !== "undefined";
});
if (directives.length === 0) {
return "";
}
const content = directives.join(strings_1.MARKDOWN_EOP);
return `${options_1.SectionLevels.LEVEL_3} Directives${strings_1.MARKDOWN_EOP}${content}${strings_1.MARKDOWN_EOP}`;
};
exports.printCustomDirectives = printCustomDirectives;
const getCustomTags = (type, options) => {

@@ -46,4 +59,8 @@ const constDirectiveMap = (0, graphql_1.getConstDirectiveMap)(type, options.customDirectives);

return Object.values(constDirectiveMap)
.map((constDirectiveOption) => (0, exports.getCustomDirectiveResolver)("tag", type, constDirectiveOption))
.filter((value) => typeof value !== "undefined");
.map((constDirectiveOption) => {
return (0, exports.getCustomDirectiveResolver)("tag", type, constDirectiveOption);
})
.filter((value) => {
return typeof value !== "undefined";
});
};

@@ -57,14 +74,7 @@ exports.getCustomTags = getCustomTags;

return badges
.map((badge) => (0, badge_1.printBadge)(badge))
.map((badge) => {
return (0, badge_1.printBadge)(badge);
})
.join(" ");
};
exports.printCustomTags = printCustomTags;
const getCustomDirectiveResolver = (resolver, type, constDirectiveOption, fallback) => {
if (typeof constDirectiveOption === "undefined" ||
typeof constDirectiveOption.type !== "object" ||
typeof constDirectiveOption[resolver] !== "function") {
return fallback;
}
return constDirectiveOption[resolver](constDirectiveOption.type, type);
};
exports.getCustomDirectiveResolver = getCustomDirectiveResolver;
import type { MDXString, PrintTypeOptions } from "@graphql-markdown/types";
export declare const printEnumMetadata: (type: unknown, options: PrintTypeOptions) => MDXString | string;
export declare const printCodeEnum: (type: unknown, options: PrintTypeOptions) => string;
export declare const printCodeEnum: (type: unknown, options?: PrintTypeOptions) => string;

@@ -7,2 +7,3 @@ "use strict";

const section_1 = require("../section");
const common_1 = require("../common");
const printEnumMetadata = (type, options) => {

@@ -23,8 +24,3 @@ if (!(0, graphql_1.isEnumType)(type)) {

.map((value) => {
const skipDirective = "skipDocDirective" in options &&
(0, graphql_1.hasDirective)(value, options.skipDocDirective);
const skipDeprecated = "deprecated" in options &&
options.deprecated === "skip" &&
(0, graphql_1.isDeprecated)(value);
if (skipDirective || skipDeprecated) {
if (!(0, common_1.hasPrintableDirective)(value, options)) {
return "";

@@ -36,3 +32,5 @@ }

})
.filter((value) => value.length > 0)
.filter((value) => {
return value.length > 0;
})
.join(strings_1.MARKDOWN_EOL);

@@ -39,0 +37,0 @@ code += `${strings_1.MARKDOWN_EOL}}`;

import type { MDXString, Maybe, PrintLinkOptions, TypeLink, TypeLocale } from "@graphql-markdown/types";
export declare const getLinkCategory: (type: unknown) => Maybe<TypeLocale>;
export declare const hasOptionWithAttributes: (options: PrintLinkOptions) => boolean;
export declare const hasOptionParentType: (options: PrintLinkOptions) => boolean;
export declare const toLink: (type: unknown, name: string, operation: Maybe<TypeLocale>, options: PrintLinkOptions) => TypeLink;
export declare const getRelationLink: (category: Maybe<TypeLocale>, type: unknown, options: PrintLinkOptions) => Maybe<TypeLink>;
export declare const printLinkAttributes: (type: unknown, text?: Maybe<string>) => string;
export declare const printLink: (type: unknown, options: PrintLinkOptions) => string;
export declare const printParentLink: (type: unknown, options: PrintLinkOptions) => MDXString | string;
export declare const hasOptionWithAttributes: (options: PrintLinkOptions) => boolean;
export declare const hasOptionParentType: (options: PrintLinkOptions) => boolean;
export declare const printLink: (type: unknown, options: PrintLinkOptions) => string;
export declare const printLinkAttributes: (type: unknown, text?: Maybe<string>) => string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.printLinkAttributes = exports.printLink = exports.hasOptionParentType = exports.hasOptionWithAttributes = exports.printParentLink = exports.getRelationLink = exports.toLink = exports.getLinkCategory = void 0;
exports.printParentLink = exports.printLink = exports.printLinkAttributes = exports.getRelationLink = exports.toLink = exports.hasOptionParentType = exports.hasOptionWithAttributes = exports.getLinkCategory = void 0;
const graphql_1 = require("@graphql-markdown/graphql");

@@ -8,2 +8,3 @@ const utils_1 = require("@graphql-markdown/utils");

const strings_1 = require("./const/strings");
const common_1 = require("./common");
const getLinkCategory = (type) => {

@@ -31,2 +32,13 @@ switch (true) {

exports.getLinkCategory = getLinkCategory;
const hasOptionWithAttributes = (options) => {
return "withAttributes" in options && options.withAttributes === true;
};
exports.hasOptionWithAttributes = hasOptionWithAttributes;
const hasOptionParentType = (options) => {
return ("parentTypePrefix" in options &&
options.parentTypePrefix === true &&
"parentType" in options &&
typeof options.parentType !== "undefined");
};
exports.hasOptionParentType = hasOptionParentType;
const toLink = (type, name, operation, options) => {

@@ -40,6 +52,4 @@ const fallback = {

}
if (typeof options !== "undefined" && "skipDocDirective" in options) {
if ((0, graphql_1.hasDirective)(type, options.skipDocDirective)) {
return fallback;
}
if (typeof options !== "undefined" && !(0, common_1.hasPrintableDirective)(type, options)) {
return fallback;
}

@@ -88,19 +98,20 @@ const graphQLNamedType = (0, graphql_1.getNamedType)(type);

exports.getRelationLink = getRelationLink;
const printParentLink = (type, options) => {
if (typeof type !== "object" || type === null || !("type" in type)) {
return "";
const printLinkAttributes = (type, text = "") => {
if (typeof type !== "object" || type === null) {
return text ?? "";
}
return `<Bullet />${(0, exports.printLink)(type.type, {
...options,
withAttributes: true,
})}`;
if (!(0, graphql_1.isLeafType)(type) &&
"ofType" in type &&
typeof type.ofType !== "undefined") {
text = (0, exports.printLinkAttributes)(type.ofType, text);
}
if ((0, graphql_1.isListType)(type)) {
return `[${text}]`;
}
if ((0, graphql_1.isNonNullType)(type)) {
return `${text}!`;
}
return text ?? "";
};
exports.printParentLink = printParentLink;
const hasOptionWithAttributes = (options) => "withAttributes" in options && options.withAttributes === true;
exports.hasOptionWithAttributes = hasOptionWithAttributes;
const hasOptionParentType = (options) => "parentTypePrefix" in options &&
options.parentTypePrefix === true &&
"parentType" in options &&
typeof options.parentType !== "undefined";
exports.hasOptionParentType = hasOptionParentType;
exports.printLinkAttributes = printLinkAttributes;
const printLink = (type, options) => {

@@ -121,19 +132,11 @@ if (typeof type !== "object" || type === null) {

exports.printLink = printLink;
const printLinkAttributes = (type, text = "") => {
if (typeof type !== "object" || type === null) {
return text ?? "";
const printParentLink = (type, options) => {
if (typeof type !== "object" || type === null || !("type" in type)) {
return "";
}
if (!(0, graphql_1.isLeafType)(type) &&
"ofType" in type &&
typeof type.ofType != "undefined") {
text = (0, exports.printLinkAttributes)(type.ofType, text);
}
if ((0, graphql_1.isListType)(type)) {
return `[${text}]`;
}
if ((0, graphql_1.isNonNullType)(type)) {
return `${text}!`;
}
return text ?? "";
return `<Bullet />${(0, exports.printLink)(type.type, {
...options,
withAttributes: true,
})}`;
};
exports.printLinkAttributes = printLinkAttributes;
exports.printParentLink = printParentLink;

@@ -1,19 +0,21 @@

import type { CustomDirectiveMap, DirectiveName, GraphQLSchema, IPrinter, MDXString, Maybe, PrintTypeOptions, PrinterConfigPrintTypeOptions, SchemaEntitiesGroupMap, TypeDeprecatedOption } from "@graphql-markdown/types";
import type { CustomDirectiveMap, GraphQLDirective, GraphQLSchema, IPrinter, MDXString, Maybe, PrintTypeOptions, PrinterConfigPrintTypeOptions, SchemaEntitiesGroupMap, TypeDeprecatedOption } from "@graphql-markdown/types";
export declare class Printer implements IPrinter {
static options: Maybe<PrintTypeOptions>;
static init(schema: Maybe<GraphQLSchema>, baseURL?: Maybe<string>, linkRoot?: Maybe<string>, { customDirectives, groups, printTypeOptions, skipDocDirective, }?: {
static printDescription: (type: unknown, options?: PrintTypeOptions | undefined, noText?: string | undefined) => string | MDXString;
static printCustomDirectives: (type: unknown, options: PrintTypeOptions) => string;
static printCustomTags: (type: unknown, options: PrintTypeOptions) => string | MDXString;
static init(schema: Maybe<GraphQLSchema>, baseURL?: Maybe<string>, linkRoot?: Maybe<string>, { customDirectives, groups, onlyDocDirectives, printTypeOptions, skipDocDirectives, }?: {
customDirectives?: CustomDirectiveMap;
deprecated?: TypeDeprecatedOption;
groups?: SchemaEntitiesGroupMap;
onlyDocDirectives?: GraphQLDirective[];
printTypeOptions?: PrinterConfigPrintTypeOptions;
skipDocDirective?: DirectiveName[];
skipDocDirectives?: GraphQLDirective[];
}): void;
static printHeader: (id: string, title: string, options: PrintTypeOptions) => string;
static printDescription: (type: unknown, options?: PrintTypeOptions | undefined, noText?: string | undefined) => string | MDXString;
static printCode: (type: unknown, options: PrintTypeOptions) => string;
static printCustomDirectives: (type: unknown, options: PrintTypeOptions) => string;
static printCustomTags: (type: unknown, options: PrintTypeOptions) => string | MDXString;
static printTypeMetadata: (type: unknown, options: PrintTypeOptions) => MDXString | string;
static printRelations: (type: unknown, options: PrintTypeOptions) => MDXString | string;
static printMetaTags: (_type: unknown, { metatags }: PrintTypeOptions) => MDXString | string;
static printType: (name: Maybe<string>, type: unknown, options?: Maybe<Partial<PrintTypeOptions>>) => Maybe<MDXString>;
}

@@ -15,7 +15,11 @@ "use strict";

static options;
static init(schema, baseURL = "schema", linkRoot = "/", { customDirectives, groups, printTypeOptions, skipDocDirective, } = {
static printDescription = common_1.printDescription;
static printCustomDirectives = directive_1.printCustomDirectives;
static printCustomTags = directive_1.printCustomTags;
static init(schema, baseURL = "schema", linkRoot = "/", { customDirectives, groups, onlyDocDirectives, printTypeOptions, skipDocDirectives, } = {
customDirectives: undefined,
groups: undefined,
onlyDocDirectives: [],
printTypeOptions: options_1.PRINT_TYPE_DEFAULT_OPTIONS,
skipDocDirective: undefined,
skipDocDirectives: [],
}) {

@@ -37,3 +41,4 @@ if (typeof Printer.options !== "undefined") {

schema,
skipDocDirective: skipDocDirective ?? undefined,
onlyDocDirectives: onlyDocDirectives ?? [],
skipDocDirectives: skipDocDirectives ?? [],
typeBadges: printTypeOptions?.typeBadges ?? options_1.PRINT_TYPE_DEFAULT_OPTIONS.typeBadges,

@@ -44,3 +49,3 @@ };

const { toc, pagination } = options.header ?? options_1.DEFAULT_OPTIONS.header;
const pagination_buttons = pagination
const paginationButtons = pagination
? []

@@ -53,3 +58,3 @@ : ["pagination_next: null", "pagination_prev: null"];

`hide_table_of_contents: ${!toc}`,
...pagination_buttons,
...paginationButtons,
strings_1.FRONT_MATTER,

@@ -59,3 +64,2 @@ ];

};
static printDescription = common_1.printDescription;
static printCode = (type, options) => {

@@ -97,4 +101,2 @@ let code = "";

};
static printCustomDirectives = directive_1.printCustomDirectives;
static printCustomTags = directive_1.printCustomTags;
static printTypeMetadata = (type, options) => {

@@ -128,2 +130,14 @@ switch (true) {

};
static printMetaTags = (_type, { metatags }) => {
if (!metatags || metatags.length < 1) {
return "";
}
const meta = metatags.map((tag) => {
const props = Object.entries(tag).map(([name, value]) => {
return `${name}="${value}"`;
});
return `<meta ${props.join(" ")} />`;
});
return ["<head>", ...meta, "</head>"].join(strings_1.MARKDOWN_EOL);
};
static printType = (name, type, options) => {

@@ -135,8 +149,7 @@ const printTypeOptions = {

};
if (!type ||
!name ||
(0, graphql_1.hasDirective)(type, printTypeOptions.skipDocDirective)) {
if (!name || !(0, common_1.hasPrintableDirective)(type, printTypeOptions)) {
return undefined;
}
const header = Printer.printHeader(name, (0, graphql_1.getTypeName)(type), printTypeOptions);
const metatags = Printer.printMetaTags(type, printTypeOptions);
const description = Printer.printDescription(type, printTypeOptions);

@@ -151,2 +164,3 @@ const code = Printer.printCode(type, printTypeOptions);

mdx_1.mdx,
metatags,
tags,

@@ -153,0 +167,0 @@ description,

@@ -49,3 +49,5 @@ "use strict";

const content = [...data]
.sort((a, b) => a.localeCompare(b))
.sort((a, b) => {
return a.localeCompare(b);
})
.join("<Bullet />");

@@ -57,8 +59,11 @@ return `${options_1.SectionLevels.LEVEL_3} ${section}${strings_1.MARKDOWN_EOP}${content}${strings_1.MARKDOWN_EOP}`;

const relations = {
"Returned by": graphql_1.getRelationOfReturn,
"Member of": graphql_1.getRelationOfField,
"Implemented by": graphql_1.getRelationOfImplementation,
returnedBy: { section: "Returned by", getRelation: graphql_1.getRelationOfReturn },
memberOf: { section: "Member Of", getRelation: graphql_1.getRelationOfField },
implementedBy: {
section: "Implemented By",
getRelation: graphql_1.getRelationOfImplementation,
},
};
let data = "";
for (const [section, getRelation] of Object.entries(relations)) {
for (const { section, getRelation } of Object.values(relations)) {
data += (0, exports.printRelationOf)(type, section, getRelation, options);

@@ -65,0 +70,0 @@ }

import type { MDXString, PrintTypeOptions, SectionLevel } from "@graphql-markdown/types";
export declare const sectionLevels: SectionLevel[];
export declare const printMetadataSection: (type: unknown, values: unknown, section: string, options: PrintTypeOptions) => MDXString | string;
export declare const printSection: (values: unknown, section: string, options: PrintTypeOptions) => MDXString | string;
export declare const printSectionItems: (values: unknown, options: PrintTypeOptions) => MDXString | string;
export declare const printSectionItem: (type: unknown, options: PrintTypeOptions) => MDXString | string;
export declare const printSectionItem: <T>(type: T, options: PrintTypeOptions) => MDXString | string;
export declare const printSectionItems: <V>(values: V | V[], options: PrintTypeOptions) => MDXString | string;
export declare const printSection: <V>(values: V[] | readonly V[], section: string, options: PrintTypeOptions) => MDXString | string;
export declare const printMetadataSection: <T, V>(type: T, values: V | V[] | readonly V[], section: string, options: PrintTypeOptions) => MDXString | string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.printSectionItem = exports.printSectionItems = exports.printSection = exports.printMetadataSection = exports.sectionLevels = void 0;
exports.printMetadataSection = exports.printSection = exports.printSectionItems = exports.printSectionItem = exports.sectionLevels = void 0;
const graphql_1 = require("@graphql-markdown/graphql");

@@ -16,40 +16,49 @@ const common_1 = require("./common");

];
const printMetadataSection = (type, values, section, options) => {
if (typeof type !== "object" ||
type === null ||
!("name" in type) ||
!Array.isArray(values) ||
values.length === 0) {
const printSectionItem = (type, options) => {
const level = "level" in options && typeof options.level === "string"
? options.level
: options_1.SectionLevels.LEVEL_4;
if (!(0, common_1.hasPrintableDirective)(type, options)) {
return "";
}
switch (options.deprecated) {
case "group": {
const { fields, deprecated } = values.reduce((res, arg) => {
(0, graphql_1.isDeprecated)(arg) ? res.deprecated.push(arg) : res.fields.push(arg);
return res;
}, { fields: [], deprecated: [] });
const meta = (0, exports.printSection)(fields, section, {
...options,
parentType: type.name,
});
const deprecatedMeta = (0, exports.printSection)(deprecated, "", {
...options,
parentType: type.name,
level: options_1.SectionLevels.NONE,
collapsible: {
dataOpen: strings_1.HIDE_DEPRECATED,
dataClose: strings_1.SHOW_DEPRECATED,
},
});
return `${meta}${deprecatedMeta}`;
}
case "default":
default:
return (0, exports.printSection)(values, section, {
...options,
parentType: type.name,
});
const typeNameLink = (0, link_1.printLink)(type, {
...options,
withAttributes: false,
});
const description = (0, common_1.printDescription)(type, options, "").replaceAll("\n", `${strings_1.MARKDOWN_EOL}> `);
const badges = (0, badge_1.printBadges)(type, options);
const tags = (0, directive_1.printCustomTags)(type, options);
const parentTypeLink = (0, link_1.printParentLink)(type, options);
let section = `${level} ${typeNameLink}${parentTypeLink} ${badges} ${tags}${strings_1.MARKDOWN_EOL}> ${description}${strings_1.MARKDOWN_EOL}> `;
if ((0, graphql_1.isGraphQLFieldType)(type)) {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
section += (0, exports.printSectionItems)(type.args, {
...options,
level: options_1.SectionLevels.LEVEL_5,
parentType: typeof options.parentType === "undefined"
? type.name
: `${options.parentType}.${type.name}`,
});
}
return section;
};
exports.printMetadataSection = printMetadataSection;
exports.printSectionItem = printSectionItem;
const printSectionItems = (values, options) => {
if (!Array.isArray(values) || values.length === 0) {
return "";
}
const level = ("level" in options && typeof options.level === "string"
? options.level
: options_1.SectionLevels.LEVEL_4);
return values
.map((v) => {
return (v &&
(0, exports.printSectionItem)(v, {
...options,
level,
}));
})
.join(strings_1.MARKDOWN_EOP);
};
exports.printSectionItems = printSectionItems;
const printSection = (values, section, options) => {

@@ -86,47 +95,44 @@ if (!Array.isArray(values) || values.length === 0) {

exports.printSection = printSection;
const printSectionItems = (values, options) => {
if (!Array.isArray(values) || values.length === 0) {
const printMetadataSection = (type, values, section, options) => {
if (typeof type !== "object" ||
type === null ||
!("name" in type) ||
!Array.isArray(values) ||
values.length === 0) {
return "";
}
const level = ("level" in options && typeof options.level === "string"
? options.level
: options_1.SectionLevels.LEVEL_4);
return values
.map((v) => v &&
(0, exports.printSectionItem)(v, {
...options,
level,
}))
.join(strings_1.MARKDOWN_EOP);
};
exports.printSectionItems = printSectionItems;
const printSectionItem = (type, options) => {
const level = "level" in options && typeof options.level === "string"
? options.level
: options_1.SectionLevels.LEVEL_4;
const skipDirective = (0, graphql_1.hasDirective)(type, options.skipDocDirective);
const skipDeprecated = options.deprecated === "skip" && (0, graphql_1.isDeprecated)(type);
if (!type || skipDirective || skipDeprecated) {
return "";
switch (options.deprecated) {
case "group": {
const { fields, deprecated } = values.reduce((res, arg) => {
if ((0, graphql_1.isDeprecated)(arg)) {
res.deprecated.push(arg);
}
else {
res.fields.push(arg);
}
return res;
}, { fields: [], deprecated: [] });
const meta = (0, exports.printSection)(fields, section, {
...options,
parentType: type.name,
});
const deprecatedMeta = (0, exports.printSection)(deprecated, "", {
...options,
parentType: type.name,
level: options_1.SectionLevels.NONE,
collapsible: {
dataOpen: strings_1.HIDE_DEPRECATED,
dataClose: strings_1.SHOW_DEPRECATED,
},
});
return `${meta}${deprecatedMeta}`;
}
case "default":
default:
return (0, exports.printSection)(values, section, {
...options,
parentType: type.name,
});
}
const typeNameLink = (0, link_1.printLink)(type, {
...options,
withAttributes: false,
});
const description = (0, common_1.printDescription)(type, options, "").replaceAll("\n", `${strings_1.MARKDOWN_EOL}> `);
const badges = (0, badge_1.printBadges)(type, options);
const tags = (0, directive_1.printCustomTags)(type, options);
const parentTypeLink = (0, link_1.printParentLink)(type, options);
let section = `${level} ${typeNameLink}${parentTypeLink} ${badges} ${tags}${strings_1.MARKDOWN_EOL}> ${description}${strings_1.MARKDOWN_EOL}> `;
if ((0, graphql_1.isGraphQLFieldType)(type)) {
section += (0, exports.printSectionItems)(type.args, {
...options,
level: options_1.SectionLevels.LEVEL_5,
parentType: typeof options.parentType === "undefined"
? type.name
: `${options.parentType}.${type.name}`,
});
}
return section;
};
exports.printSectionItem = printSectionItem;
exports.printMetadataSection = printMetadataSection;

@@ -8,7 +8,7 @@ {

},
"version": "1.5.0-next.0",
"version": "1.5.0",
"license": "MIT",
"repository": {
"type": "git",
"url": "graphql-markdown/graphql-markdown",
"url": "git+https://github.com/graphql-markdown/graphql-markdown.git",
"directory": "packages/utils"

@@ -59,7 +59,7 @@ },

"dependencies": {
"@graphql-markdown/graphql": "^1.0.0-next.0",
"@graphql-markdown/utils": "^1.6.0-next.0"
"@graphql-markdown/graphql": "^1.0.0",
"@graphql-markdown/utils": "^1.6.0"
},
"devDependencies": {
"@graphql-markdown/types": "^1.0.0-next.0"
"@graphql-markdown/types": "^1.0.0"
},

@@ -66,0 +66,0 @@ "directories": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc