UNPKG

2.86 kBTypeScriptView Raw
1/// <reference types="node" />
2import { EventEmitter } from 'events';
3import { Fragment, Operation } from 'graphql-tool-utilities';
4import { PrintDocumentOptions, PrintSchemaOptions } from './print';
5import { EnumFormat } from './types';
6export { EnumFormat };
7export interface Options extends PrintDocumentOptions, PrintSchemaOptions {
8 addTypename: boolean;
9 schemaTypesPath: string;
10}
11export interface BuilderOptions extends Options {
12 cwd?: string;
13}
14export interface RunOptions {
15 watch?: boolean;
16}
17export interface SchemaBuild {
18 schemaPath: string;
19 schemaTypesPath: string;
20}
21export interface DocumentBuild {
22 documentPath: string;
23 definitionPath: string;
24 operation?: Operation;
25 fragments: Fragment[];
26}
27export declare class Builder extends EventEmitter {
28 private options;
29 private readonly config;
30 private documentMapByProject;
31 private readonly watchers;
32 constructor({cwd, ...options}: BuilderOptions);
33 once(event: 'error', handler: (error: Error) => void): this;
34 once(event: 'build:docs', handler: (built: DocumentBuild) => void): this;
35 once(event: 'build:schema', handler: (built: SchemaBuild) => void): this;
36 once(event: 'start:docs', handler: () => void): this;
37 once(event: 'end:docs', handler: () => void): this;
38 once(event: 'start:schema', handler: () => void): this;
39 once(event: 'end:schema', handler: () => void): this;
40 on(event: 'error', handler: (error: Error) => void): this;
41 on(event: 'build:docs', handler: (built: DocumentBuild) => void): this;
42 on(event: 'build:schema', handler: (built: SchemaBuild) => void): this;
43 on(event: 'start:docs', handler: () => void): this;
44 on(event: 'end:docs', handler: () => void): this;
45 on(event: 'start:schema', handler: () => void): this;
46 on(event: 'end:schema', handler: () => void): this;
47 emit(event: 'error', error: Error): boolean;
48 emit(event: 'build:docs', built: DocumentBuild): boolean;
49 emit(event: 'build:schema', built: SchemaBuild): boolean;
50 emit(event: 'start:docs'): boolean;
51 emit(event: 'end:docs'): boolean;
52 emit(event: 'start:schema'): boolean;
53 emit(event: 'end:schema'): boolean;
54 run({watch: watchGlobs}?: {
55 watch?: boolean;
56 }): Promise<void>;
57 stop(): void;
58 private setupDocumentWatchers();
59 private setupSchemaWatcher();
60 private generateSchemaTypes(schemaPath);
61 private generateDocumentTypes();
62 private checkForDuplicateOperations();
63 private generateDocumentTypesForProject(projectConfig, documents);
64 private writeDocumentFile(file, ast, projectConfig);
65 private getDocumentDefinition(file, ast, projectConfig);
66 private updateDocumentsForProject(projectConfig);
67 private updateDocumentForFile(filePath, projectConfig);
68 private setDocumentForFilePath(filePath, projectConfig, contents);
69}