@graphql-markdown/core
Version:
GraphQL-Markdown core package for generating Markdown documentation from a GraphQL schema.
104 lines • 5.53 kB
TypeScript
/**
* Core generator functionality for GraphQL Markdown documentation.
*
* This module contains the main functionality for generating markdown documentation
* from GraphQL schemas. It handles schema loading, processing, and markdown generation
* through appropriate printers and renderers.
*
* @packageDocumentation
*/
import type { DirectiveName, Formatter, GeneratorOptions, GraphQLDirective, GraphQLSchema, LoaderOption, Maybe, MetaInfo, PackageName, TypeDiffMethod } from "@graphql-markdown/types";
/**
* Asynchronously loads an MDX module dynamically.
*
* @param mdxParser - The MDX parser package name or path to import. Can be null or undefined.
* @returns A promise that resolves to the imported module, or undefined if:
* - The mdxParser parameter is null or undefined
* - An error occurs during import (logs a warning and returns undefined)
*
* @internal
*/
export declare const loadMDXModule: (mdxParser: Maybe<PackageName | string>) => Promise<unknown>;
/**
* Gets a property from an MDX module, checking both the module directly and `module.default`.
*
* This handles the differences between ESM and CommonJS module exports when dynamically importing.
*
* @param mdxModule - The loaded MDX module
* @param propertyName - The name of the property to extract
* @returns The property value if found, otherwise undefined
*
* @internal
*/
export declare const getMDXModuleProperty: <T>(mdxModule: unknown, propertyName: string) => T | undefined;
/**
* Extracts a formatter from an MDX module.
*
* Checks for formatter functions in the following order:
* 1. A `createMDXFormatter` factory function (for internal/advanced usage)
* 2. Individual exported formatter functions (e.g., `formatMDXBadge`, `formatMDXAdmonition`)
*
* @param mdxModule - The loaded MDX module that may contain formatter exports
* @param meta - Optional metadata to pass to the formatter factory
* @returns A partial Formatter with the found functions, or undefined if none found
*
* @internal
*/
export declare const getFormatterFromMDXModule: (mdxModule: unknown, meta?: MetaInfo) => Partial<Formatter> | undefined;
/**
* Loads a GraphQL schema from the specified location using configured document loaders.
*
* @param schemaLocation - The location/path of the GraphQL schema to load (e.g., file path, URL, or glob pattern).
* @param loadersList - Optional loader configuration for customizing how the schema is loaded.
*
* @returns A promise that resolves to the loaded GraphQL schema, or undefined if:
* - The loaders cannot be initialized
* - An error occurs during schema loading
*
* @internal
*/
export declare const loadGraphqlSchema: (schemaLocation: string, loadersList: Maybe<LoaderOption>) => Promise<Maybe<GraphQLSchema>>;
/**
* Checks if there are differences in the GraphQL schema compared to a previous version.
*
* @param schema - The GraphQL schema to check for differences.
* @param schemaLocation - The location/path of the schema file for logging purposes.
* @param diffMethod - The method to use for detecting differences. If set to `NONE`, changes detection is skipped.
* @param tmpDir - The temporary directory path used for storing and comparing schema versions.
*
* @returns A promise that resolves to `true` if changes are detected or if diff method is `NONE`,
* or `false` if no changes are detected.
*
* @remarks
* When no changes are detected, a log message is generated indicating that the schema is unchanged.
*/
export declare const checkSchemaDifferences: (schema: GraphQLSchema, schemaLocation: string, diffMethod: Maybe<TypeDiffMethod>, tmpDir: string) => Promise<boolean>;
/**
* Resolves and retrieves GraphQL directive objects from the schema based on their names.
*
* Takes two lists of directive names (for "only" and "skip" documentation directives),
* looks them up in the provided GraphQL schema, and returns the resolved directive objects.
*
* @param onlyDocDirective - A directive name or array of directive names for "only" documentation filtering
* @param skipDocDirective - A directive name or array of directive names for "skip" documentation filtering
* @param schema - The GraphQL schema to resolve directives from
*
* @returns A tuple containing two arrays: the first with resolved "only" directives,
* the second with resolved "skip" directives. Only defined directives are included.
*/
export declare const resolveSkipAndOnlyDirectives: (onlyDocDirective: Maybe<DirectiveName | DirectiveName[]>, skipDocDirective: Maybe<DirectiveName | DirectiveName[]>, schema: GraphQLSchema) => GraphQLDirective[][];
/**
* Main entry point for generating Markdown documentation from a GraphQL schema.
*
* This function coordinates the entire documentation generation process:
* - Loads and validates the schema
* - Checks for schema changes if diffing is enabled
* - Processes directives and groups
* - Initializes printers and renderers
* - Generates markdown files
*
* @param options - Complete configuration for the documentation generation
* @returns Promise that resolves when documentation is fully generated
*/
export declare const generateDocFromSchema: ({ baseURL, customDirective, diffMethod, docOptions, force, groupByDirective, homepageLocation, linkRoot, loaders: loadersList, loggerModule, formatter, metatags, onlyDocDirective, outputDir, prettify, printTypeOptions, schemaLocation, skipDocDirective, tmpDir, }: GeneratorOptions) => Promise<void>;
//# sourceMappingURL=generator.d.ts.map