Skip to main content

printer

GraphQL Schema Printer Module

This module provides functionality for printing GraphQL schema types into Markdown documentation. It includes utilities for handling various GraphQL types, custom directives, and formatting options.

Printer​

Defined in: printer-legacy/src/printer.ts:157

The Printer class implements the core functionality for generating Markdown documentation from GraphQL schema types.

Remarks​

This class provides static methods for rendering different components of the documentation:

  • Headers and frontmatter
  • Type descriptions and code blocks
  • Custom directives and metadata
  • Examples and relations

Example​

const printer = new Printer();
await printer.init(schema, "/docs", "graphql", options);
const docs = printer.printType("Query", queryType);

Implements​

  • IPrinter

Constructors​

Constructor​

new Printer(): Printer;
Returns​

Printer

Properties​

printCustomDirectives​

readonly static printCustomDirectives: (type, options) => Maybe<PageSection>;

Defined in: printer-legacy/src/printer.ts:166

Prints custom directives

Prints all custom directives for a type as a Markdown section

Parameters​
type​

unknown

The GraphQL type to print directives for

options​

PrintTypeOptions

General printing options

Returns​

Maybe<PageSection>

A "Directives" PageSection, or undefined when no directives are printable

printCustomTags​

readonly static printCustomTags: (type, options) => string | MDXString;

Defined in: printer-legacy/src/printer.ts:171

Prints custom tags

Prints custom directive tags as Markdown badges

Parameters​
type​

unknown

The GraphQL type to print tags for

options​

PrintTypeOptions

General printing options

Returns​

string | MDXString

Formatted Markdown string of badges or empty string

printDescription​

readonly static printDescription: (type, options, noText?) => string | MDXString;

Defined in: printer-legacy/src/printer.ts:161

Prints type descriptions

Prints the complete description for a GraphQL type, including deprecation warnings and custom directives.

Parameters​
type​

unknown

The GraphQL type to document

options​

PrintTypeOptions

Configuration options for printing

noText?​

string

Optional text to display when no description exists

Returns​

string | MDXString

Combined description, deprecation notices, and custom directives as MDX content

Accessors​

deprecatedOptions​

Get Signature​
get static deprecatedOptions(): Readonly<Maybe<DeprecatedPrintTypeOptions>>;

Defined in: printer-legacy/src/printer.ts:195

Backward-compat section toggles extracted from legacy config options.

These flags are applied only during section order composition.

Returns​

Readonly<Maybe<DeprecatedPrintTypeOptions>>

eventEmitter​

Get Signature​
get static eventEmitter(): Maybe<PrinterEventEmitter>;

Defined in: printer-legacy/src/printer.ts:204

Optional event emitter for print events. When set, the printer will emit events before/after printCode and printType, allowing external code to intercept and modify the output.

Returns​

Maybe<PrinterEventEmitter>

Set Signature​
set static eventEmitter(eventEmitter): void;

Defined in: printer-legacy/src/printer.ts:219

Parameters​
eventEmitter​

Maybe<PrinterEventEmitter>

Returns​

void

mdxDeclaration​

Get Signature​
get static mdxDeclaration(): Readonly<Maybe<string>>;

Defined in: printer-legacy/src/printer.ts:211

Prints mdx modules import declaration

Returns​

Readonly<Maybe<string>>

Set Signature​
set static mdxDeclaration(mdxDeclaration): void;

Defined in: printer-legacy/src/printer.ts:223

Parameters​
mdxDeclaration​

Readonly<Maybe<string>>

Returns​

void

options​

Get Signature​
get static options(): Readonly<Maybe<PrintTypeOptions>>;

Defined in: printer-legacy/src/printer.ts:186

Global printer configuration options

Returns​

Readonly<Maybe<PrintTypeOptions>>

Set Signature​
set static options(options): void;

Defined in: printer-legacy/src/printer.ts:215

Parameters​
options​

Readonly<Maybe<PrintTypeOptions>>

Returns​

void

Methods​

init()​

static init(
schema,
baseURL?,
linkRoot?,
options?,
formatter?,
mdxDeclaration?,
eventEmitter?): Promise<void>;

Defined in: printer-legacy/src/printer.ts:238

Initializes the printer with the given schema and configuration.

Parameters​
schema​

Maybe<GraphQLSchema>

GraphQL schema to generate documentation for

baseURL?​

Maybe<string> = "schema"

Base URL path for documentation, e.g. '/docs'

linkRoot?​

Maybe<string> = "/"

Root path for generating links between types

options?​

Configuration options for the printer

customDirectives?​

CustomDirectiveMap

deprecated?​

TypeDeprecatedOption

groups?​

Partial<Record<SchemaEntity, Record<string, Maybe<string>>>>

meta?​

Maybe<MetaInfo>

metatags?​

Record<string, string>[]

onlyDocDirectives?​

GraphQLDirective[]

printTypeOptions?​

InitPrintTypeOptions

sectionHeaderId?​

boolean

skipDocDirectives?​

GraphQLDirective[]

formatter?​

Partial<Formatter>

Optional formatter functions for customizing output format

mdxDeclaration?​

Maybe<string>

Optional MDX import declaration

eventEmitter?​

Maybe<PrinterEventEmitter>

Optional event emitter for print events interception

Returns​

Promise<void>

printCode()​

readonly static printCode(type, options): string;

Defined in: printer-legacy/src/printer.ts:354

Prints the GraphQL type definition as code block

Parameters​
type​

unknown

GraphQL type to print

options​

PrintTypeOptions

Printer configuration options

Returns​

string

Formatted code block string with type definition

printCodeAsync()​

readonly static printCodeAsync(
type,
typeName,
options): Promise<string>;

Defined in: printer-legacy/src/printer.ts:410

Prints the GraphQL type definition as code block with event emission support.

Parameters​
type​

unknown

GraphQL type to print

typeName​

string

Name of the type being printed

options​

PrintTypeOptions

Printer configuration options

Returns​

Promise<string>

Promise resolving to formatted code block string with type definition

Remarks​

This async version emits events before and after code generation:

  • print:beforePrintCode - Emitted before generating code (can modify inputs or prevent default)
  • print:afterPrintCode - Emitted after generating code (can modify output)

Event handlers can:

  • Modify event.data.options in BEFORE to affect code generation
  • Call event.preventDefault() in BEFORE to skip default generation and provide custom output
  • Modify event.output in AFTER to change the final result

printExample()​

readonly static printExample(type, options): Maybe<PageSection>;

Defined in: printer-legacy/src/printer.ts:455

Prints example usage of the type if available

Parameters​
type​

unknown

GraphQL type to generate example for

options​

PrintTypeOptions

Printer configuration options

Returns​

Maybe<PageSection>

Example page section or undefined when no example is available

printHeader()​

readonly static printHeader(
id,
title,
options): string;

Defined in: printer-legacy/src/printer.ts:333

Prints the header section of a type documentation

Parameters​
id​

string

Unique identifier for the type

title​

string

Display title for the type

options​

PrintTypeOptions

Printer configuration options

Returns​

string

Formatted header string with optional frontmatter

printMetaTags()​

readonly static printMetaTags(_type, options): string | MDXString;

Defined in: printer-legacy/src/printer.ts:528

Prints HTML meta tags for the documentation

Parameters​
_type​

unknown

GraphQL type (unused)

options​

PrintTypeOptions

Printer configuration options containing metatags

Returns​

string | MDXString

Formatted HTML meta tags string

printRelations()​

readonly static printRelations(type, options): string | MDXString;

Defined in: printer-legacy/src/printer.ts:514

Prints related type information

Parameters​
type​

unknown

GraphQL type to find relations for

options​

PrintTypeOptions

Printer configuration options

Returns​

string | MDXString

Formatted relations section as MDX or plain string

printType()​

readonly static printType(
name,
type,
options?): Promise<Maybe<MDXString>>;

Defined in: printer-legacy/src/printer.ts:578

Main method to print complete documentation for a GraphQL type

Parameters​
name​

Maybe<string>

Name identifier for the type

type​

unknown

GraphQL type to generate documentation for

options?​

Maybe<Partial<PrintTypeOptions>>

Optional printer configuration options

Returns​

Promise<Maybe<MDXString>>

Complete documentation as MDX string or undefined if type should be skipped

Example​
const doc = await Printer.printType("User", UserType, {
frontMatter: true,
});
Remarks​

The method combines multiple sections:

  • Header with frontmatter
  • Meta tags
  • Description
  • Code definition
  • Custom directives
  • Type metadata
  • Example usage
  • Related types

When an event emitter is configured, emits events:

  • print:beforePrintType - Before generating documentation
  • print:beforeComposePageType - Before composing section order and final page output
  • print:afterPrintType - After generating documentation (output can be modified)

printTypeMetadata()​

readonly static printTypeMetadata(type, options): Maybe<
| PageSection
| PageSection[]>;

Defined in: printer-legacy/src/printer.ts:478

Prints metadata information for a GraphQL type

Parameters​
type​

unknown

GraphQL type to print metadata for

options​

PrintTypeOptions

Printer configuration options

Returns​

Maybe< | PageSection | PageSection[]>

Metadata section (or section list) for supported types, otherwise undefined