-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
index.ts
20 lines (18 loc) · 983 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { GraphQLSchema } from 'graphql';
import { PluginFunction, Types, getCachedDocumentNodeFromSchema, oldVisit } from '@graphql-codegen/plugin-helpers';
import { CSharpResolversVisitor } from './visitor';
import { CSharpResolversPluginRawConfig } from './config';
export const plugin: PluginFunction<CSharpResolversPluginRawConfig> = async (
schema: GraphQLSchema,
documents: Types.DocumentFile[],
config: CSharpResolversPluginRawConfig
): Promise<string> => {
const visitor = new CSharpResolversVisitor(config, schema);
const astNode = getCachedDocumentNodeFromSchema(schema);
const visitorResult = oldVisit(astNode, { leave: visitor });
const imports = visitor.getImports();
const blockContent = visitorResult.definitions.filter(d => typeof d === 'string').join('\n');
const wrappedBlockContent = visitor.wrapWithClass(blockContent);
const wrappedContent = visitor.wrapWithNamespace(wrappedBlockContent);
return [imports, wrappedContent].join('\n');
};