relay-compiler 0.0.0-main-8ff54d69 → 0.0.0-main-4467ae84
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,174 +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
|
-
* @format
|
8
|
-
* @flow strict-local
|
9
|
-
*/
|
10
|
-
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
|
13
|
-
'use strict';
|
14
|
-
|
15
|
-
import type {ExecutableDefinitionNode} from 'graphql';
|
16
|
-
|
17
|
-
const {getName} = require('./GraphQLASTUtils');
|
18
|
-
const GraphQLNodeMap = require('./GraphQLNodeMap');
|
19
|
-
const {visit} = require('graphql');
|
20
|
-
|
21
|
-
type DependencyMap = Map<string, Array<string>>;
|
22
|
-
|
23
|
-
export type NodeGroup = {|
|
24
|
-
+nodes: GraphQLNodeMap,
|
25
|
-
+baseNames: Set<string>,
|
26
|
-
|};
|
27
|
-
|
28
|
-
function buildDependencyMap(nodes: GraphQLNodeMap): DependencyMap {
|
29
|
-
const dependencyMap: DependencyMap = new Map();
|
30
|
-
for (const node of nodes.values()) {
|
31
|
-
const name = getName(node);
|
32
|
-
if (dependencyMap.has(name)) {
|
33
|
-
throw new Error(`Duplicated definition for ${name}`);
|
34
|
-
}
|
35
|
-
dependencyMap.set(name, findIncludedFragments(node));
|
36
|
-
}
|
37
|
-
return dependencyMap;
|
38
|
-
}
|
39
|
-
|
40
|
-
function mergeMaps<T>(maps: $ReadOnlyArray<Map<string, T>>): Map<string, T> {
|
41
|
-
const result = new Map();
|
42
|
-
for (const source of maps) {
|
43
|
-
for (const [key, value] of source.entries()) {
|
44
|
-
if (result.has(key)) {
|
45
|
-
throw new Error(`Duplicate entry for '${key}'.`);
|
46
|
-
}
|
47
|
-
result.set(key, value);
|
48
|
-
}
|
49
|
-
}
|
50
|
-
return result;
|
51
|
-
}
|
52
|
-
|
53
|
-
function forFullBuild(
|
54
|
-
nodes: GraphQLNodeMap,
|
55
|
-
baseNodes: $ReadOnlyArray<GraphQLNodeMap>,
|
56
|
-
): NodeGroup {
|
57
|
-
const dependencyMap = mergeMaps(
|
58
|
-
[nodes, ...baseNodes].map(buildDependencyMap),
|
59
|
-
);
|
60
|
-
const includedNames = includeReachable(new Set(nodes.keys()), dependencyMap);
|
61
|
-
return buildResult(includedNames, nodes, mergeMaps(baseNodes));
|
62
|
-
}
|
63
|
-
|
64
|
-
function forChanges(
|
65
|
-
nodes: GraphQLNodeMap,
|
66
|
-
changedNames: Set<string>,
|
67
|
-
baseNodes: $ReadOnlyArray<GraphQLNodeMap> = [],
|
68
|
-
): NodeGroup {
|
69
|
-
const projectDependencyMap = buildDependencyMap(nodes);
|
70
|
-
const baseDependencyMap = mergeMaps(baseNodes.map(buildDependencyMap));
|
71
|
-
const dependencyMap = mergeMaps([projectDependencyMap, baseDependencyMap]);
|
72
|
-
const invertedDependencyMap = inverseDependencyMap(dependencyMap);
|
73
|
-
const baseNameToNode: Map<string, ExecutableDefinitionNode> =
|
74
|
-
mergeMaps(baseNodes);
|
75
|
-
|
76
|
-
// The first step of the process is to find all ancestors of changed nodes.
|
77
|
-
// And we perform this search on complete dependency map (project + base)
|
78
|
-
const directlyChangedAndAncestors = includeReachable(
|
79
|
-
changedNames,
|
80
|
-
invertedDependencyMap,
|
81
|
-
);
|
82
|
-
// Now, we need to intersect obtained set with the project nodes
|
83
|
-
const directlyChangedRelatedToProject = new Set();
|
84
|
-
for (const node of directlyChangedAndAncestors) {
|
85
|
-
if (nodes.has(node)) {
|
86
|
-
directlyChangedRelatedToProject.add(node);
|
87
|
-
}
|
88
|
-
}
|
89
|
-
|
90
|
-
// Finally, we need to find all descendants of project-related changed nodes
|
91
|
-
// in the complete dependency map (project + base)
|
92
|
-
const allRelated = includeReachable(
|
93
|
-
directlyChangedRelatedToProject,
|
94
|
-
dependencyMap,
|
95
|
-
);
|
96
|
-
|
97
|
-
return buildResult(allRelated, nodes, baseNameToNode);
|
98
|
-
}
|
99
|
-
|
100
|
-
function buildResult(
|
101
|
-
includedNames: Set<string>,
|
102
|
-
nameToNode: Map<string, ExecutableDefinitionNode>,
|
103
|
-
baseNameToNode: Map<string, ExecutableDefinitionNode>,
|
104
|
-
): NodeGroup {
|
105
|
-
const baseNames = new Set();
|
106
|
-
const nodes = [];
|
107
|
-
for (const name of includedNames) {
|
108
|
-
const baseNode = baseNameToNode.get(name);
|
109
|
-
if (baseNode != null) {
|
110
|
-
nodes.push(baseNode);
|
111
|
-
baseNames.add(name);
|
112
|
-
}
|
113
|
-
|
114
|
-
const node = nameToNode.get(name);
|
115
|
-
if (node != null) {
|
116
|
-
nodes.push(node);
|
117
|
-
}
|
118
|
-
}
|
119
|
-
return {
|
120
|
-
baseNames,
|
121
|
-
nodes: GraphQLNodeMap.from(nodes),
|
122
|
-
};
|
123
|
-
}
|
124
|
-
|
125
|
-
function includeReachable(
|
126
|
-
changed: Set<string>,
|
127
|
-
deps: DependencyMap,
|
128
|
-
): Set<string> {
|
129
|
-
const toVisit = Array.from(changed);
|
130
|
-
const visited = new Set();
|
131
|
-
while (toVisit.length > 0) {
|
132
|
-
const current = toVisit.pop();
|
133
|
-
visited.add(current);
|
134
|
-
for (const dep of deps.get(current) || []) {
|
135
|
-
if (!visited.has(dep)) {
|
136
|
-
toVisit.push(dep);
|
137
|
-
}
|
138
|
-
}
|
139
|
-
}
|
140
|
-
return visited;
|
141
|
-
}
|
142
|
-
|
143
|
-
function findIncludedFragments(node: ExecutableDefinitionNode): Array<string> {
|
144
|
-
const result = [];
|
145
|
-
visit(node, {
|
146
|
-
FragmentSpread(spread) {
|
147
|
-
result.push(spread.name.value);
|
148
|
-
},
|
149
|
-
});
|
150
|
-
return result;
|
151
|
-
}
|
152
|
-
|
153
|
-
function inverseDependencyMap(map: DependencyMap): DependencyMap {
|
154
|
-
const invertedMap = new Map();
|
155
|
-
for (const [source, dests] of map.entries()) {
|
156
|
-
const inverseDest = source;
|
157
|
-
for (const dest of dests) {
|
158
|
-
const inverseSource = dest;
|
159
|
-
|
160
|
-
let inverseDests = invertedMap.get(inverseSource);
|
161
|
-
if (inverseDests == null) {
|
162
|
-
inverseDests = [];
|
163
|
-
invertedMap.set(inverseSource, inverseDests);
|
164
|
-
}
|
165
|
-
inverseDests.push(inverseDest);
|
166
|
-
}
|
167
|
-
}
|
168
|
-
return invertedMap;
|
169
|
-
}
|
170
|
-
|
171
|
-
module.exports = {
|
172
|
-
forChanges,
|
173
|
-
forFullBuild,
|
174
|
-
};
|
@@ -1,26 +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
|
-
* @format
|
8
|
-
* @flow strict
|
9
|
-
*/
|
10
|
-
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
|
13
|
-
'use strict';
|
14
|
-
|
15
|
-
import type {ExecutableDefinitionNode} from 'graphql';
|
16
|
-
|
17
|
-
function getName(node: ExecutableDefinitionNode): string {
|
18
|
-
if (node.name == null) {
|
19
|
-
throw new Error('All fragments and operations have to have names in Relay');
|
20
|
-
}
|
21
|
-
return node.name.value;
|
22
|
-
}
|
23
|
-
|
24
|
-
module.exports = {
|
25
|
-
getName,
|
26
|
-
};
|
@@ -1,55 +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
|
-
* @format
|
8
|
-
* @flow strict-local
|
9
|
-
*/
|
10
|
-
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
|
13
|
-
'use strict';
|
14
|
-
|
15
|
-
import type {ExecutableDefinitionNode} from 'graphql';
|
16
|
-
import type {Sources} from 'relay-compiler';
|
17
|
-
|
18
|
-
const {createCompilerError, createUserError} = require('../core/CompilerError');
|
19
|
-
const {getName} = require('./GraphQLASTUtils');
|
20
|
-
|
21
|
-
class GraphQLNodeMap extends Map<string, ExecutableDefinitionNode> {
|
22
|
-
static from(nodes: Iterable<ExecutableDefinitionNode>): GraphQLNodeMap {
|
23
|
-
const result = new GraphQLNodeMap();
|
24
|
-
for (const node of nodes) {
|
25
|
-
const name = getName(node);
|
26
|
-
const prevNode = result.get(name);
|
27
|
-
if (prevNode) {
|
28
|
-
throw createUserError(`Duplicate node named '${name}'`, null, [
|
29
|
-
node,
|
30
|
-
prevNode,
|
31
|
-
]);
|
32
|
-
}
|
33
|
-
result.set(name, node);
|
34
|
-
}
|
35
|
-
return result;
|
36
|
-
}
|
37
|
-
|
38
|
-
static fromSources(
|
39
|
-
sources: Sources<ExecutableDefinitionNode>,
|
40
|
-
): GraphQLNodeMap {
|
41
|
-
return GraphQLNodeMap.from(sources.nodes());
|
42
|
-
}
|
43
|
-
|
44
|
-
enforceGet(name: string): ExecutableDefinitionNode {
|
45
|
-
const node = this.get(name);
|
46
|
-
if (!node) {
|
47
|
-
throw createCompilerError(
|
48
|
-
`GraphQLNodeMap: expected to have a node named ${name}.`,
|
49
|
-
);
|
50
|
-
}
|
51
|
-
return node;
|
52
|
-
}
|
53
|
-
}
|
54
|
-
|
55
|
-
module.exports = GraphQLNodeMap;
|
package/runner/Sources.js.flow
DELETED
@@ -1,227 +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
|
-
* @format
|
8
|
-
* @flow strict-local
|
9
|
-
* @emails oncall+relay
|
10
|
-
*/
|
11
|
-
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
|
-
'use strict';
|
15
|
-
|
16
|
-
import type {ASTRecord} from './extractAST';
|
17
|
-
import type {SavedStateCollection, WatchmanFile} from './types';
|
18
|
-
import type {ASTNode} from 'graphql';
|
19
|
-
|
20
|
-
const md5 = require('../util/md5');
|
21
|
-
const {toASTRecord} = require('./extractAST');
|
22
|
-
const {Source, parse} = require('graphql');
|
23
|
-
const invariant = require('invariant');
|
24
|
-
|
25
|
-
export type GraphQLExtractor<T: ASTNode> = (
|
26
|
-
baseDir: string,
|
27
|
-
file: WatchmanFile,
|
28
|
-
) => ?{|
|
29
|
-
+nodes: $ReadOnlyArray<ASTRecord<T>>,
|
30
|
-
+sources: $ReadOnlyArray<string>,
|
31
|
-
|};
|
32
|
-
|
33
|
-
type ASTNodeWithFile<T: ASTNode> = {|
|
34
|
-
+file: string,
|
35
|
-
+ast: T,
|
36
|
-
|};
|
37
|
-
|
38
|
-
export type SourceChanges<T: ASTNode> = {|
|
39
|
-
+added: $ReadOnlyArray<ASTNodeWithFile<T>>,
|
40
|
-
+removed: $ReadOnlyArray<ASTNodeWithFile<T>>,
|
41
|
-
|};
|
42
|
-
|
43
|
-
type SourcesState = {
|
44
|
-
[filename: string]: {
|
45
|
-
nodes: {[hash: string]: ASTNode, ...},
|
46
|
-
sources: [string],
|
47
|
-
...
|
48
|
-
},
|
49
|
-
...
|
50
|
-
};
|
51
|
-
|
52
|
-
class Sources<T: ASTNode> {
|
53
|
-
_extractFromFile: GraphQLExtractor<T>;
|
54
|
-
_state: SourcesState;
|
55
|
-
|
56
|
-
static fromSavedState({
|
57
|
-
extractFromFile,
|
58
|
-
savedState,
|
59
|
-
}: {|
|
60
|
-
+extractFromFile: GraphQLExtractor<T>,
|
61
|
-
+savedState: SavedStateCollection,
|
62
|
-
|}): Sources<T> {
|
63
|
-
const state = {};
|
64
|
-
for (const {file, sources: savedStateSources} of savedState) {
|
65
|
-
const nodes = {};
|
66
|
-
const sources = [];
|
67
|
-
for (const text of savedStateSources) {
|
68
|
-
const doc = parse(new Source(text, file));
|
69
|
-
invariant(
|
70
|
-
doc.definitions.length,
|
71
|
-
'expected not empty list of definitions',
|
72
|
-
);
|
73
|
-
const entities = doc.definitions.map(node => {
|
74
|
-
return toASTRecord(node);
|
75
|
-
});
|
76
|
-
entities.forEach(astRecord => {
|
77
|
-
nodes[md5(astRecord.text)] = astRecord.ast;
|
78
|
-
});
|
79
|
-
sources.push(text);
|
80
|
-
}
|
81
|
-
state[file] = {
|
82
|
-
nodes,
|
83
|
-
sources,
|
84
|
-
};
|
85
|
-
}
|
86
|
-
return new Sources({
|
87
|
-
extractFromFile,
|
88
|
-
state,
|
89
|
-
});
|
90
|
-
}
|
91
|
-
|
92
|
-
constructor({
|
93
|
-
extractFromFile,
|
94
|
-
state,
|
95
|
-
}: {|
|
96
|
-
extractFromFile: GraphQLExtractor<T>,
|
97
|
-
state: SourcesState,
|
98
|
-
|}) {
|
99
|
-
this._extractFromFile = extractFromFile;
|
100
|
-
this._state = {...state};
|
101
|
-
}
|
102
|
-
|
103
|
-
processChanges(
|
104
|
-
baseDir: string,
|
105
|
-
files: $ReadOnlyArray<WatchmanFile>,
|
106
|
-
): {|
|
107
|
-
+changes: SourceChanges<T>,
|
108
|
-
+sources: Sources<T>,
|
109
|
-
|} {
|
110
|
-
const added = [];
|
111
|
-
const removed = [];
|
112
|
-
const state = {...this._state};
|
113
|
-
|
114
|
-
for (const file of files) {
|
115
|
-
let newDefs;
|
116
|
-
let newSources;
|
117
|
-
try {
|
118
|
-
const extracted = this._extractFromFile(baseDir, file);
|
119
|
-
if (extracted != null) {
|
120
|
-
newDefs = extracted.nodes;
|
121
|
-
newSources = extracted.sources;
|
122
|
-
}
|
123
|
-
} catch (error) {
|
124
|
-
throw new Error(
|
125
|
-
`RelayCompiler: Sources module failed to parse ${file.name}:\n${error.message}`,
|
126
|
-
);
|
127
|
-
}
|
128
|
-
const hasEntry = state.hasOwnProperty(file.name);
|
129
|
-
const oldEntry = state[file.name]?.nodes ?? {};
|
130
|
-
|
131
|
-
// First case, we have new changes in the file
|
132
|
-
// for example changed Query or Fragment
|
133
|
-
if (newDefs != null && newDefs.length > 0) {
|
134
|
-
// We need to add all entities from the changed file to added arrays
|
135
|
-
const newEntry = {};
|
136
|
-
const newTexts = new Set();
|
137
|
-
for (const {ast, text} of newDefs) {
|
138
|
-
const hashedText = md5(text);
|
139
|
-
if (newTexts.has(hashedText)) {
|
140
|
-
let name = 'unknown';
|
141
|
-
switch (ast.kind) {
|
142
|
-
case 'FragmentDefinition':
|
143
|
-
name = ast.name.value;
|
144
|
-
break;
|
145
|
-
case 'OperationDefinition':
|
146
|
-
name = ast.name?.value ?? 'unnamed operation';
|
147
|
-
break;
|
148
|
-
}
|
149
|
-
throw new Error(
|
150
|
-
`Duplicate definition of \`${name}\` in \`${file.name}\``,
|
151
|
-
);
|
152
|
-
}
|
153
|
-
newTexts.add(hashedText);
|
154
|
-
if (hasEntry && oldEntry[hashedText] != null) {
|
155
|
-
// Entity text did not change, so we
|
156
|
-
// don't need to change it in the state
|
157
|
-
newEntry[hashedText] = oldEntry[hashedText];
|
158
|
-
} else {
|
159
|
-
// Here we have completely new text.
|
160
|
-
// We need add it to the `added` changes
|
161
|
-
newEntry[hashedText] = ast;
|
162
|
-
added.push({file: file.name, ast});
|
163
|
-
}
|
164
|
-
}
|
165
|
-
|
166
|
-
// Also, we need to delete all old entities
|
167
|
-
// that are not included in the new changes
|
168
|
-
if (hasEntry) {
|
169
|
-
for (const oldHashedText of Object.keys(oldEntry)) {
|
170
|
-
const ast = oldEntry[oldHashedText];
|
171
|
-
if (!newTexts.has(oldHashedText)) {
|
172
|
-
removed.push({file: file.name, ast});
|
173
|
-
}
|
174
|
-
}
|
175
|
-
}
|
176
|
-
|
177
|
-
// Finally, update the state with the changes
|
178
|
-
state[file.name] = {
|
179
|
-
nodes: newEntry,
|
180
|
-
// $FlowFixMe[incompatible-type]
|
181
|
-
sources: newSources,
|
182
|
-
};
|
183
|
-
} else {
|
184
|
-
// Otherwise, file has been removed or there are no entities in the file
|
185
|
-
if (hasEntry) {
|
186
|
-
// We will put all ASTNodes from current state to removed collection
|
187
|
-
for (const oldHashedText of Object.keys(oldEntry)) {
|
188
|
-
const ast = oldEntry[oldHashedText];
|
189
|
-
removed.push({file: file.name, ast});
|
190
|
-
}
|
191
|
-
delete state[file.name];
|
192
|
-
}
|
193
|
-
}
|
194
|
-
}
|
195
|
-
|
196
|
-
return {
|
197
|
-
// $FlowFixMe[incompatible-return]
|
198
|
-
changes: {added, removed},
|
199
|
-
sources: new Sources({
|
200
|
-
extractFromFile: this._extractFromFile,
|
201
|
-
state,
|
202
|
-
}),
|
203
|
-
};
|
204
|
-
}
|
205
|
-
|
206
|
-
*nodes(): Iterable<T> {
|
207
|
-
for (const file in this._state) {
|
208
|
-
const entry = this._state[file];
|
209
|
-
for (const node of Object.values(entry.nodes)) {
|
210
|
-
yield ((node: $FlowFixMe): T);
|
211
|
-
}
|
212
|
-
}
|
213
|
-
}
|
214
|
-
|
215
|
-
serializeState(): SavedStateCollection {
|
216
|
-
const serializedState = [];
|
217
|
-
for (const file in this._state) {
|
218
|
-
serializedState.push({
|
219
|
-
file,
|
220
|
-
sources: this._state[file].sources,
|
221
|
-
});
|
222
|
-
}
|
223
|
-
return serializedState;
|
224
|
-
}
|
225
|
-
}
|
226
|
-
|
227
|
-
module.exports = Sources;
|
package/runner/StrictMap.js.flow
DELETED
@@ -1,96 +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
|
-
* @emails oncall+relay
|
10
|
-
*/
|
11
|
-
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
|
-
'use strict';
|
15
|
-
|
16
|
-
const invariant = require('invariant');
|
17
|
-
|
18
|
-
export type {StrictMap};
|
19
|
-
|
20
|
-
class StrictMap<K, V> {
|
21
|
-
_map: Map<K, V>;
|
22
|
-
|
23
|
-
constructor(iterable: ?Iterable<[K, V]>): StrictMap<K, V> {
|
24
|
-
this._map = new Map<K, V>(iterable);
|
25
|
-
return this;
|
26
|
-
}
|
27
|
-
|
28
|
-
clear(): void {
|
29
|
-
this._map.clear();
|
30
|
-
}
|
31
|
-
|
32
|
-
delete(key: K): boolean {
|
33
|
-
return this._map.delete(key);
|
34
|
-
}
|
35
|
-
|
36
|
-
entries(): Iterator<[K, V]> {
|
37
|
-
return this._map.entries();
|
38
|
-
}
|
39
|
-
|
40
|
-
forEach(
|
41
|
-
callbackfn: (value: V, index: K, map: Map<K, V>) => mixed,
|
42
|
-
thisArg?: mixed,
|
43
|
-
): void {
|
44
|
-
this._map.forEach(callbackfn, thisArg);
|
45
|
-
}
|
46
|
-
|
47
|
-
map<V2>(
|
48
|
-
f: (value: V, index: K, map: StrictMap<K, V>) => V2,
|
49
|
-
): StrictMap<K, V2> {
|
50
|
-
const result = new StrictMap();
|
51
|
-
for (const [key, val] of this._map) {
|
52
|
-
result.set(key, f(val, key, this));
|
53
|
-
}
|
54
|
-
return result;
|
55
|
-
}
|
56
|
-
|
57
|
-
async asyncMap<V2>(
|
58
|
-
f: (value: V, index: K, map: StrictMap<K, V>) => Promise<V2>,
|
59
|
-
): Promise<StrictMap<K, V2>> {
|
60
|
-
const entryPromises: Array<Promise<[K, V2]>> = [];
|
61
|
-
for (const [key, val] of this._map) {
|
62
|
-
entryPromises.push(f(val, key, this).then(resultVal => [key, resultVal]));
|
63
|
-
}
|
64
|
-
const entries = await Promise.all(entryPromises);
|
65
|
-
return new StrictMap(entries);
|
66
|
-
}
|
67
|
-
|
68
|
-
get(key: K): V {
|
69
|
-
invariant(
|
70
|
-
this.has(key),
|
71
|
-
'StrictMap: trying to read non-existent key `%s`.',
|
72
|
-
String(key),
|
73
|
-
);
|
74
|
-
// $FlowFixMe[incompatible-return] - we checked the key exists
|
75
|
-
return this._map.get(key);
|
76
|
-
}
|
77
|
-
|
78
|
-
has(key: K): boolean {
|
79
|
-
return this._map.has(key);
|
80
|
-
}
|
81
|
-
|
82
|
-
keys(): Iterator<K> {
|
83
|
-
return this._map.keys();
|
84
|
-
}
|
85
|
-
|
86
|
-
set(key: K, value: V): StrictMap<K, V> {
|
87
|
-
this._map.set(key, value);
|
88
|
-
return this;
|
89
|
-
}
|
90
|
-
|
91
|
-
values(): Iterator<V> {
|
92
|
-
return this._map.values();
|
93
|
-
}
|
94
|
-
}
|
95
|
-
|
96
|
-
module.exports = StrictMap;
|
@@ -1,75 +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 {ExecutableDefinitionNode, ValidationContext} from 'graphql';
|
16
|
-
import type {
|
17
|
-
GeneratedDefinition,
|
18
|
-
RelayCompilerTransforms,
|
19
|
-
Reporter,
|
20
|
-
Schema,
|
21
|
-
TypeGenerator,
|
22
|
-
} from 'relay-compiler';
|
23
|
-
import type {GeneratedNode} from 'relay-runtime';
|
24
|
-
|
25
|
-
const compileRelayArtifacts = require('../codegen/compileRelayArtifacts');
|
26
|
-
const ASTConvert = require('../core/ASTConvert');
|
27
|
-
const CompilerContext = require('../core/CompilerContext');
|
28
|
-
const RelayParser = require('../core/RelayParser');
|
29
|
-
|
30
|
-
export type ValidationRule = (context: ValidationContext) => $FlowFixMe;
|
31
|
-
|
32
|
-
function compileArtifacts({
|
33
|
-
schema,
|
34
|
-
compilerTransforms,
|
35
|
-
definitions: inputDefinitions,
|
36
|
-
reporter,
|
37
|
-
typeGenerator,
|
38
|
-
}: {|
|
39
|
-
schema: Schema,
|
40
|
-
compilerTransforms: RelayCompilerTransforms,
|
41
|
-
definitions: $ReadOnlyArray<ExecutableDefinitionNode>,
|
42
|
-
reporter: Reporter,
|
43
|
-
typeGenerator: TypeGenerator,
|
44
|
-
|}): {|
|
45
|
-
artifacts: $ReadOnlyArray<[GeneratedDefinition, GeneratedNode]>,
|
46
|
-
transformedTypeContext: CompilerContext,
|
47
|
-
|} {
|
48
|
-
const definitions = ASTConvert.convertASTDocuments(
|
49
|
-
schema,
|
50
|
-
[
|
51
|
-
{
|
52
|
-
kind: 'Document',
|
53
|
-
definitions: inputDefinitions,
|
54
|
-
},
|
55
|
-
],
|
56
|
-
RelayParser.transform,
|
57
|
-
);
|
58
|
-
|
59
|
-
const compilerContext = new CompilerContext(schema).addAll(definitions);
|
60
|
-
const transformedTypeContext = compilerContext.applyTransforms(
|
61
|
-
typeGenerator.transforms,
|
62
|
-
reporter,
|
63
|
-
);
|
64
|
-
|
65
|
-
return {
|
66
|
-
transformedTypeContext,
|
67
|
-
artifacts: compileRelayArtifacts(
|
68
|
-
compilerContext,
|
69
|
-
compilerTransforms,
|
70
|
-
reporter,
|
71
|
-
),
|
72
|
-
};
|
73
|
-
}
|
74
|
-
|
75
|
-
module.exports = compileArtifacts;
|