UNPKG

2.38 kBTypeScriptView Raw
1import { GraphQLSchema, DocumentNode } from 'graphql';
2import { DocumentFile } from './types';
3export declare namespace Types {
4 type InstanceOrArray<T> = T | T[];
5 type SchemaWithLoader = {
6 [schemaString: string]: {
7 loader: string;
8 };
9 };
10 type UrlSchema = string | {
11 [url: string]: {
12 headers?: {
13 [headerName: string]: string;
14 };
15 };
16 };
17 type LocalSchemaPath = string;
18 type SchemaGlobPath = string;
19 type Schema = UrlSchema | LocalSchemaPath | SchemaGlobPath | SchemaWithLoader;
20 type OperationDocumentGlobPath = string;
21 type CustomDocumentLoader = {
22 [path: string]: {
23 loader: string;
24 };
25 };
26 type OperationDocument = OperationDocumentGlobPath | CustomDocumentLoader;
27 type PluginConfig = InstanceOrArray<string> | {
28 [key: string]: any;
29 };
30 type ConfiguredPlugin = {
31 [name: string]: PluginConfig;
32 };
33 type NamedPlugin = string;
34 type OutputConfig = InstanceOrArray<NamedPlugin | ConfiguredPlugin>;
35 type ConfiguredOutput = {
36 documents?: InstanceOrArray<OperationDocument>;
37 schema?: InstanceOrArray<Schema>;
38 plugins: OutputConfig;
39 config?: {
40 [key: string]: any;
41 };
42 };
43 type RequireExtension = InstanceOrArray<string>;
44 type PluginLoaderFn = (pluginName: string) => CodegenPlugin | Promise<CodegenPlugin>;
45 interface Config {
46 schema?: InstanceOrArray<Schema>;
47 require?: RequireExtension;
48 documents?: InstanceOrArray<OperationDocument>;
49 config?: {
50 [key: string]: any;
51 };
52 generates: {
53 [filename: string]: OutputConfig | ConfiguredOutput;
54 };
55 overwrite?: boolean;
56 watch?: boolean;
57 silent?: boolean;
58 pluginLoader?: PluginLoaderFn;
59 }
60}
61export declare type PluginFunction<T = any> = (schema: GraphQLSchema, documents: DocumentFile[], config: T) => Promise<string> | string;
62export declare type PluginValidateFn<T = any> = (schema: GraphQLSchema, documents: DocumentFile[], config: T, outputFile: string, allPlugins: Types.ConfiguredPlugin[]) => Promise<void> | void;
63export interface CodegenPlugin<T = any> {
64 plugin: PluginFunction<T>;
65 addToSchema?: string | DocumentNode;
66 validate?: PluginValidateFn;
67}