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.ts:96
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β
optionsβ
static options: Readonly<Maybe<PrintTypeOptions>>;
Defined in: printer.ts:101
Global printer configuration options
Staticβ
printCustomDirectives()β
readonly static printCustomDirectives: (type, options) => string;
Defined in: printer.ts:113
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β
string
Markdown string containing all formatted directives
Staticβ
printCustomTags()β
readonly static printCustomTags: (type, options) => string | MDXString;
Defined in: printer.ts:119
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
Staticβ
printDescription()β
readonly static printDescription: (type, options, noText?) => string | MDXString;
Defined in: printer.ts:107
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
Staticβ
printMDXModuleβ
static printMDXModule: Readonly<MDXSupportType>;
Defined in: printer.ts:125
MDX module configuration
Staticβ
Methodsβ
init()β
static init(
schema,
baseURL,
linkRoot,
options,
mdxParser?): Promise<void>
Defined in: printer.ts:136
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
<MetaOptions
>
metatags?β
Record
<string
, string
>[]
onlyDocDirectives?β
GraphQLDirective
[]
printTypeOptions?β
PrinterConfigPrintTypeOptions
skipDocDirectives?β
GraphQLDirective
[]
mdxParser?β
Record
<string
, unknown
>
Optional MDX parser module for MDX output support
Returnsβ
Promise
<void
>
printCode()β
readonly static printCode(type, options): string
Defined in: printer.ts:228
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
printExample()β
readonly static printExample(type, options): string
Defined in: printer.ts:280
Prints example usage of the type if available
Parametersβ
typeβ
unknown
GraphQL type to generate example for
optionsβ
PrintTypeOptions
Printer configuration options
Returnsβ
string
Formatted example section string or empty string if no example
printHeader()β
readonly static printHeader(
id,
title,
options): string
Defined in: printer.ts:207
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.ts:362
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.ts:345
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?): Maybe<MDXString>
Defined in: printer.ts:408
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β
Maybe
<MDXString
>
Complete documentation as MDX string or undefined if type should be skipped
Exampleβ
const doc = Printer.printType('User', UserType, {
frontMatter: true,
codeSection: true
});
Remarksβ
The method combines multiple sections:
- Header with frontmatter
- Meta tags
- Description
- Code definition
- Custom directives
- Type metadata
- Example usage
- Related types
printTypeMetadata()β
readonly static printTypeMetadata(type, options): string | MDXString
Defined in: printer.ts:309
Prints metadata information for a GraphQL type
Parametersβ
typeβ
unknown
GraphQL type to print metadata for
optionsβ
PrintTypeOptions
Printer configuration options
Returnsβ
string
| MDXString
Formatted metadata string as MDX or plain string
Throwsβ
When type is not supported