printer
getPrinter()
function getPrinter(
printerModule?,
config?,
options?,
formatter?,
mdxDeclaration?,
eventEmitter?,
): Promise<typeof IPrinter>;
Defined in: printer.ts:62
Loads and initializes a printer module for GraphQL schema documentation.
This function dynamically imports 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
printerModule?
Maybe<PackageName>
The name/path of the printer module to load
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 printerModule is not a string
Throws
Will throw an error if config is not provided
Throws
Will throw an error if the module specified by printerModule cannot be found
Example
import { getPrinter } from "@graphql-markdown/core";
import { buildSchema } from "graphql";
const schema = buildSchema(`
type Query {
hello: String
}
`);
const printer = await getPrinter(
"@graphql-markdown/printer-legacy",
{
schema,
baseURL: "/docs",
linkRoot: "graphql",
},
{
printTypeOptions: { includeDeprecationReasons: true },
},
);
const output = printer.printSchema();