# GraphQL-Markdown Documentation > Human-friendly documentation for GraphQL-Markdown schemas and tooling. Complete offline export of the core docs, API reference, and worked examples published on graphql-markdown.dev. ## Introduction GraphQL-Markdown generates Markdown and MDX documentation from a GraphQL schema. You can use the official Docusaurus integration for Docusaurus sites, or use the CLI with formatter presets for other supported documentation ecosystems such as Hugo, MkDocs, DocFX, and mdBook. ## Why GraphQL Markdown? Managing API documentation can be time-consuming and prone to becoming outdated. This package solves these challenges by: - Automatically generating documentation from your schema - Keeping documentation in sync with your API - Providing a consistent documentation structure - Integrating with Docusaurus and supported formatter-based documentation ecosystems ## Features - Easy set up and customizable output - Full cross-linking between types with visual relationship hierarchy - MDX output fully customizable using your own components - Extensible lifecycle hooks and events system - Any schema loader compatible with `@graphql-tools/load` — SDL files, remote endpoints, or code-first TS/JS schemas - Group types into categories using directives - Namespaced operations (nested query/mutation/subscription objects) - GraphQL config support ## Quick Install For **Docusaurus** projects: ```bash npm install @graphql-markdown/docusaurus graphql ``` For **formatter-based setups** (Hugo, MkDocs, DocFX, mdBook, Astro, Next.js, etc.): ```bash npm install @graphql-markdown/cli @graphql-markdown/formatters graphql ``` For the full list of supported formatter presets, see [Integration with Frameworks](/docs/advanced/integration-with-frameworks). --- ## Getting started :::info GraphQL-Markdown supports two main setup paths: - the official Docusaurus integration for Docusaurus sites - the CLI with formatter presets for other supported documentation ecosystems This guide focuses on the Docusaurus path. If you are using Hugo, MkDocs, DocFX, mdBook, or another supported formatter-based setup, start with our [Framework Integration Guide](/docs/advanced/integration-with-frameworks). ::: If you are setting up Docusaurus, get started by [creating a new site](#new-docusaurus-site). Or try GraphQL-Markdown immediately with our [demo](/docs/try-it). If you are not using Docusaurus, install the CLI and formatter presets: ```shell title="shell" npm install @graphql-markdown/cli @graphql-markdown/formatters graphql ``` Then continue with [Integration with Frameworks](/docs/advanced/integration-with-frameworks) to choose the preset for your documentation stack. ## New Docusaurus site ### Requirements Node.js version [22.12](https://nodejs.org/en/download/) or above (which can be checked by running `node -v`) is required. :::info[Package managers] You can use either `npm`, `yarn`, or `pnpm` as your package manager. The examples in this documentation use `npm`, but you can substitute the commands with your preferred package manager. When installing Node.js, you are recommended to check all checkboxes related to dependencies. ::: :::tip You can use [nvm](https://github.com/nvm-sh/nvm), installed on a single machine, to manage multiple Node.js versions. ::: ### Generate a new site Generate a new Docusaurus site using the [GraphQL-Markdown template](https://github.com/graphql-markdown/template). The template will automatically be added to your project after you run the command: ```shell title="shell" npm init docusaurus my-website https://github.com/graphql-markdown/template.git ``` You can type this command into Command Prompt, Powershell, Terminal, or any other integrated terminal of your code editor. The command also installs all the necessary dependencies you need to run Docusaurus. ### Add a GraphQL schema loader A schema loader is required to load your GraphQL schema. The template comes with `@graphql-tools/url-loader` pre-configured for remote schemas. See [schema loading](/docs/advanced/schema-loading) for other loaders and configuration options. ### Start your site Run the development server: ```shell title="shell" cd my-website npm start ``` :::tip The `npm run doc` command is a shortcut in the template for command-line document generation: `npm run docusaurus graphql-to-doc`. ::: The `npm run start` command builds your website locally and serves it through a development server, ready for you to view at [http://localhost:3000/](http://localhost:3000/). ## Existing Docusaurus site ### Prerequisites :::note These requirements are specific to Docusaurus integration. See our [Framework Integration Guide](/docs/advanced/integration-with-frameworks) for formatter-based setups and their requirements. ::: Your project needs to meet the following requirements: - Node.js version [22.12](https://nodejs.org/en/download/) or above - [Docusaurus](https://docusaurus.io/) instance version 2.0 or above with the [docs plugin](https://docusaurus.io/docs/docs-introduction) enabled - [GraphQL.js](https://graphql.org/graphql-js/) version 16.0 or above ### Install the plugin Add the `@graphql-markdown/docusaurus` plugin to your site installation: ```shell title="shell" npm install @graphql-markdown/docusaurus graphql ``` ### Add a schema loader See [schema loading](/docs/advanced/schema-loading). ### Configure the plugin See [configuration](/docs/configuration). ## Update your documentation Build your website: ```shell title="shell" npm run docusaurus build ``` Or run the documentation generator directly: ```shell title="shell" npm run docusaurus graphql-to-doc ``` The `npm run docusaurus graphql-to-doc` command generates MDX files locally from your GraphQL schema. The possible command flags are documented in [settings](/docs/settings). --- ## Try it ## Docusaurus Use the [CodeSandbox template](https://codesandbox.io/p/sandbox/github/graphql-markdown/demo-docusaurus/tree/main?file=/.graphqlrc) or fork our [demo repo](https://github.com/graphql-markdown/demo-docusaurus) to try with your own GraphQL schema. Edit the configuration in `.graphqlrc`. ## Astro/Starlight Use the [CodeSandbox template](https://codesandbox.io/p/sandbox/github/graphql-markdown/demo-astro-starlight/tree/main?file=/.graphqlrc) or fork our [demo repo](https://github.com/graphql-markdown/demo-astro-starlight) to try with your own GraphQL schema. Edit the configuration in `graphql.config.mjs`. ## Next.js/Fumadocs Use the [CodeSandbox template](https://codesandbox.io/p/sandbox/github/graphql-markdown/demo-nextjs-fumadocs/tree/main?file=/.graphqlrc) or fork our [demo repo](https://github.com/graphql-markdown/demo-nextjs-fumadocs) to try with your own GraphQL schema. Edit the configuration in `graphql.config.mjs`. ## Vite/Vocs Fork our [demo repo](https://github.com/graphql-markdown/demo-vite-vocs) to try with your own GraphQL schema. Edit the configuration in `graphql.config.mjs`. ## HonKit / GitBook legacy Fork our [demo repo](https://github.com/graphql-markdown/demo-honkit) to try with your own GraphQL schema. Edit the configuration in `graphql.config.mjs`. ## Hugo Fork our [demo repo](https://github.com/graphql-markdown/demo-hugo) to try with your own GraphQL schema. Edit the configuration in `.graphqlrc.yml`. ## MkDocs Fork our [demo repo](https://github.com/graphql-markdown/demo-mkdocs) to try with your own GraphQL schema. Edit the configuration in `scripts/generate-docs.mjs`. ## mdBook Fork our [demo repo](https://github.com/graphql-markdown/demo-mdbook) to try with your own GraphQL schema. Edit the configuration in `scripts/generate-docs.mjs`. ## DocFX Fork our [demo repo](https://github.com/graphql-markdown/demo-docfx) to try with your own GraphQL schema. Edit the configuration in `scripts/generate-docs.mjs`. --- ## How It Works GraphQL-Markdown reads your schema, parses every type and operation, and writes one MDX file per type category — ready to publish with Docusaurus or any MDX framework. ## Pipeline ![pipeline](/img/docs/pipeline.png) ### Input Given this schema: ```graphql type User { """User's unique identifier""" id: ID! """User's full name""" name: String! """List of posts authored by this user""" posts: [Post!] } type Post { id: ID! title: String! author: User! } type Query { getUser(id: ID!): User getPosts: [Post!]! } ``` ### Output GraphQL-Markdown generates a file per type category. For example, `objects/user.mdx`: ```mdx --- id: user title: User --- # User Object Type ## Fields | Name | Type | Description | | ---- | ---- | ----------- | | `id` | `ID!` | User's unique identifier | | `name` | `String!` | User's full name | | `posts` | [`[Post!]`](/docs/graphql/objects/post) | List of posts authored by this user | ## Returned by [`getUser`](/docs/graphql/queries/get-user) ``` Notice the cross-link on `Post` and the back-reference under "Returned by" — these are generated automatically from the schema graph. ## What gets generated | Output | Description | | ------ | ----------- | | `objects/` | One file per Object type | | `inputs/` | One file per Input type | | `queries/` | One file per Query field | | `mutations/` | One file per Mutation field | | `subscriptions/` | One file per Subscription field | | `enums/` | One file per Enum type | | `interfaces/` | One file per Interface type | | `unions/` | One file per Union type | | `scalars/` | One file per Scalar type | | `_category_.yml` | Sidebar metadata for each folder | ## Customization The generation pipeline exposes lifecycle hooks at every stage — before/after schema load, before/after rendering each type, before/after composing each page. See [hook recipes](/docs/advanced/hook-recipes) and [custom directives](/docs/advanced/custom-directive). To see the full output in action, browse the [live examples](/examples/default). --- ## Configuration Cheat Sheet :::note This is a quick reference guide. All settings are thoroughly documented in the [**Settings** page](/docs/settings). ::: :::tip For formatter-based setups, prefer `formatter`. The older `mdxParser` setting and CLI flag are deprecated aliases. ::: ## Essential Options | Option | Type | Default | Description | | ---------- | -------- | ---------- | --------------------------------------------------------- | | `schema` | `string` | — | **Required**. Path to schema file or introspection result | | `rootPath` | `string` | `./docs` | Root folder for documentation generation | | `baseURL` | `string` | `schema` | Base URL path and output folder name under `rootPath` | ## Document Structure | Option | Type | Default | Description | | ------------------ | ---------------------- | -------------- | ---------------------------------------------------------------- | | `linkRoot` | `string` | `/` | Root path used for type cross-links in generated documentation | | `homepage` | `string` \| `false` | `generated.md` | Custom homepage content file, `false` to disable | | `hierarchy` | `string` | `api` | Documentation structure: `api`, `entity`, or `flat` | | `index` | `boolean` | `false` | Generate category indices | | `categorySort` | `string` \| `function` | — | Sort categories: `"natural"` for alphabetical or custom function | | `sectionHeaderId` | `boolean` | `true` | Generate custom section header IDs for permalinks | | `pretty` | `boolean` | `false` | Format generated Markdown files | ## Content Options | Option | Type | Default | Description | | -------------- | --------- | ------- | ----------------------- | | `noParentType` | `boolean` | `false` | Hide parent type prefix | | `noTypeBadges` | `boolean` | `false` | Hide type badges | ## Filtering Options | Option | Type | Default | Description | | ------------------ | ---------- | --------- | ------------------------------------------------------------------ | | `groupByDirective` | `string` | — | Group by directive: `@directive(field)` or `@directive(=fallback)` | | `only` | `string[]` | — | Include only types with specified directives | | `skip` | `string[]` | — | Exclude types with specified directives | | `deprecated` | `string` | `default` | Handling of deprecated items: `default`, `group`, `skip` | ## Build Control Options | Option | Type | Default | Description | | ------------- | --------- | ------- | ----------------------------------------------------------------- | | `force` | `boolean` | `false` | Force regeneration of all files | | `diffMethod` | `string` | `NONE` | Change detection: `NONE`, `FORCE`, `SCHEMA-DIFF`, `SCHEMA-HASH` | | `tmpDir` | `string` | — | Temporary directory for storing schema signature (used by diff) | | `pretty` | `boolean` | `false` | Format output files with Prettier (requires `prettier` installed) | | `formatter` | `string` | — | Package name or path to a custom formatter module | | `outputAdapter` | `object` | fs | Write pages somewhere other than the local filesystem | ## CLI Flags All config options can be passed as CLI flags to `npx docusaurus graphql-to-doc` (Docusaurus plugin) or `npx gqlmd graphql-to-doc` (standalone CLI). | Flag | Config option | Description | | --------------------------------- | ------------------------------------- | ---------------------------------------------- | | `-s, --schema ` | `schema` | Schema file, URL, or introspection JSON | | `-b, --base ` | `baseURL` | Base URL and output folder name | | `-r, --root ` | `rootPath` | Root output folder | | `-l, --link ` | `linkRoot` | Root path for cross-links | | `-h, --homepage ` | `homepage` | Custom homepage file | | `-f, --force` | `force` | Skip diff, always regenerate | | `-d, --diff ` | `diffMethod` | Diff method (`NONE`, `SCHEMA-DIFF`, etc.) | | `-t, --tmp ` | `tmpDir` | Temp dir for schema diffing | | `--index` | `docOptions.index` | Generate category index pages | | `--hierarchy ` | `printTypeOptions.hierarchy` | Folder structure: `api`, `entity`, `flat` | | `--deprecated