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.
Files changed (263) hide show
  1. package/cli.js +23 -0
  2. package/index.js +19 -3
  3. package/linux-x64/relay +0 -0
  4. package/macos-x64/relay +0 -0
  5. package/package.json +2 -24
  6. package/win-x64/relay.exe +0 -0
  7. package/bin/RelayCompilerBin.js.flow +0 -168
  8. package/bin/RelayCompilerMain.js.flow +0 -515
  9. package/bin/__fixtures__/plugin-module.js.flow +0 -17
  10. package/bin/relay-compiler +0 -19068
  11. package/codegen/CodegenDirectory.js.flow +0 -372
  12. package/codegen/CodegenRunner.js.flow +0 -424
  13. package/codegen/CodegenTypes.js.flow +0 -28
  14. package/codegen/CodegenWatcher.js.flow +0 -250
  15. package/codegen/NormalizationCodeGenerator.js.flow +0 -566
  16. package/codegen/ReaderCodeGenerator.js.flow +0 -510
  17. package/codegen/RelayCodeGenerator.js.flow +0 -85
  18. package/codegen/RelayFileWriter.js.flow +0 -365
  19. package/codegen/SourceControl.js.flow +0 -58
  20. package/codegen/compileRelayArtifacts.js.flow +0 -181
  21. package/codegen/createPrintRequireModuleDependency.js.flow +0 -19
  22. package/codegen/sortObjectByKey.js.flow +0 -25
  23. package/codegen/writeRelayGeneratedFile.js.flow +0 -235
  24. package/core/ASTCache.js.flow +0 -73
  25. package/core/ASTConvert.js.flow +0 -230
  26. package/core/CompilerContext.js.flow +0 -189
  27. package/core/CompilerError.js.flow +0 -255
  28. package/core/DotGraphQLParser.js.flow +0 -37
  29. package/core/GraphQLCompilerProfiler.js.flow +0 -341
  30. package/core/GraphQLDerivedFromMetadata.js.flow +0 -36
  31. package/core/GraphQLWatchmanClient.js.flow +0 -109
  32. package/core/IR.js.flow +0 -326
  33. package/core/IRPrinter.js.flow +0 -472
  34. package/core/IRTransformer.js.flow +0 -376
  35. package/core/IRValidator.js.flow +0 -259
  36. package/core/IRVisitor.js.flow +0 -150
  37. package/core/JSModuleParser.js.flow +0 -24
  38. package/core/RelayCompilerScope.js.flow +0 -199
  39. package/core/RelayFindGraphQLTags.js.flow +0 -118
  40. package/core/RelayGraphQLEnumsGenerator.js.flow +0 -55
  41. package/core/RelayIRTransforms.js.flow +0 -138
  42. package/core/RelayParser.js.flow +0 -1741
  43. package/core/RelaySourceModuleParser.js.flow +0 -133
  44. package/core/Schema.js.flow +0 -2035
  45. package/core/SchemaUtils.js.flow +0 -120
  46. package/core/filterContextForNode.js.flow +0 -49
  47. package/core/getFieldDefinition.js.flow +0 -156
  48. package/core/getIdentifierForArgumentValue.js.flow +0 -49
  49. package/core/getIdentifierForSelection.js.flow +0 -68
  50. package/core/getLiteralArgumentValues.js.flow +0 -32
  51. package/core/getNormalizationOperationName.js.flow +0 -19
  52. package/core/inferRootArgumentDefinitions.js.flow +0 -322
  53. package/index.js.flow +0 -198
  54. package/language/RelayLanguagePluginInterface.js.flow +0 -283
  55. package/language/javascript/FindGraphQLTags.js.flow +0 -136
  56. package/language/javascript/RelayFlowBabelFactories.js.flow +0 -176
  57. package/language/javascript/RelayFlowGenerator.js.flow +0 -1096
  58. package/language/javascript/RelayFlowTypeTransformers.js.flow +0 -181
  59. package/language/javascript/RelayLanguagePluginJavaScript.js.flow +0 -33
  60. package/language/javascript/formatGeneratedModule.js.flow +0 -65
  61. package/lib/bin/RelayCompilerBin.js +0 -143
  62. package/lib/bin/RelayCompilerMain.js +0 -488
  63. package/lib/bin/__fixtures__/plugin-module.js +0 -16
  64. package/lib/codegen/CodegenDirectory.js +0 -335
  65. package/lib/codegen/CodegenRunner.js +0 -433
  66. package/lib/codegen/CodegenTypes.js +0 -11
  67. package/lib/codegen/CodegenWatcher.js +0 -271
  68. package/lib/codegen/NormalizationCodeGenerator.js +0 -487
  69. package/lib/codegen/ReaderCodeGenerator.js +0 -473
  70. package/lib/codegen/RelayCodeGenerator.js +0 -75
  71. package/lib/codegen/RelayFileWriter.js +0 -270
  72. package/lib/codegen/SourceControl.js +0 -60
  73. package/lib/codegen/compileRelayArtifacts.js +0 -157
  74. package/lib/codegen/createPrintRequireModuleDependency.js +0 -19
  75. package/lib/codegen/sortObjectByKey.js +0 -41
  76. package/lib/codegen/writeRelayGeneratedFile.js +0 -206
  77. package/lib/core/ASTCache.js +0 -70
  78. package/lib/core/ASTConvert.js +0 -198
  79. package/lib/core/CompilerContext.js +0 -165
  80. package/lib/core/CompilerError.js +0 -252
  81. package/lib/core/DotGraphQLParser.js +0 -40
  82. package/lib/core/GraphQLCompilerProfiler.js +0 -299
  83. package/lib/core/GraphQLDerivedFromMetadata.js +0 -31
  84. package/lib/core/GraphQLWatchmanClient.js +0 -150
  85. package/lib/core/IR.js +0 -11
  86. package/lib/core/IRPrinter.js +0 -388
  87. package/lib/core/IRTransformer.js +0 -345
  88. package/lib/core/IRValidator.js +0 -226
  89. package/lib/core/IRVisitor.js +0 -45
  90. package/lib/core/JSModuleParser.js +0 -18
  91. package/lib/core/RelayCompilerScope.js +0 -183
  92. package/lib/core/RelayFindGraphQLTags.js +0 -79
  93. package/lib/core/RelayGraphQLEnumsGenerator.js +0 -50
  94. package/lib/core/RelayIRTransforms.js +0 -109
  95. package/lib/core/RelayParser.js +0 -1381
  96. package/lib/core/RelaySourceModuleParser.js +0 -104
  97. package/lib/core/Schema.js +0 -1877
  98. package/lib/core/SchemaUtils.js +0 -98
  99. package/lib/core/filterContextForNode.js +0 -50
  100. package/lib/core/getFieldDefinition.js +0 -145
  101. package/lib/core/getIdentifierForArgumentValue.js +0 -54
  102. package/lib/core/getIdentifierForSelection.js +0 -49
  103. package/lib/core/getLiteralArgumentValues.js +0 -26
  104. package/lib/core/getNormalizationOperationName.js +0 -17
  105. package/lib/core/inferRootArgumentDefinitions.js +0 -351
  106. package/lib/index.js +0 -178
  107. package/lib/language/RelayLanguagePluginInterface.js +0 -26
  108. package/lib/language/javascript/FindGraphQLTags.js +0 -126
  109. package/lib/language/javascript/RelayFlowBabelFactories.js +0 -160
  110. package/lib/language/javascript/RelayFlowGenerator.js +0 -856
  111. package/lib/language/javascript/RelayFlowTypeTransformers.js +0 -119
  112. package/lib/language/javascript/RelayLanguagePluginJavaScript.js +0 -30
  113. package/lib/language/javascript/formatGeneratedModule.js +0 -36
  114. package/lib/reporters/ConsoleReporter.js +0 -61
  115. package/lib/reporters/MultiReporter.js +0 -45
  116. package/lib/reporters/Reporter.js +0 -11
  117. package/lib/runner/Artifacts.js +0 -323
  118. package/lib/runner/BufferedFilesystem.js +0 -262
  119. package/lib/runner/GraphQLASTNodeGroup.js +0 -256
  120. package/lib/runner/GraphQLASTUtils.js +0 -23
  121. package/lib/runner/GraphQLNodeMap.js +0 -81
  122. package/lib/runner/Sources.js +0 -271
  123. package/lib/runner/StrictMap.js +0 -134
  124. package/lib/runner/compileArtifacts.js +0 -39
  125. package/lib/runner/extractAST.js +0 -77
  126. package/lib/runner/getChangedNodeNames.js +0 -82
  127. package/lib/runner/getSchemaInstance.js +0 -30
  128. package/lib/runner/types.js +0 -12
  129. package/lib/test-utils/TestSchema.js +0 -27
  130. package/lib/test-utils/parseGraphQLText.js +0 -30
  131. package/lib/transforms/ApplyFragmentArgumentTransform.js +0 -393
  132. package/lib/transforms/ClientExtensionsTransform.js +0 -221
  133. package/lib/transforms/ConnectionTransform.js +0 -639
  134. package/lib/transforms/DeclarativeConnectionMutationTransform.js +0 -218
  135. package/lib/transforms/DeferStreamTransform.js +0 -246
  136. package/lib/transforms/DisallowIdAsAlias.js +0 -40
  137. package/lib/transforms/DisallowTypenameOnRoot.js +0 -53
  138. package/lib/transforms/FieldHandleTransform.js +0 -79
  139. package/lib/transforms/FilterCompilerDirectivesTransform.js +0 -29
  140. package/lib/transforms/FilterDirectivesTransform.js +0 -42
  141. package/lib/transforms/FlattenTransform.js +0 -306
  142. package/lib/transforms/GenerateIDFieldTransform.js +0 -135
  143. package/lib/transforms/GenerateTypeNameTransform.js +0 -149
  144. package/lib/transforms/InlineDataFragmentTransform.js +0 -100
  145. package/lib/transforms/InlineFragmentsTransform.js +0 -61
  146. package/lib/transforms/MaskTransform.js +0 -117
  147. package/lib/transforms/MatchTransform.js +0 -434
  148. package/lib/transforms/ReactFlightComponentTransform.js +0 -158
  149. package/lib/transforms/RefetchableFragmentTransform.js +0 -249
  150. package/lib/transforms/RelayDirectiveTransform.js +0 -83
  151. package/lib/transforms/RequiredFieldTransform.js +0 -369
  152. package/lib/transforms/SkipClientExtensionsTransform.js +0 -46
  153. package/lib/transforms/SkipHandleFieldTransform.js +0 -45
  154. package/lib/transforms/SkipRedundantNodesTransform.js +0 -261
  155. package/lib/transforms/SkipSplitOperationTransform.js +0 -32
  156. package/lib/transforms/SkipUnreachableNodeTransform.js +0 -158
  157. package/lib/transforms/SkipUnusedVariablesTransform.js +0 -75
  158. package/lib/transforms/SplitModuleImportTransform.js +0 -82
  159. package/lib/transforms/TestOperationTransform.js +0 -144
  160. package/lib/transforms/TransformUtils.js +0 -21
  161. package/lib/transforms/ValidateGlobalVariablesTransform.js +0 -92
  162. package/lib/transforms/ValidateRequiredArgumentsTransform.js +0 -114
  163. package/lib/transforms/ValidateServerOnlyDirectivesTransform.js +0 -108
  164. package/lib/transforms/ValidateUnusedVariablesTransform.js +0 -96
  165. package/lib/transforms/query-generators/FetchableQueryGenerator.js +0 -157
  166. package/lib/transforms/query-generators/NodeQueryGenerator.js +0 -166
  167. package/lib/transforms/query-generators/QueryQueryGenerator.js +0 -48
  168. package/lib/transforms/query-generators/ViewerQueryGenerator.js +0 -77
  169. package/lib/transforms/query-generators/index.js +0 -60
  170. package/lib/transforms/query-generators/utils.js +0 -92
  171. package/lib/util/CodeMarker.js +0 -80
  172. package/lib/util/DefaultHandleKey.js +0 -15
  173. package/lib/util/RelayCompilerCache.js +0 -97
  174. package/lib/util/Rollout.js +0 -40
  175. package/lib/util/TimeReporter.js +0 -83
  176. package/lib/util/areEqualArgValues.js +0 -135
  177. package/lib/util/argumentContainsVariables.js +0 -37
  178. package/lib/util/dedupeJSONStringify.js +0 -160
  179. package/lib/util/generateAbstractTypeRefinementKey.js +0 -24
  180. package/lib/util/getDefinitionNodeHash.js +0 -22
  181. package/lib/util/getModuleName.js +0 -32
  182. package/lib/util/joinArgumentDefinitions.js +0 -67
  183. package/lib/util/md5.js +0 -17
  184. package/lib/util/murmurHash.js +0 -86
  185. package/lib/util/nullthrowsOSS.js +0 -23
  186. package/lib/util/orList.js +0 -36
  187. package/lib/util/partitionArray.js +0 -35
  188. package/relay-compiler.js +0 -17
  189. package/relay-compiler.min.js +0 -22
  190. package/reporters/ConsoleReporter.js.flow +0 -81
  191. package/reporters/MultiReporter.js.flow +0 -43
  192. package/reporters/Reporter.js.flow +0 -19
  193. package/runner/Artifacts.js.flow +0 -215
  194. package/runner/BufferedFilesystem.js.flow +0 -194
  195. package/runner/GraphQLASTNodeGroup.js.flow +0 -174
  196. package/runner/GraphQLASTUtils.js.flow +0 -26
  197. package/runner/GraphQLNodeMap.js.flow +0 -55
  198. package/runner/Sources.js.flow +0 -227
  199. package/runner/StrictMap.js.flow +0 -96
  200. package/runner/compileArtifacts.js.flow +0 -75
  201. package/runner/extractAST.js.flow +0 -98
  202. package/runner/getChangedNodeNames.js.flow +0 -48
  203. package/runner/getSchemaInstance.js.flow +0 -36
  204. package/runner/types.js.flow +0 -37
  205. package/test-utils/TestSchema.js.flow +0 -30
  206. package/test-utils/parseGraphQLText.js.flow +0 -41
  207. package/transforms/ApplyFragmentArgumentTransform.js.flow +0 -524
  208. package/transforms/ClientExtensionsTransform.js.flow +0 -224
  209. package/transforms/ConnectionTransform.js.flow +0 -850
  210. package/transforms/DeclarativeConnectionMutationTransform.js.flow +0 -245
  211. package/transforms/DeferStreamTransform.js.flow +0 -263
  212. package/transforms/DisallowIdAsAlias.js.flow +0 -46
  213. package/transforms/DisallowTypenameOnRoot.js.flow +0 -44
  214. package/transforms/FieldHandleTransform.js.flow +0 -77
  215. package/transforms/FilterCompilerDirectivesTransform.js.flow +0 -33
  216. package/transforms/FilterDirectivesTransform.js.flow +0 -45
  217. package/transforms/FlattenTransform.js.flow +0 -458
  218. package/transforms/GenerateIDFieldTransform.js.flow +0 -151
  219. package/transforms/GenerateTypeNameTransform.js.flow +0 -159
  220. package/transforms/InlineDataFragmentTransform.js.flow +0 -123
  221. package/transforms/InlineFragmentsTransform.js.flow +0 -70
  222. package/transforms/MaskTransform.js.flow +0 -124
  223. package/transforms/MatchTransform.js.flow +0 -587
  224. package/transforms/ReactFlightComponentTransform.js.flow +0 -207
  225. package/transforms/RefetchableFragmentTransform.js.flow +0 -266
  226. package/transforms/RelayDirectiveTransform.js.flow +0 -96
  227. package/transforms/RequiredFieldTransform.js.flow +0 -413
  228. package/transforms/SkipClientExtensionsTransform.js.flow +0 -54
  229. package/transforms/SkipHandleFieldTransform.js.flow +0 -44
  230. package/transforms/SkipRedundantNodesTransform.js.flow +0 -277
  231. package/transforms/SkipSplitOperationTransform.js.flow +0 -37
  232. package/transforms/SkipUnreachableNodeTransform.js.flow +0 -148
  233. package/transforms/SkipUnusedVariablesTransform.js.flow +0 -59
  234. package/transforms/SplitModuleImportTransform.js.flow +0 -97
  235. package/transforms/TestOperationTransform.js.flow +0 -142
  236. package/transforms/TransformUtils.js.flow +0 -26
  237. package/transforms/ValidateGlobalVariablesTransform.js.flow +0 -80
  238. package/transforms/ValidateRequiredArgumentsTransform.js.flow +0 -130
  239. package/transforms/ValidateServerOnlyDirectivesTransform.js.flow +0 -128
  240. package/transforms/ValidateUnusedVariablesTransform.js.flow +0 -88
  241. package/transforms/query-generators/FetchableQueryGenerator.js.flow +0 -188
  242. package/transforms/query-generators/NodeQueryGenerator.js.flow +0 -217
  243. package/transforms/query-generators/QueryQueryGenerator.js.flow +0 -57
  244. package/transforms/query-generators/ViewerQueryGenerator.js.flow +0 -97
  245. package/transforms/query-generators/index.js.flow +0 -89
  246. package/transforms/query-generators/utils.js.flow +0 -76
  247. package/util/CodeMarker.js.flow +0 -79
  248. package/util/DefaultHandleKey.js.flow +0 -17
  249. package/util/RelayCompilerCache.js.flow +0 -86
  250. package/util/Rollout.js.flow +0 -39
  251. package/util/TimeReporter.js.flow +0 -79
  252. package/util/areEqualArgValues.js.flow +0 -126
  253. package/util/argumentContainsVariables.js.flow +0 -38
  254. package/util/dedupeJSONStringify.js.flow +0 -156
  255. package/util/generateAbstractTypeRefinementKey.js.flow +0 -29
  256. package/util/getDefinitionNodeHash.js.flow +0 -24
  257. package/util/getModuleName.js.flow +0 -39
  258. package/util/joinArgumentDefinitions.js.flow +0 -105
  259. package/util/md5.js.flow +0 -19
  260. package/util/murmurHash.js.flow +0 -94
  261. package/util/nullthrowsOSS.js.flow +0 -25
  262. package/util/orList.js.flow +0 -37
  263. 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;
@@ -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;
@@ -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;