This guide explains how to automatically generate GraphQL documentation from the schema.
SpectaQL is already installed as a development dependency. If not:
cd backend
pnpm add -D spectaqlThe SpectaQL configuration is located in backend/spectaql.config.yml.
- schema.file: Path to the GraphQL schema file (
src/graphql/schema.gql) - targetDir: Output directory for documentation (
docs/graphql) - baseUrl: Base URL of the API (default:
http://localhost:4000) - title: Documentation title
- description: API description
cd backend
pnpm docs:generateThis command:
- Reads the GraphQL schema from
src/graphql/schema.gql - Generates HTML documentation in
docs/graphql/ - Creates an
index.htmlfile that you can open in a browser
cd backend
pnpm docs:watchThis command watches for schema changes and automatically regenerates the documentation.
Once generated, open the file:
docs/graphql/index.html
In your browser, or serve it with a local HTTP server:
# With Python
cd docs/graphql
python3 -m http.server 8000
# With Node.js (http-server)
npx http-server docs/graphql -p 8000Then access http://localhost:8000
The GraphQL schema is automatically generated by NestJS when the application starts. To generate documentation after each build:
- Add to your CI/CD:
- name: Generate GraphQL Documentation
run: |
cd backend
pnpm docs:generate- Or create a build script that includes generation:
{
"scripts": {
"build:docs": "pnpm build && pnpm docs:generate"
}
}The GraphQL schema (src/graphql/schema.gql) is automatically generated by NestJS from your resolvers and entities. It updates:
- When starting the application in development mode
- When running
pnpm start:dev
To force regeneration:
cd backend
pnpm start:dev
# The schema will be regenerated, then:
pnpm docs:generateEdit backend/spectaql.config.yml to customize:
title: Documentation titledescription: API descriptionintroText: Introduction text (Markdown supported)footerText: Footer textlogoFile: Path to a logo filefaviconFile: Path to a favicon file
In spectaql.config.yml, you can hide/show different sections:
hideSearch: Hide search barhideSchema: Hide complete schemahideExamples: Hide exampleshideDeprecated: Hide deprecated elementshideInternal: Hide internal elements
schema:
file: ./src/graphql/schema.gql
targetDir: ./docs/graphql
baseUrl: https://api.epitrello.com
title: Epitrello API - Complete Documentation
description: GraphQL API for Trello-like project management
introText: |
# Welcome to Epitrello Documentation
This API allows you to manage boards, lists, cards, and workspaces.
logoFile: ./assets/logo.png
hideDeprecated: true
hideInternal: trueMake sure the GraphQL schema exists:
cd backend
ls -la src/graphql/schema.gqlIf the file doesn't exist, start the application once to generate it:
pnpm start:dev
# Wait for the application to start, then stop it (Ctrl+C)If the documentation doesn't reflect recent changes:
-
Check that the schema is up to date:
cd backend pnpm start:dev -
Regenerate the documentation:
pnpm docs:generate
If you have path errors, use absolute paths or make sure you're running the command from the correct directory (backend/).