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:184
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β
Propertiesβ
printDecoratorsβ
readonly static printDecorators: (type, options) => PageSections;
Defined in: printer-legacy/src/printer.ts:193
Prints predicate-driven decorators
Prints every decorator declared in the print options, excluding those
targeting a named slot (position: { into }) β those are not part of the
page's section order and are printed separately, into their slot.
Every declared decorator yields an entry, so that composition hooks can restore one which rendered no content. Decorators with a reserved or repeated id are dropped.
Parametersβ
typeβ
unknown
the GraphQL type being printed.
optionsβ
PrintTypeOptions
the print options in effect.
Returnsβ
a map of decorator id to rendered section, empty when none is declared.
printDescriptionβ
readonly static printDescription: (type, options, noText?) => string | MDXString;
Defined in: printer-legacy/src/printer.ts:188
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β
eventEmitterβ
Get Signatureβ
get static eventEmitter(): Maybe<PrinterEventEmitter>;
Defined in: printer-legacy/src/printer.ts:213
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:228
Parametersβ
eventEmitterβ
Maybe<PrinterEventEmitter>
Returnsβ
void
mdxDeclarationβ
Get Signatureβ
get static mdxDeclaration(): Readonly<Maybe<string>>;
Defined in: printer-legacy/src/printer.ts:220
Prints mdx modules import declaration
Returnsβ
Readonly<Maybe<string>>
Set Signatureβ
set static mdxDeclaration(mdxDeclaration): void;
Defined in: printer-legacy/src/printer.ts:232
Parametersβ
mdxDeclarationβ
Readonly<Maybe<string>>
Returnsβ
void
optionsβ
Get Signatureβ
get static options(): Readonly<Maybe<PrintTypeOptions>>;
Defined in: printer-legacy/src/printer.ts:204
Global printer configuration options
Returnsβ
Readonly<Maybe<PrintTypeOptions>>
Set Signatureβ
set static options(options): void;
Defined in: printer-legacy/src/printer.ts:224
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:247
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?β
PrinterInitOptions = DEFAULT_INIT_OPTIONS
Configuration options for the printer
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:335
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:391
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.optionsin BEFORE to affect code generation - Call
event.preventDefault()in BEFORE to skip default generation and provide custom output - Modify
event.outputin AFTER to change the final result
printExample()β
readonly static printExample(type, options): Maybe<PageSection>;
Defined in: printer-legacy/src/printer.ts:436
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:314
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:497
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:483
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:547
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 documentationprint:beforeComposePageType- Before composing section order and final page outputprint:afterPrintType- After generating documentation (output can be modified)
printTypeMetadata()β
readonly static printTypeMetadata(type, options): Maybe<
| PageSection
| PageSection[]>;
Defined in: printer-legacy/src/printer.ts:450
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