UNPKG

@graphql-markdown/core

Version:

GraphQL-Markdown core package for generating Markdown documentation from a GraphQL schema.

57 lines (56 loc) 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPrinter = void 0; const printer_legacy_1 = require("@graphql-markdown/printer-legacy"); /** * Loads and initializes a printer module for GraphQL schema documentation. * * This function resolves the specified printer module and initializes it * with the provided configuration and options. The printer is responsible for rendering * GraphQL schema documentation in the desired format. * * @param config - Configuration for the printer including schema, baseURL, and linkRoot * @param options - Additional options for customizing the printer's behavior * @param formatter - Optional formatter functions for customizing output format (e.g., MDX) * * @returns A promise that resolves to the initialized Printer instance * * @throws Will throw an error if config is not provided * * @example * ```typescript * import { getPrinter } from '@graphql-markdown/core'; * import { buildSchema } from 'graphql'; * * const schema = buildSchema(` * type Query { * hello: String * } * `); * * const printer = await getPrinter( * { * schema, * baseURL: '/docs', * linkRoot: 'graphql' * }, * { * printTypeOptions: { deprecated: 'group' } * } * ); * * const queryType = schema.getQueryType(); * if (queryType) { * const output = await printer.printType('Query', queryType); * } * ``` */ const getPrinter = async (config, options, formatter, mdxDeclaration, eventEmitter) => { if (!config) { throw new Error("Invalid printer config."); } const { schema, baseURL, linkRoot } = config; await printer_legacy_1.Printer.init(schema, baseURL, linkRoot, options ?? undefined, formatter, mdxDeclaration, eventEmitter); return printer_legacy_1.Printer; }; exports.getPrinter = getPrinter;