-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
index.ts
26 lines (22 loc) · 863 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { Types, PluginFunction, getCachedDocumentNodeFromSchema, oldVisit } from '@graphql-codegen/plugin-helpers';
import { GraphQLSchema } from 'graphql';
import { FlowVisitor } from './visitor';
import { FlowPluginConfig } from './config';
export * from './visitor';
export * from './flow-variables-to-object';
export const plugin: PluginFunction<FlowPluginConfig, Types.ComplexPluginOutput> = (
schema: GraphQLSchema,
documents: Types.DocumentFile[],
config: FlowPluginConfig
) => {
const header = `// @flow\n`;
const astNode = getCachedDocumentNodeFromSchema(schema);
const visitor = new FlowVisitor(schema, config);
const visitorResult = oldVisit(astNode, {
leave: visitor,
});
return {
prepend: [header, ...visitor.getEnumsImports()],
content: [visitor.scalarsDefinition, ...visitorResult.definitions].join('\n'),
};
};