生成 GraphQL 参考文档

Pre-release
以 Markdown 格式查看
GraphQL API 参考文档没有积极维护。如果您有疑问,请联系我们

Fern 从 GraphQL schema 生成 API 参考文档。将您的 schema 文件添加到 Fern 项目中,Fern 会将查询、变更、订阅和类型渲染为交互式参考文档。

配置

1

设置项目结构

将您的 GraphQL schema 文件添加到 /fern 目录并创建引用它的 generators.yml

generators.yml
1api:
2 specs:
3 - graphql: plants.schema.graphql
4 name: Plants
5 origin: https://api.example.com/plants/graphql
2

将 GraphQL 参考文档添加到导航

docs.yml 的导航中添加 - api: API Reference

docs.yml
1navigation:
2 - api: API Reference
3

自定义布局

有关配置选项和布局自定义的完整列表,请参阅自定义 API 参考文档布局

包含多个 GraphQL 参考文档

要在文档中包含多个 GraphQL 定义,请使用 api-name 属性。api-name 对应包含您 GraphQL schema 的文件夹名称。

fern
fern.config.json
docs.yml
plant-graphql
schema.graphql# Plant GraphQL schema
generators.yml
garden-graphql
schema.graphql# Garden GraphQL schema
generators.yml
docs.yml
1navigation:
2 - api: Plant GraphQL API
3 api-name: plant-graphql
4 - api: Garden GraphQL API
5 api-name: garden-graphql

配置属性

api.specs[].graphql
Required

您的 GraphQL schema 文件路径。如果您的项目暴露多个 GraphQL API,您可以包含多个 GraphQL 规范。

api.specs[].name

此规范的操作在 API 参考文档侧边栏中显示的文件夹名称。使用此属性将相关的 GraphQL 操作分组在一起。

api.specs[].origin

您的 GraphQL API 端点 URL。Fern 对此端点执行内省以获取 schema。设置后,运行 fern api update 会从此端点更新本地 schema。