Skip to main content

printer

Printer loader helpers for bootstrapping GraphQL-Markdown renderers.

getPrinter()

function getPrinter(
config?,
options?,
formatter?,
mdxDeclaration?,
eventEmitter?,
): Promise<typeof IPrinter>;

Defined in: core/src/printer.ts:65

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.

Parameters

config?

Maybe<PrinterConfig>

Configuration for the printer including schema, baseURL, and linkRoot

options?

Maybe<PrinterOptions>

Additional options for customizing the printer's behavior

formatter?

Partial<Formatter>

Optional formatter functions for customizing output format (e.g., MDX)

mdxDeclaration?

Maybe<string>

eventEmitter?

Maybe<PrinterEventEmitter>

Returns

Promise<typeof IPrinter>

A promise that resolves to the initialized Printer instance

Throws

Will throw an error if config is not provided

Example

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);
}