Ponder GraphQL Docstring Enrichment Middleware
raw JSON →This package, `ponder-enrich-gql-docs-middleware`, provides a middleware for Ponder-based GraphQL APIs, enabling developers to augment their GraphQL documentation with detailed docstrings for types, fields, and queries. Currently at version `0.1.3`, it is in active development with a consistent release of minor versions, indicating potential breaking changes between `0.x.x` releases as it approaches a stable 1.0. Its core value lies in enhancing API discoverability and usability by enriching introspection query results with human-readable descriptions, without modifying the underlying GraphQL schema or affecting runtime performance. Key differentiators include its seamless integration into the Ponder ecosystem, comprehensive TypeScript support, zero runtime overhead due to its introspection-only processing, and a suite of helper functions for automatically generating common documentation patterns like pagination and filtering, significantly reducing manual documentation effort.
Common errors
error TypeError: Cannot read properties of undefined (reading 'use') ↓
import { ponder } from "ponder:registry"; is present and ponder is correctly configured and available before calling ponder.use(). error Error: Cannot find module 'ponder:registry' ↓
ponder.config.ts is valid and the ponder CLI has been run to generate necessary files. This often happens if Ponder is not running or misconfigured, or if your build system doesn't support Ponder's virtual modules. error Error: GraphQL Schema validation error: Unknown type "MyCustomType" (or similar 'field not found' errors) ↓
docs object passed to createDocumentationMiddleware and ensure all type and field names (e.g., "User", "User.email") precisely match the definitions within your schema.graphql and the schema Ponder generates at runtime. Warnings
breaking As a 0.x.x package, `ponder-enrich-gql-docs-middleware` may introduce breaking changes in minor versions (e.g., 0.1.x to 0.2.x) without prior major version increments. Users should pin exact versions or review changelogs carefully during upgrades. ↓
gotcha Incorrect versions of `graphql` or `hono` (peer dependencies) can lead to runtime errors or unexpected behavior due to API mismatches. Ensure your project's installed versions satisfy the specified peer dependency ranges. ↓
gotcha This middleware exclusively modifies the documentation returned by introspection queries; it does not alter your `schema.graphql` file or affect the runtime behavior of your GraphQL API. Applications relying on runtime schema modifications or code generation from a modified schema will not see these documentation changes. ↓
Install
npm install ponder-enrich-gql-docs-middleware yarn add ponder-enrich-gql-docs-middleware pnpm add ponder-enrich-gql-docs-middleware Imports
- createDocumentationMiddleware wrong
const { createDocumentationMiddleware } = require('ponder-enrich-gql-docs-middleware');correctimport { createDocumentationMiddleware } from 'ponder-enrich-gql-docs-middleware'; - extendWithBaseDefinitions wrong
import extendWithBaseDefinitions from 'ponder-enrich-gql-docs-middleware/extendWithBaseDefinitions';correctimport { extendWithBaseDefinitions } from 'ponder-enrich-gql-docs-middleware'; - generatePageDocs wrong
import * as docHelpers from 'ponder-enrich-gql-docs-middleware'; docHelpers.generatePageDocs();correctimport { generatePageDocs } from 'ponder-enrich-gql-docs-middleware'; - generateFilterDocs
import { generateFilterDocs } from 'ponder-enrich-gql-docs-middleware';
Quickstart
import {
createDocumentationMiddleware,
extendWithBaseDefinitions,
generatePageDocs
} from "ponder-enrich-gql-docs-middleware";
import { ponder } from "ponder:registry";
import { graphql } from "ponder";
// Define your documentation object with base definitions and generated pagination docs
const docs = extendWithBaseDefinitions({
// Define specific type and field descriptions
User: "Represents a user in the system",
"User.email": "The user's email address",
"User.name": "The user's full name",
// Dynamically generate documentation for pagination on the 'User' type
...generatePageDocs("User", "user"),
});
// Initialize the documentation middleware with the defined documentation
const docMiddleware = createDocumentationMiddleware(docs, { debug: false });
// Apply the documentation middleware and then the Ponder GraphQL handler to your /graphql endpoint
// The order is important: middleware first, then the actual GraphQL handler
ponder.use("/graphql", docMiddleware);
ponder.use("/graphql", graphql());
console.log('Ponder GraphQL endpoint enriched with documentation middleware.');