relay-compiler 0.0.0-main-8ff54d69 → 0.0.0-main-38f1c96e
Sign up to get free protection for your applications and to get access to all the features.
- package/cli.js +23 -0
- package/index.js +19 -3
- package/linux-x64/relay +0 -0
- package/macos-x64/relay +0 -0
- package/package.json +2 -24
- package/win-x64/relay.exe +0 -0
- package/bin/RelayCompilerBin.js.flow +0 -168
- package/bin/RelayCompilerMain.js.flow +0 -515
- package/bin/__fixtures__/plugin-module.js.flow +0 -17
- package/bin/relay-compiler +0 -19068
- package/codegen/CodegenDirectory.js.flow +0 -372
- package/codegen/CodegenRunner.js.flow +0 -424
- package/codegen/CodegenTypes.js.flow +0 -28
- package/codegen/CodegenWatcher.js.flow +0 -250
- package/codegen/NormalizationCodeGenerator.js.flow +0 -566
- package/codegen/ReaderCodeGenerator.js.flow +0 -510
- package/codegen/RelayCodeGenerator.js.flow +0 -85
- package/codegen/RelayFileWriter.js.flow +0 -365
- package/codegen/SourceControl.js.flow +0 -58
- package/codegen/compileRelayArtifacts.js.flow +0 -181
- package/codegen/createPrintRequireModuleDependency.js.flow +0 -19
- package/codegen/sortObjectByKey.js.flow +0 -25
- package/codegen/writeRelayGeneratedFile.js.flow +0 -235
- package/core/ASTCache.js.flow +0 -73
- package/core/ASTConvert.js.flow +0 -230
- package/core/CompilerContext.js.flow +0 -189
- package/core/CompilerError.js.flow +0 -255
- package/core/DotGraphQLParser.js.flow +0 -37
- package/core/GraphQLCompilerProfiler.js.flow +0 -341
- package/core/GraphQLDerivedFromMetadata.js.flow +0 -36
- package/core/GraphQLWatchmanClient.js.flow +0 -109
- package/core/IR.js.flow +0 -326
- package/core/IRPrinter.js.flow +0 -472
- package/core/IRTransformer.js.flow +0 -376
- package/core/IRValidator.js.flow +0 -259
- package/core/IRVisitor.js.flow +0 -150
- package/core/JSModuleParser.js.flow +0 -24
- package/core/RelayCompilerScope.js.flow +0 -199
- package/core/RelayFindGraphQLTags.js.flow +0 -118
- package/core/RelayGraphQLEnumsGenerator.js.flow +0 -55
- package/core/RelayIRTransforms.js.flow +0 -138
- package/core/RelayParser.js.flow +0 -1741
- package/core/RelaySourceModuleParser.js.flow +0 -133
- package/core/Schema.js.flow +0 -2035
- package/core/SchemaUtils.js.flow +0 -120
- package/core/filterContextForNode.js.flow +0 -49
- package/core/getFieldDefinition.js.flow +0 -156
- package/core/getIdentifierForArgumentValue.js.flow +0 -49
- package/core/getIdentifierForSelection.js.flow +0 -68
- package/core/getLiteralArgumentValues.js.flow +0 -32
- package/core/getNormalizationOperationName.js.flow +0 -19
- package/core/inferRootArgumentDefinitions.js.flow +0 -322
- package/index.js.flow +0 -198
- package/language/RelayLanguagePluginInterface.js.flow +0 -283
- package/language/javascript/FindGraphQLTags.js.flow +0 -136
- package/language/javascript/RelayFlowBabelFactories.js.flow +0 -176
- package/language/javascript/RelayFlowGenerator.js.flow +0 -1096
- package/language/javascript/RelayFlowTypeTransformers.js.flow +0 -181
- package/language/javascript/RelayLanguagePluginJavaScript.js.flow +0 -33
- package/language/javascript/formatGeneratedModule.js.flow +0 -65
- package/lib/bin/RelayCompilerBin.js +0 -143
- package/lib/bin/RelayCompilerMain.js +0 -488
- package/lib/bin/__fixtures__/plugin-module.js +0 -16
- package/lib/codegen/CodegenDirectory.js +0 -335
- package/lib/codegen/CodegenRunner.js +0 -433
- package/lib/codegen/CodegenTypes.js +0 -11
- package/lib/codegen/CodegenWatcher.js +0 -271
- package/lib/codegen/NormalizationCodeGenerator.js +0 -487
- package/lib/codegen/ReaderCodeGenerator.js +0 -473
- package/lib/codegen/RelayCodeGenerator.js +0 -75
- package/lib/codegen/RelayFileWriter.js +0 -270
- package/lib/codegen/SourceControl.js +0 -60
- package/lib/codegen/compileRelayArtifacts.js +0 -157
- package/lib/codegen/createPrintRequireModuleDependency.js +0 -19
- package/lib/codegen/sortObjectByKey.js +0 -41
- package/lib/codegen/writeRelayGeneratedFile.js +0 -206
- package/lib/core/ASTCache.js +0 -70
- package/lib/core/ASTConvert.js +0 -198
- package/lib/core/CompilerContext.js +0 -165
- package/lib/core/CompilerError.js +0 -252
- package/lib/core/DotGraphQLParser.js +0 -40
- package/lib/core/GraphQLCompilerProfiler.js +0 -299
- package/lib/core/GraphQLDerivedFromMetadata.js +0 -31
- package/lib/core/GraphQLWatchmanClient.js +0 -150
- package/lib/core/IR.js +0 -11
- package/lib/core/IRPrinter.js +0 -388
- package/lib/core/IRTransformer.js +0 -345
- package/lib/core/IRValidator.js +0 -226
- package/lib/core/IRVisitor.js +0 -45
- package/lib/core/JSModuleParser.js +0 -18
- package/lib/core/RelayCompilerScope.js +0 -183
- package/lib/core/RelayFindGraphQLTags.js +0 -79
- package/lib/core/RelayGraphQLEnumsGenerator.js +0 -50
- package/lib/core/RelayIRTransforms.js +0 -109
- package/lib/core/RelayParser.js +0 -1381
- package/lib/core/RelaySourceModuleParser.js +0 -104
- package/lib/core/Schema.js +0 -1877
- package/lib/core/SchemaUtils.js +0 -98
- package/lib/core/filterContextForNode.js +0 -50
- package/lib/core/getFieldDefinition.js +0 -145
- package/lib/core/getIdentifierForArgumentValue.js +0 -54
- package/lib/core/getIdentifierForSelection.js +0 -49
- package/lib/core/getLiteralArgumentValues.js +0 -26
- package/lib/core/getNormalizationOperationName.js +0 -17
- package/lib/core/inferRootArgumentDefinitions.js +0 -351
- package/lib/index.js +0 -178
- package/lib/language/RelayLanguagePluginInterface.js +0 -26
- package/lib/language/javascript/FindGraphQLTags.js +0 -126
- package/lib/language/javascript/RelayFlowBabelFactories.js +0 -160
- package/lib/language/javascript/RelayFlowGenerator.js +0 -856
- package/lib/language/javascript/RelayFlowTypeTransformers.js +0 -119
- package/lib/language/javascript/RelayLanguagePluginJavaScript.js +0 -30
- package/lib/language/javascript/formatGeneratedModule.js +0 -36
- package/lib/reporters/ConsoleReporter.js +0 -61
- package/lib/reporters/MultiReporter.js +0 -45
- package/lib/reporters/Reporter.js +0 -11
- package/lib/runner/Artifacts.js +0 -323
- package/lib/runner/BufferedFilesystem.js +0 -262
- package/lib/runner/GraphQLASTNodeGroup.js +0 -256
- package/lib/runner/GraphQLASTUtils.js +0 -23
- package/lib/runner/GraphQLNodeMap.js +0 -81
- package/lib/runner/Sources.js +0 -271
- package/lib/runner/StrictMap.js +0 -134
- package/lib/runner/compileArtifacts.js +0 -39
- package/lib/runner/extractAST.js +0 -77
- package/lib/runner/getChangedNodeNames.js +0 -82
- package/lib/runner/getSchemaInstance.js +0 -30
- package/lib/runner/types.js +0 -12
- package/lib/test-utils/TestSchema.js +0 -27
- package/lib/test-utils/parseGraphQLText.js +0 -30
- package/lib/transforms/ApplyFragmentArgumentTransform.js +0 -393
- package/lib/transforms/ClientExtensionsTransform.js +0 -221
- package/lib/transforms/ConnectionTransform.js +0 -639
- package/lib/transforms/DeclarativeConnectionMutationTransform.js +0 -218
- package/lib/transforms/DeferStreamTransform.js +0 -246
- package/lib/transforms/DisallowIdAsAlias.js +0 -40
- package/lib/transforms/DisallowTypenameOnRoot.js +0 -53
- package/lib/transforms/FieldHandleTransform.js +0 -79
- package/lib/transforms/FilterCompilerDirectivesTransform.js +0 -29
- package/lib/transforms/FilterDirectivesTransform.js +0 -42
- package/lib/transforms/FlattenTransform.js +0 -306
- package/lib/transforms/GenerateIDFieldTransform.js +0 -135
- package/lib/transforms/GenerateTypeNameTransform.js +0 -149
- package/lib/transforms/InlineDataFragmentTransform.js +0 -100
- package/lib/transforms/InlineFragmentsTransform.js +0 -61
- package/lib/transforms/MaskTransform.js +0 -117
- package/lib/transforms/MatchTransform.js +0 -434
- package/lib/transforms/ReactFlightComponentTransform.js +0 -158
- package/lib/transforms/RefetchableFragmentTransform.js +0 -249
- package/lib/transforms/RelayDirectiveTransform.js +0 -83
- package/lib/transforms/RequiredFieldTransform.js +0 -369
- package/lib/transforms/SkipClientExtensionsTransform.js +0 -46
- package/lib/transforms/SkipHandleFieldTransform.js +0 -45
- package/lib/transforms/SkipRedundantNodesTransform.js +0 -261
- package/lib/transforms/SkipSplitOperationTransform.js +0 -32
- package/lib/transforms/SkipUnreachableNodeTransform.js +0 -158
- package/lib/transforms/SkipUnusedVariablesTransform.js +0 -75
- package/lib/transforms/SplitModuleImportTransform.js +0 -82
- package/lib/transforms/TestOperationTransform.js +0 -144
- package/lib/transforms/TransformUtils.js +0 -21
- package/lib/transforms/ValidateGlobalVariablesTransform.js +0 -92
- package/lib/transforms/ValidateRequiredArgumentsTransform.js +0 -114
- package/lib/transforms/ValidateServerOnlyDirectivesTransform.js +0 -108
- package/lib/transforms/ValidateUnusedVariablesTransform.js +0 -96
- package/lib/transforms/query-generators/FetchableQueryGenerator.js +0 -157
- package/lib/transforms/query-generators/NodeQueryGenerator.js +0 -166
- package/lib/transforms/query-generators/QueryQueryGenerator.js +0 -48
- package/lib/transforms/query-generators/ViewerQueryGenerator.js +0 -77
- package/lib/transforms/query-generators/index.js +0 -60
- package/lib/transforms/query-generators/utils.js +0 -92
- package/lib/util/CodeMarker.js +0 -80
- package/lib/util/DefaultHandleKey.js +0 -15
- package/lib/util/RelayCompilerCache.js +0 -97
- package/lib/util/Rollout.js +0 -40
- package/lib/util/TimeReporter.js +0 -83
- package/lib/util/areEqualArgValues.js +0 -135
- package/lib/util/argumentContainsVariables.js +0 -37
- package/lib/util/dedupeJSONStringify.js +0 -160
- package/lib/util/generateAbstractTypeRefinementKey.js +0 -24
- package/lib/util/getDefinitionNodeHash.js +0 -22
- package/lib/util/getModuleName.js +0 -32
- package/lib/util/joinArgumentDefinitions.js +0 -67
- package/lib/util/md5.js +0 -17
- package/lib/util/murmurHash.js +0 -86
- package/lib/util/nullthrowsOSS.js +0 -23
- package/lib/util/orList.js +0 -36
- package/lib/util/partitionArray.js +0 -35
- package/relay-compiler.js +0 -17
- package/relay-compiler.min.js +0 -22
- package/reporters/ConsoleReporter.js.flow +0 -81
- package/reporters/MultiReporter.js.flow +0 -43
- package/reporters/Reporter.js.flow +0 -19
- package/runner/Artifacts.js.flow +0 -215
- package/runner/BufferedFilesystem.js.flow +0 -194
- package/runner/GraphQLASTNodeGroup.js.flow +0 -174
- package/runner/GraphQLASTUtils.js.flow +0 -26
- package/runner/GraphQLNodeMap.js.flow +0 -55
- package/runner/Sources.js.flow +0 -227
- package/runner/StrictMap.js.flow +0 -96
- package/runner/compileArtifacts.js.flow +0 -75
- package/runner/extractAST.js.flow +0 -98
- package/runner/getChangedNodeNames.js.flow +0 -48
- package/runner/getSchemaInstance.js.flow +0 -36
- package/runner/types.js.flow +0 -37
- package/test-utils/TestSchema.js.flow +0 -30
- package/test-utils/parseGraphQLText.js.flow +0 -41
- package/transforms/ApplyFragmentArgumentTransform.js.flow +0 -524
- package/transforms/ClientExtensionsTransform.js.flow +0 -224
- package/transforms/ConnectionTransform.js.flow +0 -850
- package/transforms/DeclarativeConnectionMutationTransform.js.flow +0 -245
- package/transforms/DeferStreamTransform.js.flow +0 -263
- package/transforms/DisallowIdAsAlias.js.flow +0 -46
- package/transforms/DisallowTypenameOnRoot.js.flow +0 -44
- package/transforms/FieldHandleTransform.js.flow +0 -77
- package/transforms/FilterCompilerDirectivesTransform.js.flow +0 -33
- package/transforms/FilterDirectivesTransform.js.flow +0 -45
- package/transforms/FlattenTransform.js.flow +0 -458
- package/transforms/GenerateIDFieldTransform.js.flow +0 -151
- package/transforms/GenerateTypeNameTransform.js.flow +0 -159
- package/transforms/InlineDataFragmentTransform.js.flow +0 -123
- package/transforms/InlineFragmentsTransform.js.flow +0 -70
- package/transforms/MaskTransform.js.flow +0 -124
- package/transforms/MatchTransform.js.flow +0 -587
- package/transforms/ReactFlightComponentTransform.js.flow +0 -207
- package/transforms/RefetchableFragmentTransform.js.flow +0 -266
- package/transforms/RelayDirectiveTransform.js.flow +0 -96
- package/transforms/RequiredFieldTransform.js.flow +0 -413
- package/transforms/SkipClientExtensionsTransform.js.flow +0 -54
- package/transforms/SkipHandleFieldTransform.js.flow +0 -44
- package/transforms/SkipRedundantNodesTransform.js.flow +0 -277
- package/transforms/SkipSplitOperationTransform.js.flow +0 -37
- package/transforms/SkipUnreachableNodeTransform.js.flow +0 -148
- package/transforms/SkipUnusedVariablesTransform.js.flow +0 -59
- package/transforms/SplitModuleImportTransform.js.flow +0 -97
- package/transforms/TestOperationTransform.js.flow +0 -142
- package/transforms/TransformUtils.js.flow +0 -26
- package/transforms/ValidateGlobalVariablesTransform.js.flow +0 -80
- package/transforms/ValidateRequiredArgumentsTransform.js.flow +0 -130
- package/transforms/ValidateServerOnlyDirectivesTransform.js.flow +0 -128
- package/transforms/ValidateUnusedVariablesTransform.js.flow +0 -88
- package/transforms/query-generators/FetchableQueryGenerator.js.flow +0 -188
- package/transforms/query-generators/NodeQueryGenerator.js.flow +0 -217
- package/transforms/query-generators/QueryQueryGenerator.js.flow +0 -57
- package/transforms/query-generators/ViewerQueryGenerator.js.flow +0 -97
- package/transforms/query-generators/index.js.flow +0 -89
- package/transforms/query-generators/utils.js.flow +0 -76
- package/util/CodeMarker.js.flow +0 -79
- package/util/DefaultHandleKey.js.flow +0 -17
- package/util/RelayCompilerCache.js.flow +0 -86
- package/util/Rollout.js.flow +0 -39
- package/util/TimeReporter.js.flow +0 -79
- package/util/areEqualArgValues.js.flow +0 -126
- package/util/argumentContainsVariables.js.flow +0 -38
- package/util/dedupeJSONStringify.js.flow +0 -156
- package/util/generateAbstractTypeRefinementKey.js.flow +0 -29
- package/util/getDefinitionNodeHash.js.flow +0 -24
- package/util/getModuleName.js.flow +0 -39
- package/util/joinArgumentDefinitions.js.flow +0 -105
- package/util/md5.js.flow +0 -19
- package/util/murmurHash.js.flow +0 -94
- package/util/nullthrowsOSS.js.flow +0 -25
- package/util/orList.js.flow +0 -37
- package/util/partitionArray.js.flow +0 -37
@@ -1,365 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
6
|
-
*
|
7
|
-
* @flow
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
|
13
|
-
'use strict';
|
14
|
-
|
15
|
-
import type {Schema} from '../core/Schema';
|
16
|
-
import type {ScalarTypeMapping} from '../language/javascript/RelayFlowTypeTransformers';
|
17
|
-
import type {
|
18
|
-
FormatModule,
|
19
|
-
PluginInterface,
|
20
|
-
TypeGenerator,
|
21
|
-
} from '../language/RelayLanguagePluginInterface';
|
22
|
-
import type {Reporter} from '../reporters/Reporter';
|
23
|
-
import type {Filesystem} from './CodegenDirectory';
|
24
|
-
import type {RelayCompilerTransforms} from './compileRelayArtifacts';
|
25
|
-
import type {SourceControl} from './SourceControl';
|
26
|
-
import type {DocumentNode, ValidationContext} from 'graphql';
|
27
|
-
import type {RequestParameters} from 'relay-runtime';
|
28
|
-
|
29
|
-
const ASTConvert = require('../core/ASTConvert');
|
30
|
-
const CompilerContext = require('../core/CompilerContext');
|
31
|
-
const Profiler = require('../core/GraphQLCompilerProfiler');
|
32
|
-
const {
|
33
|
-
getReaderSourceDefinitionName,
|
34
|
-
} = require('../core/GraphQLDerivedFromMetadata');
|
35
|
-
const RelayParser = require('../core/RelayParser');
|
36
|
-
const {isExecutableDefinitionAST} = require('../core/SchemaUtils');
|
37
|
-
const md5 = require('../util/md5');
|
38
|
-
const CodegenDirectory = require('./CodegenDirectory');
|
39
|
-
const compileRelayArtifacts = require('./compileRelayArtifacts');
|
40
|
-
const writeRelayGeneratedFile = require('./writeRelayGeneratedFile');
|
41
|
-
const graphql = require('graphql');
|
42
|
-
const {Map: ImmutableMap} = require('immutable');
|
43
|
-
const invariant = require('invariant');
|
44
|
-
const nullthrows = require('nullthrows');
|
45
|
-
const path = require('path');
|
46
|
-
|
47
|
-
export type GenerateExtraFiles = (
|
48
|
-
getOutputDirectory: (path?: string) => CodegenDirectory,
|
49
|
-
compilerContext: CompilerContext,
|
50
|
-
getGeneratedDirectory: (definitionName: string) => CodegenDirectory,
|
51
|
-
) => void;
|
52
|
-
|
53
|
-
export type ValidationRule = (context: ValidationContext) => any;
|
54
|
-
|
55
|
-
export type WriterConfig = {
|
56
|
-
baseDir: string,
|
57
|
-
compilerTransforms: RelayCompilerTransforms,
|
58
|
-
customScalars: ScalarTypeMapping,
|
59
|
-
formatModule: FormatModule,
|
60
|
-
generateExtraFiles?: GenerateExtraFiles,
|
61
|
-
optionalInputFieldsForFlow: $ReadOnlyArray<string>,
|
62
|
-
outputDir?: ?string,
|
63
|
-
generatedDirectories?: $ReadOnlyArray<string>,
|
64
|
-
persistQuery?: ?(text: string) => Promise<string>,
|
65
|
-
schemaExtensions: $ReadOnlyArray<string>,
|
66
|
-
noFutureProofEnums: boolean,
|
67
|
-
useHaste: boolean,
|
68
|
-
extension: string,
|
69
|
-
typeGenerator: TypeGenerator,
|
70
|
-
// Haste style module that exports flow types for GraphQL enums.
|
71
|
-
// TODO(T22422153) support non-haste environments
|
72
|
-
enumsHasteModule?: string,
|
73
|
-
printModuleDependency?: string => string,
|
74
|
-
filesystem?: Filesystem,
|
75
|
-
repersist?: boolean,
|
76
|
-
writeQueryParameters?: (
|
77
|
-
outputDirectory: CodegenDirectory,
|
78
|
-
filename: string,
|
79
|
-
moduleName: string,
|
80
|
-
requestParams: RequestParameters,
|
81
|
-
) => void,
|
82
|
-
...
|
83
|
-
};
|
84
|
-
|
85
|
-
function compileAll({
|
86
|
-
baseDir,
|
87
|
-
baseDocuments,
|
88
|
-
schema,
|
89
|
-
compilerTransforms,
|
90
|
-
documents,
|
91
|
-
reporter,
|
92
|
-
typeGenerator,
|
93
|
-
}: {|
|
94
|
-
baseDir: string,
|
95
|
-
baseDocuments: $ReadOnlyArray<DocumentNode>,
|
96
|
-
schema: Schema,
|
97
|
-
compilerTransforms: RelayCompilerTransforms,
|
98
|
-
documents: $ReadOnlyArray<DocumentNode>,
|
99
|
-
reporter: Reporter,
|
100
|
-
typeGenerator: TypeGenerator,
|
101
|
-
|}) {
|
102
|
-
const definitions = ASTConvert.convertASTDocumentsWithBase(
|
103
|
-
schema,
|
104
|
-
baseDocuments,
|
105
|
-
documents,
|
106
|
-
RelayParser.transform,
|
107
|
-
);
|
108
|
-
const compilerContext = new CompilerContext(schema).addAll(definitions);
|
109
|
-
|
110
|
-
const transformedTypeContext = compilerContext.applyTransforms(
|
111
|
-
typeGenerator.transforms,
|
112
|
-
reporter,
|
113
|
-
);
|
114
|
-
const transformedQueryContext = compilerContext.applyTransforms(
|
115
|
-
[
|
116
|
-
...compilerTransforms.commonTransforms,
|
117
|
-
...compilerTransforms.queryTransforms,
|
118
|
-
],
|
119
|
-
reporter,
|
120
|
-
);
|
121
|
-
const artifacts = compileRelayArtifacts(
|
122
|
-
compilerContext,
|
123
|
-
compilerTransforms,
|
124
|
-
reporter,
|
125
|
-
);
|
126
|
-
|
127
|
-
return {
|
128
|
-
artifacts,
|
129
|
-
definitions,
|
130
|
-
transformedQueryContext,
|
131
|
-
transformedTypeContext,
|
132
|
-
};
|
133
|
-
}
|
134
|
-
|
135
|
-
function writeAll({
|
136
|
-
config: writerConfig,
|
137
|
-
onlyValidate,
|
138
|
-
baseDocuments,
|
139
|
-
documents,
|
140
|
-
schema,
|
141
|
-
reporter,
|
142
|
-
sourceControl,
|
143
|
-
languagePlugin,
|
144
|
-
}: {|
|
145
|
-
config: WriterConfig,
|
146
|
-
onlyValidate: boolean,
|
147
|
-
// $FlowFixMe[value-as-type]
|
148
|
-
baseDocuments: ImmutableMap<string, DocumentNode>,
|
149
|
-
// $FlowFixMe[value-as-type]
|
150
|
-
documents: ImmutableMap<string, DocumentNode>,
|
151
|
-
schema: Schema,
|
152
|
-
reporter: Reporter,
|
153
|
-
sourceControl: ?SourceControl,
|
154
|
-
languagePlugin?: ?PluginInterface,
|
155
|
-
|}): Promise<Map<string, CodegenDirectory>> {
|
156
|
-
return Profiler.asyncContext('RelayFileWriter.writeAll', async () => {
|
157
|
-
const {
|
158
|
-
artifacts: artifactsWithBase,
|
159
|
-
transformedTypeContext,
|
160
|
-
transformedQueryContext,
|
161
|
-
} = compileAll({
|
162
|
-
schema,
|
163
|
-
baseDir: writerConfig.baseDir,
|
164
|
-
baseDocuments: baseDocuments.valueSeq().toArray(),
|
165
|
-
compilerTransforms: writerConfig.compilerTransforms,
|
166
|
-
documents: documents.valueSeq().toArray(),
|
167
|
-
reporter,
|
168
|
-
typeGenerator: writerConfig.typeGenerator,
|
169
|
-
});
|
170
|
-
// Build a context from all the documents
|
171
|
-
const baseDefinitionNames = new Set();
|
172
|
-
baseDocuments.forEach(doc => {
|
173
|
-
doc.definitions.forEach(def => {
|
174
|
-
if (isExecutableDefinitionAST(def) && def.name) {
|
175
|
-
baseDefinitionNames.add(def.name.value);
|
176
|
-
}
|
177
|
-
});
|
178
|
-
});
|
179
|
-
|
180
|
-
// remove nodes that are present in the base or that derive from nodes
|
181
|
-
// in the base
|
182
|
-
const artifacts = artifactsWithBase.filter(([_definition, node]) => {
|
183
|
-
const sourceName = getReaderSourceDefinitionName(node);
|
184
|
-
return !baseDefinitionNames.has(sourceName);
|
185
|
-
});
|
186
|
-
|
187
|
-
const artifactMap = new Map(
|
188
|
-
artifacts.map(([_definition, node]) => [
|
189
|
-
node.kind === 'Request' ? node.params.name : node.name,
|
190
|
-
node,
|
191
|
-
]),
|
192
|
-
);
|
193
|
-
|
194
|
-
const definitionsMeta = new Map();
|
195
|
-
const getDefinitionMeta = (definitionName: string) => {
|
196
|
-
const artifact = nullthrows(artifactMap.get(definitionName));
|
197
|
-
const sourceName = getReaderSourceDefinitionName(artifact);
|
198
|
-
const definitionMeta = definitionsMeta.get(sourceName);
|
199
|
-
invariant(
|
200
|
-
definitionMeta,
|
201
|
-
'RelayFileWriter: Could not determine source for definition: `%s`.',
|
202
|
-
definitionName,
|
203
|
-
);
|
204
|
-
return definitionMeta;
|
205
|
-
};
|
206
|
-
documents.forEach((doc, filePath) => {
|
207
|
-
doc.definitions.forEach(def => {
|
208
|
-
if (def.name) {
|
209
|
-
definitionsMeta.set(def.name.value, {
|
210
|
-
dir: path.join(writerConfig.baseDir, path.dirname(filePath)),
|
211
|
-
ast: def,
|
212
|
-
});
|
213
|
-
}
|
214
|
-
});
|
215
|
-
});
|
216
|
-
|
217
|
-
const allOutputDirectories: Map<string, CodegenDirectory> = new Map();
|
218
|
-
const addCodegenDir = (dirPath: string) => {
|
219
|
-
const codegenDir = new CodegenDirectory(dirPath, {
|
220
|
-
onlyValidate: onlyValidate,
|
221
|
-
filesystem: writerConfig.filesystem,
|
222
|
-
});
|
223
|
-
allOutputDirectories.set(dirPath, codegenDir);
|
224
|
-
return codegenDir;
|
225
|
-
};
|
226
|
-
|
227
|
-
for (const existingDirectory of writerConfig.generatedDirectories || []) {
|
228
|
-
addCodegenDir(existingDirectory);
|
229
|
-
}
|
230
|
-
|
231
|
-
let configOutputDirectory;
|
232
|
-
if (writerConfig.outputDir) {
|
233
|
-
configOutputDirectory = addCodegenDir(writerConfig.outputDir);
|
234
|
-
}
|
235
|
-
|
236
|
-
const getGeneratedDirectory = (definitionName: string) => {
|
237
|
-
if (configOutputDirectory) {
|
238
|
-
return configOutputDirectory;
|
239
|
-
}
|
240
|
-
const generatedPath = path.join(
|
241
|
-
getDefinitionMeta(definitionName).dir,
|
242
|
-
'__generated__',
|
243
|
-
);
|
244
|
-
let cachedDir = allOutputDirectories.get(generatedPath);
|
245
|
-
if (!cachedDir) {
|
246
|
-
cachedDir = addCodegenDir(generatedPath);
|
247
|
-
}
|
248
|
-
return cachedDir;
|
249
|
-
};
|
250
|
-
|
251
|
-
const formatModule = Profiler.instrument(
|
252
|
-
writerConfig.formatModule,
|
253
|
-
'RelayFileWriter:formatModule',
|
254
|
-
);
|
255
|
-
|
256
|
-
const persistQuery = writerConfig.persistQuery
|
257
|
-
? Profiler.instrumentWait(
|
258
|
-
writerConfig.persistQuery,
|
259
|
-
'RelayFileWriter:persistQuery',
|
260
|
-
)
|
261
|
-
: null;
|
262
|
-
|
263
|
-
try {
|
264
|
-
await Promise.all(
|
265
|
-
artifacts.map(async ([definition, node]) => {
|
266
|
-
const nodeName =
|
267
|
-
node.kind === 'Request' ? node.params.name : node.name;
|
268
|
-
if (baseDefinitionNames.has(nodeName)) {
|
269
|
-
// don't add definitions that were part of base context
|
270
|
-
return;
|
271
|
-
}
|
272
|
-
|
273
|
-
const typeNode = transformedTypeContext.get(nodeName);
|
274
|
-
const typeText = typeNode
|
275
|
-
? writerConfig.typeGenerator.generate(
|
276
|
-
schema,
|
277
|
-
(typeNode: $FlowFixMe),
|
278
|
-
{
|
279
|
-
customScalars: writerConfig.customScalars,
|
280
|
-
enumsHasteModule: writerConfig.enumsHasteModule,
|
281
|
-
optionalInputFields: writerConfig.optionalInputFieldsForFlow,
|
282
|
-
useHaste: writerConfig.useHaste,
|
283
|
-
useSingleArtifactDirectory: !!writerConfig.outputDir,
|
284
|
-
noFutureProofEnums: writerConfig.noFutureProofEnums,
|
285
|
-
normalizationIR:
|
286
|
-
definition.kind === 'Request' ? definition.root : undefined,
|
287
|
-
},
|
288
|
-
)
|
289
|
-
: '';
|
290
|
-
|
291
|
-
const sourceHash = Profiler.run('hashGraphQL', () =>
|
292
|
-
md5(graphql.print(getDefinitionMeta(nodeName).ast)),
|
293
|
-
);
|
294
|
-
|
295
|
-
await writeRelayGeneratedFile(
|
296
|
-
schema,
|
297
|
-
getGeneratedDirectory(nodeName),
|
298
|
-
definition,
|
299
|
-
node,
|
300
|
-
formatModule,
|
301
|
-
typeText,
|
302
|
-
persistQuery,
|
303
|
-
sourceHash,
|
304
|
-
writerConfig.extension,
|
305
|
-
writerConfig.printModuleDependency,
|
306
|
-
writerConfig.repersist ?? false,
|
307
|
-
writerConfig.writeQueryParameters ?? function noop() {},
|
308
|
-
languagePlugin,
|
309
|
-
);
|
310
|
-
}),
|
311
|
-
);
|
312
|
-
|
313
|
-
const generateExtraFiles = writerConfig.generateExtraFiles;
|
314
|
-
if (generateExtraFiles) {
|
315
|
-
Profiler.run('RelayFileWriter:generateExtraFiles', () => {
|
316
|
-
const configDirectory = writerConfig.outputDir;
|
317
|
-
generateExtraFiles(
|
318
|
-
dir => {
|
319
|
-
const outputDirectory = dir || configDirectory;
|
320
|
-
invariant(
|
321
|
-
outputDirectory,
|
322
|
-
'RelayFileWriter: cannot generate extra files without specifying ' +
|
323
|
-
'an outputDir in the config or passing it in.',
|
324
|
-
);
|
325
|
-
let outputDir = allOutputDirectories.get(outputDirectory);
|
326
|
-
if (!outputDir) {
|
327
|
-
outputDir = addCodegenDir(outputDirectory);
|
328
|
-
}
|
329
|
-
return outputDir;
|
330
|
-
},
|
331
|
-
transformedQueryContext,
|
332
|
-
getGeneratedDirectory,
|
333
|
-
);
|
334
|
-
});
|
335
|
-
}
|
336
|
-
|
337
|
-
allOutputDirectories.forEach(dir => {
|
338
|
-
dir.deleteExtraFiles(languagePlugin?.keepExtraFile);
|
339
|
-
});
|
340
|
-
if (sourceControl && !onlyValidate) {
|
341
|
-
await CodegenDirectory.sourceControlAddRemove(
|
342
|
-
sourceControl,
|
343
|
-
Array.from(allOutputDirectories.values()),
|
344
|
-
);
|
345
|
-
}
|
346
|
-
} catch (error) {
|
347
|
-
let details;
|
348
|
-
try {
|
349
|
-
details = JSON.parse(error.message);
|
350
|
-
} catch (_) {} // eslint-disable-line lint/no-unused-catch-bindings
|
351
|
-
if (details && details.name === 'GraphQL2Exception' && details.message) {
|
352
|
-
throw new Error('GraphQL error writing modules:\n' + details.message);
|
353
|
-
}
|
354
|
-
throw new Error(
|
355
|
-
'Error writing modules:\n' + String(error.stack || error),
|
356
|
-
);
|
357
|
-
}
|
358
|
-
|
359
|
-
return allOutputDirectories;
|
360
|
-
});
|
361
|
-
}
|
362
|
-
|
363
|
-
module.exports = {
|
364
|
-
writeAll,
|
365
|
-
};
|
@@ -1,58 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
6
|
-
*
|
7
|
-
* @flow strict
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
|
13
|
-
'use strict';
|
14
|
-
|
15
|
-
const childProcess = require('child_process');
|
16
|
-
|
17
|
-
function execFile(cmd: string, args: Array<string>): Promise<void> {
|
18
|
-
return new Promise((resolve, reject) => {
|
19
|
-
childProcess.execFile(cmd, args, err => {
|
20
|
-
if (err) {
|
21
|
-
reject(err);
|
22
|
-
} else {
|
23
|
-
resolve();
|
24
|
-
}
|
25
|
-
});
|
26
|
-
});
|
27
|
-
}
|
28
|
-
|
29
|
-
/**
|
30
|
-
* An abstraction over the source control system to make it injectable.
|
31
|
-
*/
|
32
|
-
export type SourceControl = {
|
33
|
-
addRemove(
|
34
|
-
added: $ReadOnlyArray<string>,
|
35
|
-
removed: $ReadOnlyArray<string>,
|
36
|
-
): Promise<void>,
|
37
|
-
...
|
38
|
-
};
|
39
|
-
|
40
|
-
const SourceControlMercurial: SourceControl = {
|
41
|
-
async addRemove(
|
42
|
-
added: $ReadOnlyArray<string>,
|
43
|
-
removed: $ReadOnlyArray<string>,
|
44
|
-
): Promise<void> {
|
45
|
-
// NOTE: Not using `hg addremove` as that has a bug when deleting a file
|
46
|
-
// that was just added, but not yet committed: T10711513
|
47
|
-
if (added.length > 0) {
|
48
|
-
await execFile('hg', ['add', ...added]);
|
49
|
-
}
|
50
|
-
if (removed.length > 0) {
|
51
|
-
await execFile('hg', ['forget', ...removed]);
|
52
|
-
}
|
53
|
-
},
|
54
|
-
};
|
55
|
-
|
56
|
-
module.exports = {
|
57
|
-
SourceControlMercurial,
|
58
|
-
};
|
@@ -1,181 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
6
|
-
*
|
7
|
-
* @flow strict-local
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
|
13
|
-
'use strict';
|
14
|
-
|
15
|
-
import type CompilerContext from '../core/CompilerContext';
|
16
|
-
import type {IRTransform} from '../core/CompilerContext';
|
17
|
-
import type {GeneratedDefinition} from '../core/IR';
|
18
|
-
import type {Reporter} from '../reporters/Reporter';
|
19
|
-
import type {GeneratedNode} from 'relay-runtime';
|
20
|
-
|
21
|
-
const filterContextForNode = require('../core/filterContextForNode');
|
22
|
-
const Profiler = require('../core/GraphQLCompilerProfiler');
|
23
|
-
const Printer = require('../core/IRPrinter');
|
24
|
-
const RelayCodeGenerator = require('./RelayCodeGenerator');
|
25
|
-
|
26
|
-
export type RelayCompilerTransforms = {
|
27
|
-
commonTransforms: $ReadOnlyArray<IRTransform>,
|
28
|
-
codegenTransforms: $ReadOnlyArray<IRTransform>,
|
29
|
-
fragmentTransforms: $ReadOnlyArray<IRTransform>,
|
30
|
-
printTransforms: $ReadOnlyArray<IRTransform>,
|
31
|
-
queryTransforms: $ReadOnlyArray<IRTransform>,
|
32
|
-
...
|
33
|
-
};
|
34
|
-
|
35
|
-
function createFragmentContext(
|
36
|
-
context: CompilerContext,
|
37
|
-
transforms: RelayCompilerTransforms,
|
38
|
-
reporter?: Reporter,
|
39
|
-
): CompilerContext {
|
40
|
-
// The fragment is used for reading data from the normalized store.
|
41
|
-
return context.applyTransforms(
|
42
|
-
[...transforms.commonTransforms, ...transforms.fragmentTransforms],
|
43
|
-
reporter,
|
44
|
-
);
|
45
|
-
}
|
46
|
-
|
47
|
-
function createPrintContext(
|
48
|
-
context: CompilerContext,
|
49
|
-
transforms: RelayCompilerTransforms,
|
50
|
-
reporter?: Reporter,
|
51
|
-
): CompilerContext {
|
52
|
-
// The unflattened query is used for printing, since flattening creates an
|
53
|
-
// invalid query.
|
54
|
-
return context.applyTransforms(
|
55
|
-
[
|
56
|
-
...transforms.commonTransforms,
|
57
|
-
...transforms.queryTransforms,
|
58
|
-
...transforms.printTransforms,
|
59
|
-
],
|
60
|
-
reporter,
|
61
|
-
);
|
62
|
-
}
|
63
|
-
|
64
|
-
function createCodeGenContext(
|
65
|
-
context: CompilerContext,
|
66
|
-
transforms: RelayCompilerTransforms,
|
67
|
-
reporter?: Reporter,
|
68
|
-
): CompilerContext {
|
69
|
-
// The flattened query is used for codegen in order to reduce the number of
|
70
|
-
// duplicate fields that must be processed during response normalization.
|
71
|
-
return context.applyTransforms(
|
72
|
-
[
|
73
|
-
...transforms.commonTransforms,
|
74
|
-
...transforms.queryTransforms,
|
75
|
-
...transforms.codegenTransforms,
|
76
|
-
],
|
77
|
-
reporter,
|
78
|
-
);
|
79
|
-
}
|
80
|
-
|
81
|
-
function compile(
|
82
|
-
context: CompilerContext,
|
83
|
-
fragmentContext: CompilerContext,
|
84
|
-
printContext: CompilerContext,
|
85
|
-
codeGenContext: CompilerContext,
|
86
|
-
): $ReadOnlyArray<[GeneratedDefinition, GeneratedNode]> {
|
87
|
-
const results = [];
|
88
|
-
const schema = context.getSchema();
|
89
|
-
|
90
|
-
// Add everything from codeGenContext, these are the operations as well as
|
91
|
-
// SplitOperations from @match.
|
92
|
-
for (const node of codeGenContext.documents()) {
|
93
|
-
if (node.kind === 'Root') {
|
94
|
-
const fragment = fragmentContext.getRoot(node.name);
|
95
|
-
const request = {
|
96
|
-
kind: 'Request',
|
97
|
-
fragment: {
|
98
|
-
kind: 'Fragment',
|
99
|
-
argumentDefinitions: fragment.argumentDefinitions,
|
100
|
-
directives: fragment.directives,
|
101
|
-
loc: {kind: 'Derived', source: node.loc},
|
102
|
-
metadata: null,
|
103
|
-
name: fragment.name,
|
104
|
-
selections: fragment.selections,
|
105
|
-
type: fragment.type,
|
106
|
-
},
|
107
|
-
id: null,
|
108
|
-
loc: node.loc,
|
109
|
-
metadata: node.metadata || {},
|
110
|
-
name: fragment.name,
|
111
|
-
root: node,
|
112
|
-
text: printOperation(printContext, fragment.name),
|
113
|
-
};
|
114
|
-
results.push([request, RelayCodeGenerator.generate(schema, request)]);
|
115
|
-
} else {
|
116
|
-
results.push([node, RelayCodeGenerator.generate(schema, node)]);
|
117
|
-
}
|
118
|
-
}
|
119
|
-
|
120
|
-
// Add all the Fragments from the fragmentContext for the reader ASTs.
|
121
|
-
for (const node of fragmentContext.documents()) {
|
122
|
-
if (node.kind === 'Fragment') {
|
123
|
-
results.push([node, RelayCodeGenerator.generate(schema, node)]);
|
124
|
-
}
|
125
|
-
}
|
126
|
-
return results;
|
127
|
-
}
|
128
|
-
|
129
|
-
const OPERATION_ORDER = {
|
130
|
-
Root: 0,
|
131
|
-
SplitOperation: 1,
|
132
|
-
Fragment: 2,
|
133
|
-
};
|
134
|
-
function printOperation(printContext: CompilerContext, name: string): string {
|
135
|
-
const printableRoot = printContext.getRoot(name);
|
136
|
-
return filterContextForNode(printableRoot, printContext)
|
137
|
-
.documents()
|
138
|
-
.sort((a, b) => {
|
139
|
-
if (a.kind !== b.kind) {
|
140
|
-
return OPERATION_ORDER[a.kind] - OPERATION_ORDER[b.kind];
|
141
|
-
}
|
142
|
-
return a.name < b.name ? -1 : 1;
|
143
|
-
})
|
144
|
-
.map(doc => Printer.print(printContext.getSchema(), doc))
|
145
|
-
.join('\n');
|
146
|
-
}
|
147
|
-
|
148
|
-
/**
|
149
|
-
* Transforms the provided compiler context
|
150
|
-
*
|
151
|
-
* compileRelayArtifacts generates artifacts for Relay's runtime as a result of
|
152
|
-
* applying a series of transforms. Each kind of artifact is dependent on
|
153
|
-
* transforms being applied in the following order:
|
154
|
-
*
|
155
|
-
* - Fragment Readers: commonTransforms, fragmentTransforms
|
156
|
-
* - Operation Writers: commonTransforms, queryTransforms, codegenTransforms
|
157
|
-
* - GraphQL Text: commonTransforms, queryTransforms, printTransforms
|
158
|
-
*
|
159
|
-
* The order of the transforms applied for each artifact below is important.
|
160
|
-
* CompilerContext will memoize applying each transform, so while
|
161
|
-
* `commonTransforms` appears in each artifacts' application, it will not result
|
162
|
-
* in repeated work as long as the order remains consistent across each context.
|
163
|
-
*/
|
164
|
-
function compileRelayArtifacts(
|
165
|
-
context: CompilerContext,
|
166
|
-
transforms: RelayCompilerTransforms,
|
167
|
-
reporter?: Reporter,
|
168
|
-
): $ReadOnlyArray<[GeneratedDefinition, GeneratedNode]> {
|
169
|
-
return Profiler.run('GraphQLCompiler.compile', () => {
|
170
|
-
const fragmentContext = createFragmentContext(
|
171
|
-
context,
|
172
|
-
transforms,
|
173
|
-
reporter,
|
174
|
-
);
|
175
|
-
const printContext = createPrintContext(context, transforms, reporter);
|
176
|
-
const codeGenContext = createCodeGenContext(context, transforms, reporter);
|
177
|
-
return compile(context, fragmentContext, printContext, codeGenContext);
|
178
|
-
});
|
179
|
-
}
|
180
|
-
|
181
|
-
module.exports = compileRelayArtifacts;
|
@@ -1,19 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
6
|
-
*
|
7
|
-
* @flow strict
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
|
13
|
-
'use strict';
|
14
|
-
|
15
|
-
function createPrintRequireModuleDependency(): string => string {
|
16
|
-
return moduleName => `require('./${moduleName}')`;
|
17
|
-
}
|
18
|
-
|
19
|
-
module.exports = createPrintRequireModuleDependency;
|
@@ -1,25 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
6
|
-
*
|
7
|
-
* @flow strict-local
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
|
11
|
-
'use strict';
|
12
|
-
|
13
|
-
function sortObjectByKey<T: ?{[key: string]: mixed}>(obj: T): T {
|
14
|
-
if (obj == null) {
|
15
|
-
return obj;
|
16
|
-
}
|
17
|
-
const result = {};
|
18
|
-
for (const key of Object.keys(obj).sort()) {
|
19
|
-
result[key] = obj[key];
|
20
|
-
}
|
21
|
-
// $FlowFixMe[incompatible-return]
|
22
|
-
return result;
|
23
|
-
}
|
24
|
-
|
25
|
-
module.exports = sortObjectByKey;
|