import { GraphQLSchema , DocumentNode } from 'graphql' ; import { Source } from '@graphql-tools/utils' ; export namespace Types { export interface GenerateOptions { filename : string ; plugins : Types . ConfiguredPlugin [ ] ; schema : DocumentNode ; schemaAst ? : GraphQLSchema ; documents : Types . DocumentFile [ ] ; config : { [ key ] : any ; } ; pluginMap : { [ name ] : CodegenPlugin ; } ; skipDocumentsValidation ? : Types . SkipDocumentsValidationOptions ; pluginContext ? : { [ key ] : any ; } ; } export type FileOutput = { filename : string ; content : string ; hooks ? : { beforeOneFileWrite ? : LifecycleHooksDefinition [ 'beforeOneFileWrite' ] ; afterOneFileWrite ? : LifecycleHooksDefinition [ 'afterOneFileWrite' ] ; } ; } ; export type DocumentFile = Source ; export type Promisable < T > = T | Promise < T > ; export type InstanceOrArray < T > = T | T [ ] ; additionalProperties description export interface SchemaWithLoaderOptions { description loader : string ; } export interface SchemaWithLoader { [ pointer ] : SchemaWithLoaderOptions ; } additionalProperties description export interface SchemaFromCodeFileOptions { description noRequire ? : boolean ; description noPluck ? : boolean ; description assumeValid ? : boolean ; } export interface SchemaFromCodeFile { [ path ] : SchemaFromCodeFileOptions ; } additionalProperties description export interface UrlSchemaOptions { description headers ? : { [ headerName ] : string ; } ; description customFetch ? : string ; description method ? : string ; } export interface UrlSchemaWithOptions { [ url ] : UrlSchemaOptions ; } additionalProperties description export interface LocalSchemaPathOptions { description default skipGraphQLImport ? : boolean ; description default commentDescriptions ? : boolean ; default assumeValidSDL ? : boolean ; default noLocation ? : boolean ; default allowLegacySDLEmptyFields ? : boolean ; default allowLegacySDLImplementsInterfaces ? : boolean ; default experimentalFragmentVariables ? : boolean ; } export interface LocalSchemaPathWithOptions { [ globPath ] : LocalSchemaPathOptions ; } export type SchemaGlobPath = string ; description export type Schema = string | UrlSchemaWithOptions | LocalSchemaPathWithOptions | SchemaGlobPath | SchemaWithLoader | SchemaFromCodeFile ; export type OperationDocumentGlobPath = string ; additionalProperties description export interface CustomDocumentLoaderOptions { description loader : string ; } export interface CustomDocumentLoader { [ path ] : CustomDocumentLoaderOptions ; } export type OperationDocument = OperationDocumentGlobPath | CustomDocumentLoader ; export type PluginConfig < T = any > = { [ key ] : T ; } ; export interface ConfiguredPlugin { [ name ] : PluginConfig ; } export type NamedPlugin = string ; export type NamedPreset = string ; export type OutputConfig = NamedPlugin | ConfiguredPlugin ; additionalProperties export interface ConfiguredOutput { type array items description plugins : OutputConfig [ ] ; description preset ? : string | OutputPreset ; description presetConfig ? : { [ key ] : any ; } ; description overwrite ? : boolean ; description documents ? : InstanceOrArray < OperationDocument > ; description schema ? : InstanceOrArray < Schema > ; description config ? : PluginConfig ; description hooks ? : Partial < LifecycleHooksDefinition > ; } export type PresetFnArgs < Config = any , PluginConfig = { [ key ] : any ; } > = { presetConfig : Config ; baseOutputDir : string ; plugins : Types . ConfiguredPlugin [ ] ; schema : DocumentNode ; schemaAst ? : GraphQLSchema ; documents : Types . DocumentFile [ ] ; config : PluginConfig ; pluginMap : { [ name ] : CodegenPlugin ; } ; pluginContext ? : { [ name ] : any ; } ; } ; export type OutputPreset < TPresetConfig = any > = { buildGeneratesSection : ( options : PresetFnArgs < TPresetConfig > ) => Promisable < GenerateOptions [ ] > ; } ; export type RequireExtension = InstanceOrArray < string > ; export type PackageLoaderFn < TExpectedResult > = ( name : string ) => Promisable < TExpectedResult > ; description additionalProperties export interface Config { description schema ? : InstanceOrArray < Schema > ; description require ? : RequireExtension ; description customFetch ? : string ; description documents ? : InstanceOrArray < OperationDocument > ; type object additionalProperties description config ? : PluginConfig ; description generates : { [ outputPath ] : ConfiguredOutput | ConfiguredPlugin [ ] ; } ; description overwrite ? : boolean ; description watch ? : boolean | string | string [ ] ; description watchConfig ? : { usePolling : boolean ; interval ? : number ; } ; description silent ? : boolean ; description errorsOnly ? : boolean ; description pluginLoader ? : PackageLoaderFn < CodegenPlugin > ; description pluginContext ? : { [ key ] : any ; } ; description pluckConfig ? : { description modules ? : Array < { description name : string ; description identifier ? : string ; } > ; description magicComment ? : string ; description globalIdentifier ? : string ; } ; description hooks ? : Partial < LifecycleHooksDefinition > ; } export type ComplexPluginOutput = { content : string ; prepend ? : string [ ] ; append ? : string [ ] ; } ; export type PluginOutput = string | ComplexPluginOutput ; export type HookFunction = ( ... args : any [ ] ) => void | Promise < void > ; description additionalProperties export type LifecycleHooksDefinition < T = string | HookFunction | ( string | HookFunction ) [ ] > = { description afterStart : T ; description beforeDone : T ; description onWatchTriggered : T ; description onError : T ; description afterOneFileWrite : T ; description afterAllFileWrite : T ; description beforeOneFileWrite : T ; description beforeAllFileWrite : T ; } ; export type SkipDocumentsValidationOptions = { description ignoreRules ? : string [ ] ; description skipDuplicateValidation ? : boolean ; description skipValidationAgainstSchema ? : boolean ; } | boolean ; } export function isComplexPluginOutput ( obj ) { return typeof obj === 'object' && obj . hasOwnProperty ( 'content' ) ; } export type PluginFunction < T = any , TOutput extends Types . PluginOutput = Types . PluginOutput > = ( schema : GraphQLSchema , documents : Types . DocumentFile [ ] , config : T , info ? : { outputFile ? : string ; allPlugins ? : Types . ConfiguredPlugin [ ] ; pluginContext ? : { [ key ] : any ; } ; [ key ] : any ; } ) => Types . Promisable < TOutput > ; export type PluginValidateFn < T = any > = ( schema : GraphQLSchema , documents : Types . DocumentFile [ ] , config : T , outputFile : string , allPlugins : Types . ConfiguredPlugin [ ] , pluginContext ? : { [ key ] : any ; } ) => Types . Promisable < void > ; export type AddToSchemaResult = string | DocumentNode | undefined ; export interface CodegenPlugin < T = any > { plugin : PluginFunction < T > ; addToSchema ? : AddToSchemaResult | ( ( config : T ) => AddToSchemaResult ) ; validate ? : PluginValidateFn ; }