1 | import { Printable } from "./printer";
|
2 | import { Operation, CompilerContext } from "apollo-codegen-core/lib/compiler";
|
3 |
|
4 | import { exportDeclaration, typeAliasDeclarationForOperation } from "./types";
|
5 |
|
6 | import { constructorDeclarationForOperation } from "./constructors";
|
7 |
|
8 | import Dependencies from "./dependencies";
|
9 | import dependencyImports from "./dependencyImports";
|
10 | import stringDeclarations from "./stringDeclarations";
|
11 |
|
12 | export 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 | };
|