UNPKG

@graphql-markdown/core

Version:

GraphQL-Markdown core package for generating Markdown documentation from a GraphQL schema.

94 lines (93 loc) 3.19 kB
/** * GraphQL Markdown configuration utilities * * This module provides utilities for loading and processing GraphQL configuration * using the graphql-config package. * * @module graphql-config */ import type { ExtensionProjectConfig, GraphQLExtensionDeclaration, LoaderOption, Maybe, PackageOptionsConfig } from "@graphql-markdown/types"; /** * The name of the GraphQL Markdown extension. * Used to identify the extension in graphql-config. */ export declare const EXTENSION_NAME: "graphql-markdown"; /** * GraphQL extension declaration for graphql-config. * * @returns The extension configuration object with name property. * * @example * ```typescript * // In graphql-config setup * const config = await loadConfig({ * extensions: [graphQLConfigExtension], * }); * ``` */ export declare const graphQLConfigExtension: GraphQLExtensionDeclaration; /** * Options for controlling throw behavior when loading configuration. * * @interface ThrowOptions * @property throwOnMissing Whether to throw when the config file is missing. * @property throwOnEmpty Whether to throw when the config is empty. */ interface ThrowOptions { throwOnMissing?: boolean; throwOnEmpty?: boolean; } /** * Sets loader options for GraphQL Markdown loaders. * * This function takes a LoaderOption object and merges the provided options * with any existing options for each loader. * * @param loaders - The loader configuration object. * @param options - The package options to apply to loaders. * @returns The updated loader configuration. * * @example * ```typescript * const loaders = { * TypeScriptLoader: { * module: "@graphql-markdown/typescript-loader", * options: { baseDir: "./src" } * } * }; * const options = { outputDir: "./docs" }; * const updatedLoaders = setLoaderOptions(loaders, options); * // Result: loaders with { baseDir: "./src", outputDir: "./docs" } * ``` */ export declare const setLoaderOptions: (loaders: LoaderOption, options: PackageOptionsConfig) => LoaderOption; /** * Loads the GraphQL Markdown configuration from graphql-config. * * This function attempts to load the GraphQL config and extract the * GraphQL Markdown extension configuration for the specified project ID. * It also normalizes schema configurations. * * @param id - The project ID to load configuration for. * @param options - Optional package options to apply. * @param throwOptions - Options for controlling throw behavior. * @returns The extension project configuration if found, otherwise undefined. * * @throws Will throw an error if throwOnMissing or throwOnEmpty is true and * the corresponding condition is met. * * @example * ```typescript * // Basic usage * const config = await loadConfiguration("my-project"); * * // With options and throw behavior * const config = await loadConfiguration( * "my-project", * { baseDir: "./src" }, * { throwOnMissing: true, throwOnEmpty: false } * ); * ``` */ export declare const loadConfiguration: (id: Maybe<string>, options?: Maybe<PackageOptionsConfig>, { throwOnMissing, throwOnEmpty }?: ThrowOptions) => Promise<Maybe<Readonly<ExtensionProjectConfig>>>; export {};