UNPKG

graphql-codegen-core

Version:

GraphQL types and code generator based on schema

79 lines (78 loc) 2.68 kB
import { GraphQLSchema, DocumentNode } from 'graphql'; import { DocumentFile } from './types'; export declare namespace Types { type InstanceOrArray<T> = T | T[]; type SchemaWithLoader = { [schemaString: string]: { loader: string; }; }; type UrlSchema = string | { [url: string]: { headers?: { [headerName: string]: string; }; }; }; type LocalSchemaPath = string; type SchemaGlobPath = string; type Schema = UrlSchema | LocalSchemaPath | SchemaGlobPath | SchemaWithLoader; type OperationDocumentGlobPath = string; type CustomDocumentLoader = { [path: string]: { loader: string; }; }; type OperationDocument = OperationDocumentGlobPath | CustomDocumentLoader; type PluginConfig = InstanceOrArray<string> | { [key: string]: any; }; type ConfiguredPlugin = { [name: string]: PluginConfig; }; type NamedPlugin = string; type OutputConfig = InstanceOrArray<NamedPlugin | ConfiguredPlugin>; type ConfiguredOutput = { overwrite?: boolean; documents?: InstanceOrArray<OperationDocument>; schema?: InstanceOrArray<Schema>; plugins: OutputConfig; config?: { [key: string]: any; }; }; type RequireExtension = InstanceOrArray<string>; type PluginLoaderFn = (pluginName: string) => CodegenPlugin | Promise<CodegenPlugin>; interface Config { schema?: InstanceOrArray<Schema>; require?: RequireExtension; documents?: InstanceOrArray<OperationDocument>; config?: { [key: string]: any; }; generates: { [filename: string]: OutputConfig | ConfiguredOutput; }; overwrite?: boolean; watch?: boolean | string | string[]; silent?: boolean; pluginLoader?: PluginLoaderFn; pluckConfig?: { modules?: Array<{ name: string; identifier?: string; }>; magicComment?: string; globalIdentifier?: string; }; } } export declare type PluginFunction<T = any> = (schema: GraphQLSchema, documents: DocumentFile[], config: T, info: { outputFile: string; }) => Promise<string> | string; export declare type PluginValidateFn<T = any> = (schema: GraphQLSchema, documents: DocumentFile[], config: T, outputFile: string, allPlugins: Types.ConfiguredPlugin[]) => Promise<void> | void; export interface CodegenPlugin<T = any> { plugin: PluginFunction<T>; addToSchema?: string | DocumentNode; validate?: PluginValidateFn; }