The graphql subject handles GitHub's GraphQL API documentation, including schema synchronization, data generation, and documentation rendering. It fetches schema data from GitHub's GraphQL API and generates version-specific JSON files used to render the docs.
This subject is responsible for:
- Syncing GraphQL schema from GitHub's API
- Generating version-specific schema JSON files
- Managing GraphQL previews, upcoming changes, and changelog
- Middleware that injects GraphQL data into page context
- Rendering GraphQL reference documentation
- Validating GraphQL schema data structure
- Schema synchronization -
scripts/sync.tsfetches schema from GitHub's GraphQL API - Data generation - Generates version-specific JSON files in
data/VERSION/directories (e.g.,data/ghec/schema.json) - Validation -
lib/validator.tsvalidates schema structure - Data loading -
lib/index.tsprovides functions to load GraphQL data in Next.js pages - Content rendering - Markdown files in
content/graphql/use Liquid to render documentation
Run the sync script to fetch latest schema:
npm run sync-graphqlThis:
- Fetches schema from GitHub's GraphQL API for each version
- Generates
data/VERSION/schema.jsonfiles (e.g.,data/ghec/schema.json) - Builds
data/previews.json,data/upcoming-changes.json,data/changelog.json
npm run test -- src/graphql/tests- GraphQL data is loaded directly in Next.js pages using
getServerSideProps - Functions from
lib/index.tslikegetGraphqlSchema()provide the data - Data includes:
- Schema for current version
- Previews for current version
- Upcoming changes for current version
- Changelog
- Markdown files in
content/graphql/use Liquid to loop over this data - Liquid calls HTML includes in
includes/for rendering
- GitHub GraphQL API - Schema introspection queries
lib/non-schema-scalars.json- Custom scalar types from graphql-rubylib/types.json- High-level GraphQL types and kindslib/validator.json- JSON schema for validation
- GitHub GraphQL API access
graphql-rubylibrary scalars- JSON schema validator (AJV)
@/versions- Version mapping for schema files
data/schema-VERSION.json- One file per version (ghec, ghes-3.11, etc.)data/previews.json- Preview features across versionsdata/upcoming-changes.json- Upcoming breaking changesdata/changelog.json- GraphQL API changelog entries
All files in data/ are generated and should not be manually edited:
- ✅ Edit:
lib/*.json,scripts/*.ts - ❌ Don't edit:
data/*.json(regenerate with sync script)
src/rest- Similar pattern for REST API docssrc/webhooks- Similar pattern for webhooks docssrc/content-render- Liquid rendering of GraphQL data- Content files in
content/graphql/- GraphQL documentation pages
- GitHub GraphQL API: https://docs.github.com/graphql
- graphql-ruby scalars: https://github.com/rmosolgo/graphql-ruby
Human-editable configuration:
lib/validator.ts- TypeScript file for validating schema intests/graphql.tslib/non-schema-scalars.json- Scalar types from graphql-ruby (not in core spec)lib/types.json- High-level GraphQL types and kinds
Schema files generated per version:
data/ghec/schema.json- GitHub Enterprise Clouddata/ghes-3.11/schema.json,data/ghes-3.10/schema.json, etc. - GHES versions- Older versions may be archived
Writers can add content to Markdown files in content/graphql/ alongside Liquid:
- Note that Markdown files exist for every URL in GraphQL docs
- Liquid loops over
context.graphql.*properties - Most rendering happens in
includes/HTML files
- Schema sync requires API access
- Generated files can be large (100KB+ per version)
- Changes to upstream schema require re-sync
- Validation schema must be kept in sync with expected structure
Automated sync (if configured):
- Scheduled workflow checks for schema updates
- Creates PR if changes detected
- Manual sync:
npm run sync-graphql
When a new GHES version releases:
- Update version list in sync script
- Run
npm run sync-graphql - Commit new
data/ghes-X.XX/schema.jsonfile - Update content if needed
Sync fails:
- Check API access and authentication
- Verify version mappings are correct
- Check for schema validation errors
Schema not loading:
- Verify
data/VERSION/schema.jsonexists (e.g.,data/ghec/schema.json) - Verify version detection logic
Content not rendering:
- Check Liquid syntax in
content/graphql/ - Verify context properties are available
- Check includes in
includes/directory