@fumadocs/graphql

中文文档
0.5.1发布于 2026/11/14MITES Module构建来源已验证近 30 天下载 1.2万

Generate docs for your GraphQL schema

原始使用文档
文档目录5 节
  1. Quick Start
  2. Options
  3. Inputs
  4. Page Presets
  5. UI

Fumadocs GraphQL

Generate API reference docs from GraphQL schemas for Fumadocs, with an interactive playground.

npm i @fumadocs/graphql graphql

graphql is a peer dependency.

Quick Start

Create the server instance from your schema:

// lib/graphql.ts
import { createGraphQL } from '@fumadocs/graphql/server';

export const graphql = createGraphQL({
  input: ['./schema.graphql'],
});

Add the generated pages to your source:

// lib/source.ts
import { loader } from 'fumadocs-core/source';
import { defineDocs } from 'fumadocs-mdx/macro';
import { graphql } from './graphql';

const docs = defineDocs({
  dir: 'content/docs',
});

export const source = loader(
  {
    docs: docs.toFumadocsSource(),
    graphql: await graphql.staticSource({
      // a route group, generated pages won't have a `/graphql` prefix in their URLs
      baseDir: '(graphql)',
      meta: true,
    }),
  },
  {
    baseUrl: '/docs',
    plugins: [graphql.loaderPlugin()],
  },
);

Render them from a client component:

// components/api-page.tsx
'use client';
import { createGraphQLPage } from '@fumadocs/graphql/ui';

export const GraphQLPage = createGraphQLPage({
  playground: {
    url: '/api/graphql',
  },
});
// app/docs/[[...slug]]/page.tsx
if (page.type === 'graphql') {
  return (
    <DocsPage toc={page.data.toc} full>
      <DocsTitle>{page.data.title}</DocsTitle>
      <DocsDescription>{page.data.description}</DocsDescription>
      <DocsBody>
        <GraphQLPage {...page.data.getGraphQLPageProps()} />
      </DocsBody>
    </DocsPage>
  );
}

And import the styles in your global CSS:

@import '@fumadocs/graphql/css/preset.css';

Options

Inputs

input accepts an array of file paths/URLs to SDL files, or a record of schema id to input:

  • SDL file paths/URLs, or SDL text (including extend type definitions).
  • Introspection results (JSON).
  • GraphQLSchema instances.

Page Presets

Pass options to staticSource() to control the generated pages:

  • per: 'item' (default): a page per operation/named type, use groupBy ('kind' | 'none' or a function) to group them into folders, and includeOperations/includeTypes to filter items.
  • per: 'file': a single page per schema.
  • per: 'custom': bring your own pages builder.

UI

createGraphQLPage() accepts:

  • Cross-links of type & operation references are pre-generated when you pass baseUrl (the baseUrl of your loader()) to staticSource(); override them with the typeLinks/operationLinks callbacks if needed.
  • playground: interactive playground shown on operation pages — url (GraphQL endpoint, operations are sent over HTTP POST), fetcher (replace the default fetcher, e.g. to proxy requests), or render (replace the playground UI).
  • shikiOptions, components, and content/schemaUI render slots for deeper customisation.

See Fumadocs docs for more.

版本与发布记录

@fumadocs/graphql 共发布 23 个版本,首次发布于 2026/08/04;过去 12 个月发布了 23 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.5.1latest2026/11/142 天前
0.5.02026/11/0510 天前
0.4.22026/10/2323 天前
0.4.12026/10/2026 天前
0.4.02026/10/1927 天前
0.3.52026/10/1630 天前

其他发布通道:temp → 0.0.0-tegami-trusted-publish-setup。

关于 @fumadocs/graphql 的常见问题

@fumadocs/graphql 是什么?

Generate docs for your GraphQL schema

如何安装 @fumadocs/graphql?

在项目目录运行 npm install @fumadocs/graphql,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^19.2.0)、graphql(^17.0.0)、react-dom(^19.2.0)、fumadocs-ui(^16.17.8)、fumadocs-core(^16.17.11)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@fumadocs/graphql 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/fumadocs__graphql 是否存在。

@fumadocs/graphql 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@fumadocs/graphql 可以商用吗?

@fumadocs/graphql 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fumadocs/graphql 的下载量有多少?

根据 npm 官方下载统计,@fumadocs/graphql 在 2026/10/16 – 2026/11/14 这 30 天内被下载 12,307 次,日均约 410 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fumadocs/graphql 还在维护吗?

最新版本 0.5.1 发布于 2026/11/14(2 天前);至今共发布 23 个版本,其中过去 12 个月发布了 23 个;首次发布于 2026/08/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。