UNPKG

ponder-enrich-gql-docs-middleware

Version:

A middleware for Ponder that allows devs to enrich their GraphQL docs with docstrings

46 lines (45 loc) 1.54 kB
import type { DocStrings } from "./types"; /** * Options for configuring the documentation middleware. */ export interface MiddlewareOptions { /** Enable debug logging */ debug?: boolean; /** GraphQL endpoint path */ path?: string; } /** * Context object passed to the middleware function. */ export interface MiddlewareContext { req: { raw: Request; }; res: Response; } /** * Creates a middleware function that enhances GraphQL introspection queries with documentation. * * This middleware intercepts GraphQL introspection queries and adds documentation strings * to the schema before returning it to the client. It's particularly useful for adding * detailed documentation to your GraphQL API that will show up in tools like GraphiQL. * * @param docs - Documentation strings to add to the schema * @param options - Configuration options for the middleware * @returns A middleware function to use in your GraphQL server * * @example * ```typescript * import { createDocumentationMiddleware } from '@your-lib/graphql-docs'; * import { ponder } from 'ponder:registry'; * * const docs = { * User: "Represents a user in the system", * "User.balance": "The user's balance" * }; * * const middleware = createDocumentationMiddleware(docs, { debug: true }); * ponder.use('/graphql', middleware); * ``` */ export declare function createDocumentationMiddleware(docs: DocStrings, options?: MiddlewareOptions): (context: MiddlewareContext, next: () => Promise<void>) => Promise<void>;