Skip to main content

Integration with Frameworks

GraphQL-Markdown supports multiple documentation frameworks through formatter presets. Each framework has its own setup guide, or you can create a custom formatter for any framework.

Choose a Path​

Use the path that matches your documentation stack:

If you are using...Recommended path
DocusaurusUse the @graphql-markdown/docusaurus plugin when you want the official Docusaurus integration and default Docusaurus formatter behavior.
Hugo, MkDocs, DocFX, mdBook, or HonKitUse @graphql-markdown/cli with a formatter preset from @graphql-markdown/formatters. This is the main path for non-TS/JS documentation ecosystems.
Starlight, Fumadocs, or VocsUse @graphql-markdown/cli with the matching formatter preset when you already have one of these frameworks in place.
Any unsupported frameworkStart from the closest preset or create a custom formatter module.

For new configurations, use the formatter setting. The legacy mdxParser setting still works as a deprecated alias.

Common Setup​

Install the CLI and formatter presets:

npm install @graphql-markdown/cli @graphql-markdown/formatters graphql

Then configure the formatter that matches your framework:

schema: ./schema.graphql
extensions:
graphql-markdown:
rootPath: ./docs
baseURL: api
formatter: "@graphql-markdown/formatters/hugo"

Supported Formatters​

Install the formatters package:

npm install @graphql-markdown/formatters

Then select your framework:

FrameworkPackageSetup
Docusaurus@graphql-markdown/formatters/docusaurusGuide
Astro Starlight@graphql-markdown/formatters/starlightGuide
Next.js + Fumadocs@graphql-markdown/formatters/fumadocsGuide
Vocs@graphql-markdown/formatters/vocsGuide
HonKit@graphql-markdown/formatters/honkitGuide
Hugo@graphql-markdown/formatters/hugoGuide
MkDocs@graphql-markdown/formatters/mkdocsGuide
DocFX@graphql-markdown/formatters/docfxGuide
mdBook@graphql-markdown/formatters/mdbookGuide

Quick Example​

import { runGraphQLMarkdown } from '@graphql-markdown/cli';

await runGraphQLMarkdown({
schema: './schema.graphql',
rootPath: './docs',
baseURL: 'api',
formatter: '@graphql-markdown/formatters/docusaurus', // or your framework
});

3rd Party Packages​

Some frameworks have dedicated integration packages beyond the basic formatters:

FrameworkFramework LinkPackageNPM
VitePressvitepress.devgraphql-markdown-vitepressNPM

Custom MDX Formatter​

For frameworks not listed above, or to customize formatting behavior, create a custom MDX module.

MDX Module Contract​

A custom MDX module can export individual formatter functions:

ExportTypeDescription
formatMDXBadge(badge: { text, classname? }) => stringFormat type badges (deprecated, required, etc.)
formatMDXAdmonition(admonition: { text, title, type, icon? }, meta?) => stringFormat callout/warning blocks
formatMDXBullet(text?: string) => stringFormat bullet point separators
formatMDXDetails(option: { dataOpen, dataClose? }) => stringFormat collapsible sections
formatMDXFrontmatter(props?, formatted?: string[]) => stringFormat page frontmatter
formatMDXLink(link: { text, url }) => { text, url }Transform type links
formatMDXNameEntity(name: string, parentType?: string) => stringFormat named entity references
formatMDXSpecifiedByLink(url: string) => stringFormat scalar specification links

Optional exports:

ExportTypeDescription
mdxDeclarationstringImport statements prepended to generated files
mdxExtensionstringCustom file extension (defaults to .mdx)
tip

You only need to export the formatter functions your framework requires. Any missing functions will use the default HTML-like implementation.

formatMDXDetails Contract​

The string returned by formatMDXDetails must contain a single \r (carriage return) character as a delimiter between the opening and closing parts. The printer splits on "\r" to wrap content, so reserve \r only for that separator and use \n for line breaks.

// βœ… correct β€” use \n for line breaks and a single standalone \r as the delimiter
export const formatMDXDetails = ({ dataOpen }) =>
`\n\n<MyDetails label="${dataOpen}">\n\r</MyDetails>\n\n`;

// ❌ incorrect β€” no \r means the closing tag is lost
export const formatMDXDetails = ({ dataOpen }) =>
`\n\n<MyDetails label="${dataOpen}">\n</MyDetails>\n\n`;

// ❌ incorrect β€” CRLF introduces extra \r characters
export const formatMDXDetails = ({ dataOpen }) =>
`\r\n\r\n<MyDetails label="${dataOpen}">\r\n\r</MyDetails>\r\n\r\n`;

Extending a Preset​

To customize a preset, spread its exports and override specific formatters:

// src/modules/custom-mdx.cjs
const PresetMDX = require('@graphql-markdown/formatters/starlight');

const formatMDXBadge = ({ text, classname }) => {
// Your custom logic
return `<Badge>${text}</Badge>`;
};

module.exports = {
...PresetMDX,
formatMDXBadge,
};

Lifecycle Hooks​

Custom MDX modules can also export lifecycle hooks to customize the generation process. See Hooks Recipes for the full reference and examples.