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,393 +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
- *
8
- * @format
9
- */
10
- // flowlint ambiguous-object-type:error
11
- 'use strict';
12
-
13
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
14
-
15
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
16
-
17
- var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
18
-
19
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
20
-
21
- var _require = require('../core/CompilerError'),
22
- createCompilerError = _require.createCompilerError,
23
- createNonRecoverableUserError = _require.createNonRecoverableUserError;
24
-
25
- var getIdentifierForArgumentValue = require('../core/getIdentifierForArgumentValue');
26
-
27
- var IRTransformer = require('../core/IRTransformer');
28
-
29
- var RelayCompilerScope = require('../core/RelayCompilerScope');
30
-
31
- var murmurHash = require('../util/murmurHash');
32
-
33
- var getFragmentScope = RelayCompilerScope.getFragmentScope,
34
- getRootScope = RelayCompilerScope.getRootScope;
35
-
36
- /**
37
- * A transform that converts a set of documents containing fragments/fragment
38
- * spreads *with* arguments to one where all arguments have been inlined. This
39
- * is effectively static currying of functions. Nodes are changed as follows:
40
- * - Fragment spreads with arguments are replaced with references to an inlined
41
- * version of the referenced fragment.
42
- * - Fragments with argument definitions are cloned once per unique set of
43
- * arguments, with the name changed to original name + hash and all nested
44
- * variable references changed to the value of that variable given its
45
- * arguments.
46
- * - Field & directive argument variables are replaced with the value of those
47
- * variables in context.
48
- * - All nodes are cloned with updated children.
49
- *
50
- * The transform also handles statically passing/failing Condition nodes:
51
- * - Literal Conditions with a passing value are elided and their selections
52
- * inlined in their parent.
53
- * - Literal Conditions with a failing value are removed.
54
- * - Nodes that would become empty as a result of the above are removed.
55
- *
56
- * Note that unreferenced fragments are not added to the output.
57
- */
58
- function applyFragmentArgumentTransform(context) {
59
- var fragments = new Map();
60
- var nextContext = IRTransformer.transform(context, {
61
- Root: function Root(node) {
62
- var scope = getRootScope(node.argumentDefinitions);
63
- return transformNode(context, fragments, scope, node, [node]);
64
- },
65
- SplitOperation: function SplitOperation(node) {
66
- return transformNode(context, fragments, {}, node, [node]);
67
- },
68
- // Fragments are included below where referenced.
69
- // Unreferenced fragments are not included.
70
- Fragment: function Fragment() {
71
- return null;
72
- }
73
- });
74
-
75
- var _iterator = (0, _createForOfIteratorHelper2["default"])(fragments.values()),
76
- _step;
77
-
78
- try {
79
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
80
- var pendingFragment = _step.value;
81
-
82
- if (pendingFragment.kind === 'resolved' && pendingFragment.value) {
83
- nextContext = nextContext.add(pendingFragment.value);
84
- }
85
- }
86
- } catch (err) {
87
- _iterator.e(err);
88
- } finally {
89
- _iterator.f();
90
- }
91
-
92
- return nextContext;
93
- }
94
-
95
- function transformNode(context, fragments, scope, node, errorContext) {
96
- var selections = transformSelections(context, fragments, scope, node.selections, errorContext);
97
-
98
- if (!selections) {
99
- return null;
100
- }
101
-
102
- if (node.hasOwnProperty('directives')) {
103
- var directives = transformDirectives(scope, node.directives, errorContext);
104
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, node), {}, {
105
- directives: directives,
106
- selections: selections
107
- });
108
- }
109
-
110
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, node), {}, {
111
- selections: selections
112
- });
113
- }
114
-
115
- function transformDeferStreamNode(context, fragments, scope, node, errorContext) {
116
- var nextNode = transformNode(context, fragments, scope, node, errorContext);
117
-
118
- if (!nextNode) {
119
- return null;
120
- }
121
-
122
- nextNode;
123
-
124
- if (nextNode["if"]) {
125
- var ifVal = transformValue(scope, nextNode["if"], errorContext);
126
-
127
- if (ifVal.kind === 'Literal' && ifVal.value === false && node.selections && node.selections.length === 1) {
128
- // Skip Defer/Stream wrapper with literal if: false
129
- return node.selections[0];
130
- } // $FlowFixMe[cannot-write] nextNode is uniquely owned
131
-
132
-
133
- nextNode["if"] = ifVal;
134
- }
135
-
136
- if (nextNode.useCustomizedBatch) {
137
- // $FlowFixMe[cannot-write] nextNode is uniquely owned
138
- nextNode.useCustomizedBatch = transformValue(scope, nextNode.useCustomizedBatch, errorContext);
139
- }
140
-
141
- if (nextNode.initialCount) {
142
- // $FlowFixMe[cannot-write] nextNode is uniquely owned
143
- nextNode.initialCount = transformValue(scope, nextNode.initialCount, errorContext);
144
- }
145
-
146
- return nextNode;
147
- }
148
-
149
- function transformFragmentSpread(context, fragments, scope, spread, errorContext) {
150
- var directives = transformDirectives(scope, spread.directives, errorContext);
151
- var appliedFragment = transformFragment(context, fragments, scope, spread, spread.args, [].concat((0, _toConsumableArray2["default"])(errorContext), [spread]));
152
-
153
- if (!appliedFragment) {
154
- return null;
155
- }
156
-
157
- var transformed = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, spread), {}, {
158
- kind: 'FragmentSpread',
159
- args: [],
160
- directives: directives,
161
- name: appliedFragment.name
162
- });
163
- return transformed;
164
- }
165
-
166
- function transformField(context, fragments, scope, field, errorContext) {
167
- var args = transformArguments(scope, field.args, errorContext);
168
- var directives = transformDirectives(scope, field.directives, errorContext);
169
-
170
- if (field.kind === 'LinkedField') {
171
- var selections = transformSelections(context, fragments, scope, field.selections, errorContext);
172
-
173
- if (!selections) {
174
- return null;
175
- }
176
-
177
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, field), {}, {
178
- args: args,
179
- directives: directives,
180
- selections: selections
181
- });
182
- } else {
183
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, field), {}, {
184
- args: args,
185
- directives: directives
186
- });
187
- }
188
- }
189
-
190
- function transformCondition(context, fragments, scope, node, errorContext) {
191
- var condition = transformValue(scope, node.condition, errorContext);
192
-
193
- if (!(condition.kind === 'Literal' || condition.kind === 'Variable')) {
194
- // This transform does whole-program optimization, errors in
195
- // a single document could break invariants and/or cause
196
- // additional spurious errors.
197
- throw createNonRecoverableUserError('A non-scalar value was applied to an @include or @skip directive, ' + 'the `if` argument value must be a ' + 'variable or a literal Boolean.', [condition.loc]);
198
- }
199
-
200
- if (condition.kind === 'Literal' && condition.value !== node.passingValue) {
201
- // Dead code, no need to traverse further.
202
- return null;
203
- }
204
-
205
- var selections = transformSelections(context, fragments, scope, node.selections, errorContext);
206
-
207
- if (!selections) {
208
- return null;
209
- }
210
-
211
- if (condition.kind === 'Literal' && condition.value === node.passingValue) {
212
- // Always passes, return inlined selections
213
- return selections;
214
- }
215
-
216
- return [(0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, node), {}, {
217
- condition: condition,
218
- selections: selections
219
- })];
220
- }
221
-
222
- function transformSelections(context, fragments, scope, selections, errorContext) {
223
- var nextSelections = null;
224
- selections.forEach(function (selection) {
225
- var nextSelection;
226
-
227
- if (selection.kind === 'ClientExtension' || selection.kind === 'InlineDataFragmentSpread' || selection.kind === 'InlineFragment' || selection.kind === 'ModuleImport') {
228
- nextSelection = transformNode(context, fragments, scope, selection, errorContext);
229
- } else if (selection.kind === 'Defer' || selection.kind === 'Stream') {
230
- nextSelection = transformDeferStreamNode(context, fragments, scope, selection, errorContext);
231
- } else if (selection.kind === 'FragmentSpread') {
232
- nextSelection = transformFragmentSpread(context, fragments, scope, selection, errorContext);
233
- } else if (selection.kind === 'Condition') {
234
- var conditionSelections = transformCondition(context, fragments, scope, selection, errorContext);
235
-
236
- if (conditionSelections) {
237
- var _nextSelections;
238
-
239
- nextSelections = nextSelections || [];
240
-
241
- (_nextSelections = nextSelections).push.apply(_nextSelections, (0, _toConsumableArray2["default"])(conditionSelections));
242
- }
243
- } else if (selection.kind === 'LinkedField' || selection.kind === 'ScalarField') {
244
- nextSelection = transformField(context, fragments, scope, selection, errorContext);
245
- } else {
246
- selection;
247
- throw createCompilerError("ApplyFragmentArgumentTransform: Unsupported kind '".concat(selection.kind, "'."), [selection.loc]);
248
- }
249
-
250
- if (nextSelection) {
251
- nextSelections = nextSelections || [];
252
- nextSelections.push(nextSelection);
253
- }
254
- });
255
- return nextSelections;
256
- }
257
-
258
- function transformDirectives(scope, directives, errorContext) {
259
- return directives.map(function (directive) {
260
- var args = transformArguments(scope, directive.args, errorContext);
261
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, directive), {}, {
262
- args: args
263
- });
264
- });
265
- }
266
-
267
- function transformArguments(scope, args, errorContext) {
268
- return args.map(function (arg) {
269
- var value = transformValue(scope, arg.value, errorContext);
270
- return value === arg.value ? arg : (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, arg), {}, {
271
- value: value
272
- });
273
- });
274
- }
275
-
276
- function transformValue(scope, value, errorContext) {
277
- if (value.kind === 'Variable') {
278
- var scopeValue = scope[value.variableName];
279
-
280
- if (scopeValue == null) {
281
- var _errorContext$;
282
-
283
- // This transform does whole-program optimization, errors in
284
- // a single document could break invariants and/or cause
285
- // additional spurious errors.
286
- throw createNonRecoverableUserError("Variable '$".concat(value.variableName, "' is not in scope."), [(_errorContext$ = errorContext[0]) === null || _errorContext$ === void 0 ? void 0 : _errorContext$.loc, value.loc].filter(Boolean));
287
- }
288
-
289
- return scopeValue;
290
- } else if (value.kind === 'ObjectValue') {
291
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, value), {}, {
292
- fields: value.fields.map(function (field) {
293
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, field), {}, {
294
- value: transformValue(scope, field.value, errorContext)
295
- });
296
- })
297
- });
298
- } else if (value.kind === 'ListValue') {
299
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, value), {}, {
300
- items: value.items.map(function (item) {
301
- return transformValue(scope, item, errorContext);
302
- })
303
- });
304
- }
305
-
306
- return value;
307
- }
308
- /**
309
- * Apply arguments to a fragment, creating a new fragment (with the given name)
310
- * with all values recursively applied.
311
- */
312
-
313
-
314
- function transformFragment(context, fragments, parentScope, spread, args, errorContext) {
315
- var schema = context.getSchema();
316
- var fragment = context.getFragment(spread.name, spread.loc);
317
- var argumentsHash = hashArguments(args, parentScope, errorContext);
318
- var fragmentName = argumentsHash ? "".concat(fragment.name, "_").concat(argumentsHash) : fragment.name;
319
- var appliedFragment = fragments.get(fragmentName);
320
-
321
- if (appliedFragment) {
322
- if (appliedFragment.kind === 'resolved') {
323
- return appliedFragment.value;
324
- } else {
325
- // This transform does whole-program optimization, errors in
326
- // a single document could break invariants and/or cause
327
- // additional spurious errors.
328
- throw createNonRecoverableUserError("Found a circular reference from fragment '".concat(fragment.name, "'."), errorContext.map(function (node) {
329
- return node.loc;
330
- }));
331
- }
332
- }
333
-
334
- var fragmentScope = getFragmentScope(schema, fragment.argumentDefinitions, args, parentScope, spread); // record that this fragment is pending to detect circular references
335
-
336
- fragments.set(fragmentName, {
337
- kind: 'pending'
338
- });
339
- var transformedFragment = null;
340
- var selections = transformSelections(context, fragments, fragmentScope, fragment.selections, errorContext);
341
-
342
- if (selections) {
343
- transformedFragment = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, fragment), {}, {
344
- selections: selections,
345
- name: fragmentName,
346
- argumentDefinitions: []
347
- });
348
- }
349
-
350
- fragments.set(fragmentName, {
351
- kind: 'resolved',
352
- value: transformedFragment
353
- });
354
- return transformedFragment;
355
- }
356
-
357
- function hashArguments(args, scope, errorContext) {
358
- if (!args.length) {
359
- return null;
360
- }
361
-
362
- var sortedArgs = (0, _toConsumableArray2["default"])(args).sort(function (a, b) {
363
- return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
364
- });
365
- var printedArgs = JSON.stringify(sortedArgs.map(function (arg) {
366
- var value;
367
-
368
- if (arg.value.kind === 'Variable') {
369
- value = scope[arg.value.variableName];
370
-
371
- if (value == null) {
372
- var _errorContext$2;
373
-
374
- // This transform does whole-program optimization, errors in
375
- // a single document could break invariants and/or cause
376
- // additional spurious errors.
377
- throw createNonRecoverableUserError("Variable '$".concat(arg.value.variableName, "' is not in scope."), [(_errorContext$2 = errorContext[0]) === null || _errorContext$2 === void 0 ? void 0 : _errorContext$2.loc, arg.value.loc].filter(Boolean));
378
- }
379
- } else {
380
- value = arg.value;
381
- }
382
-
383
- return {
384
- name: arg.name,
385
- value: getIdentifierForArgumentValue(value)
386
- };
387
- }));
388
- return murmurHash(printedArgs);
389
- }
390
-
391
- module.exports = {
392
- transform: applyFragmentArgumentTransform
393
- };
@@ -1,221 +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
- *
8
- * @format
9
- */
10
- // flowlint ambiguous-object-type:error
11
- 'use strict';
12
-
13
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
14
-
15
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
16
-
17
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
18
-
19
- var _require = require('../core/CompilerError'),
20
- createCompilerError = _require.createCompilerError,
21
- createUserError = _require.createUserError;
22
-
23
- var IRTransformer = require('../core/IRTransformer');
24
-
25
- var cachesByNode = new Map();
26
-
27
- function clientExtensionTransform(context) {
28
- cachesByNode = new Map();
29
- return IRTransformer.transform(context, {
30
- Fragment: traverseDefinition,
31
- Root: traverseDefinition,
32
- SplitOperation: traverseDefinition
33
- });
34
- }
35
-
36
- function traverseDefinition(node) {
37
- var compilerContext = this.getContext();
38
- var schema = compilerContext.getSchema();
39
- var rootType;
40
-
41
- switch (node.kind) {
42
- case 'Root':
43
- switch (node.operation) {
44
- case 'query':
45
- rootType = schema.getQueryType();
46
- break;
47
-
48
- case 'mutation':
49
- rootType = schema.getMutationType();
50
- break;
51
-
52
- case 'subscription':
53
- rootType = schema.getSubscriptionType();
54
- break;
55
-
56
- default:
57
- node.operation;
58
- }
59
-
60
- break;
61
-
62
- case 'SplitOperation':
63
- if (!schema.isServerType(node.type)) {
64
- throw createUserError('ClientExtensionTransform: SplitOperation (@module) can be created ' + 'only for fragments that defined on a server type', [node.loc]);
65
- }
66
-
67
- rootType = node.type;
68
- break;
69
-
70
- case 'Fragment':
71
- rootType = node.type;
72
- break;
73
-
74
- default:
75
- node;
76
- }
77
-
78
- if (rootType == null) {
79
- throw createUserError("ClientExtensionTransform: Expected the type of `".concat(node.name, "` to have been defined in the schema. Make sure both server and ") + 'client schema are up to date.', [node.loc]);
80
- }
81
-
82
- return traverseSelections(node, compilerContext, rootType);
83
- }
84
-
85
- function traverseSelections(node, compilerContext, parentType) {
86
- // $FlowFixMe[escaped-generic]
87
- var nodeCache = cachesByNode.get(node);
88
-
89
- if (nodeCache == null) {
90
- nodeCache = new Map(); // $FlowFixMe[escaped-generic]
91
-
92
- cachesByNode.set(node, nodeCache);
93
- }
94
-
95
- var result = nodeCache.get(parentType);
96
-
97
- if (result != null) {
98
- /* $FlowFixMe[incompatible-return] - TODO: type IRTransformer to allow
99
- * changing result type */
100
- return result;
101
- }
102
-
103
- var schema = compilerContext.getSchema();
104
- var clientSelections = [];
105
- var serverSelections = cowMap(node.selections, function (selection) {
106
- switch (selection.kind) {
107
- case 'ClientExtension':
108
- throw createCompilerError('Unexpected ClientExtension node before ClientExtensionTransform', [selection.loc]);
109
-
110
- case 'Condition':
111
- case 'Defer':
112
- case 'InlineDataFragmentSpread':
113
- case 'ModuleImport':
114
- case 'Stream':
115
- return traverseSelections(selection, compilerContext, parentType);
116
-
117
- case 'ScalarField':
118
- if (schema.isClientDefinedField(schema.assertCompositeType(schema.getRawType(parentType)), selection)) {
119
- clientSelections.push(selection);
120
- return null;
121
- } else {
122
- return selection;
123
- }
124
-
125
- case 'LinkedField':
126
- {
127
- if (schema.isClientDefinedField(schema.assertCompositeType(schema.getRawType(parentType)), selection)) {
128
- clientSelections.push(selection);
129
- return null;
130
- }
131
-
132
- return traverseSelections(selection, compilerContext, selection.type);
133
- }
134
-
135
- case 'InlineFragment':
136
- {
137
- var isClientType = !schema.isServerType(selection.typeCondition);
138
-
139
- if (isClientType) {
140
- clientSelections.push(selection);
141
- return null;
142
- }
143
-
144
- return traverseSelections(selection, compilerContext, selection.typeCondition);
145
- }
146
-
147
- case 'FragmentSpread':
148
- {
149
- return selection;
150
- }
151
-
152
- default:
153
- selection;
154
- throw createCompilerError("ClientExtensionTransform: Unexpected selection of kind `".concat(selection.kind, "`."), [selection.loc]);
155
- }
156
- });
157
-
158
- if (clientSelections.length === 0) {
159
- if (serverSelections === node.selections) {
160
- result = node;
161
- } else {
162
- result = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, node), {}, {
163
- selections: serverSelections
164
- });
165
- }
166
- } else {
167
- result = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, node), {}, {
168
- selections: [].concat((0, _toConsumableArray2["default"])(serverSelections), [// Group client fields under a single ClientExtension node
169
- {
170
- kind: 'ClientExtension',
171
- loc: node.loc,
172
- metadata: null,
173
- selections: clientSelections
174
- }])
175
- });
176
- } // $FlowFixMe[escaped-generic]
177
-
178
-
179
- nodeCache.set(parentType, result);
180
- /* $FlowFixMe[incompatible-return] - TODO: type IRTransformer to allow
181
- * changing result type */
182
-
183
- return result;
184
- }
185
- /**
186
- * Maps an array with copy-on-write semantics.
187
- * `null` return values from the map function are removals.
188
- */
189
-
190
-
191
- function cowMap(selections, f) {
192
- for (var i = 0; i < selections.length; i++) {
193
- var prevSelection = selections[i];
194
- var nextSelection = f(prevSelection);
195
-
196
- if (prevSelection !== nextSelection) {
197
- var result = selections.slice(0, i);
198
-
199
- if (nextSelection != null) {
200
- result.push(nextSelection);
201
- }
202
-
203
- for (var j = i + 1; j < selections.length; j++) {
204
- var innerNextSelection = f(selections[j]);
205
-
206
- if (innerNextSelection != null) {
207
- result.push(innerNextSelection);
208
- }
209
- }
210
-
211
- return result;
212
- }
213
- } // nothing changed, return original
214
-
215
-
216
- return selections;
217
- }
218
-
219
- module.exports = {
220
- transform: clientExtensionTransform
221
- };