UNPKG

1.09 kBPlain TextView Raw
1import { Printable } from "./printer";
2import { Operation, CompilerContext } from "apollo-codegen-core/lib/compiler";
3
4import { exportDeclaration, typeAliasDeclarationForOperation } from "./types";
5
6import { constructorDeclarationForOperation } from "./constructors";
7
8import Dependencies from "./dependencies";
9import dependencyImports from "./dependencyImports";
10import stringDeclarations from "./stringDeclarations";
11
12export const operationFile = (
13 operation: Operation,
14 outputPath: string,
15 globalSourcePath: string,
16 context: CompilerContext
17): Printable[] => {
18 const dependencies = Dependencies(
19 operation.selectionSet,
20 operation.variables
21 );
22 return [
23 ...dependencyImports(dependencies, outputPath, globalSourcePath, context),
24 ...stringDeclarations(
25 operation.operationName,
26 operation.filePath,
27 outputPath,
28 dependencies.fragments.map(fragmentDependency => fragmentDependency.name)
29 ),
30 exportDeclaration(typeAliasDeclarationForOperation(operation)),
31 exportDeclaration(constructorDeclarationForOperation(operation))
32 ];
33};