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.
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,856 +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 _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
16
-
17
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
18
-
19
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
20
-
21
- var Profiler = require('../../core/GraphQLCompilerProfiler');
22
-
23
- var IRVisitor = require('../../core/IRVisitor');
24
-
25
- var FlattenTransform = require('../../transforms/FlattenTransform');
26
-
27
- var MaskTransform = require('../../transforms/MaskTransform');
28
-
29
- var MatchTransform = require('../../transforms/MatchTransform');
30
-
31
- var RefetchableFragmentTransform = require('../../transforms/RefetchableFragmentTransform');
32
-
33
- var RelayDirectiveTransform = require('../../transforms/RelayDirectiveTransform');
34
-
35
- var RequiredFieldTransform = require('../../transforms/RequiredFieldTransform');
36
-
37
- var generateAbstractTypeRefinementKey = require('../../util/generateAbstractTypeRefinementKey');
38
-
39
- var partitionArray = require('../../util/partitionArray');
40
-
41
- var _require = require('./RelayFlowBabelFactories'),
42
- anyTypeAlias = _require.anyTypeAlias,
43
- declareExportOpaqueType = _require.declareExportOpaqueType,
44
- exactObjectTypeAnnotation = _require.exactObjectTypeAnnotation,
45
- exportType = _require.exportType,
46
- exportTypes = _require.exportTypes,
47
- importTypes = _require.importTypes,
48
- inexactObjectTypeAnnotation = _require.inexactObjectTypeAnnotation,
49
- intersectionTypeAnnotation = _require.intersectionTypeAnnotation,
50
- lineComments = _require.lineComments,
51
- readOnlyArrayOfType = _require.readOnlyArrayOfType,
52
- readOnlyObjectTypeProperty = _require.readOnlyObjectTypeProperty,
53
- unionTypeAnnotation = _require.unionTypeAnnotation;
54
-
55
- var _require2 = require('./RelayFlowTypeTransformers'),
56
- transformInputType = _require2.transformInputType,
57
- transformScalarType = _require2.transformScalarType;
58
-
59
- var babelGenerator = require('@babel/generator')["default"];
60
-
61
- var t = require('@babel/types');
62
-
63
- var invariant = require('invariant');
64
-
65
- var nullthrows = require('nullthrows');
66
-
67
- function generate(schema, node, options) {
68
- var ast = IRVisitor.visit(node, createVisitor(schema, options));
69
- return babelGenerator(ast).code;
70
- }
71
-
72
- function makeProp(schema, _ref, state, unmasked, concreteType) {
73
- var key = _ref.key,
74
- schemaName = _ref.schemaName,
75
- value = _ref.value,
76
- conditional = _ref.conditional,
77
- nodeType = _ref.nodeType,
78
- nodeSelections = _ref.nodeSelections;
79
-
80
- if (schemaName === '__typename' && concreteType) {
81
- value = t.stringLiteralTypeAnnotation(concreteType);
82
- } else if (nodeType) {
83
- value = transformScalarType(schema, nodeType, state, selectionsToBabel(schema, [Array.from(nullthrows(nodeSelections).values())], state, unmasked));
84
- }
85
-
86
- var typeProperty = readOnlyObjectTypeProperty(key, value);
87
-
88
- if (conditional) {
89
- typeProperty.optional = true;
90
- }
91
-
92
- return typeProperty;
93
- }
94
-
95
- var isTypenameSelection = function isTypenameSelection(selection) {
96
- return selection.schemaName === '__typename';
97
- };
98
-
99
- var hasTypenameSelection = function hasTypenameSelection(selections) {
100
- return selections.some(isTypenameSelection);
101
- };
102
-
103
- var onlySelectsTypename = function onlySelectsTypename(selections) {
104
- return selections.every(isTypenameSelection);
105
- };
106
-
107
- function selectionsToBabel(schema, selections, state, unmasked, fragmentTypeName) {
108
- var baseFields = new Map();
109
- var byConcreteType = {};
110
- flattenArray(selections).forEach(function (selection) {
111
- var concreteType = selection.concreteType;
112
-
113
- if (concreteType) {
114
- var _byConcreteType$concr;
115
-
116
- byConcreteType[concreteType] = (_byConcreteType$concr = byConcreteType[concreteType]) !== null && _byConcreteType$concr !== void 0 ? _byConcreteType$concr : [];
117
- byConcreteType[concreteType].push(selection);
118
- } else {
119
- var previousSel = baseFields.get(selection.key);
120
- baseFields.set(selection.key, previousSel ? mergeSelection(selection, previousSel) : selection);
121
- }
122
- });
123
- var types = [];
124
-
125
- if (Object.keys(byConcreteType).length > 0 && onlySelectsTypename(Array.from(baseFields.values())) && (hasTypenameSelection(Array.from(baseFields.values())) || Object.keys(byConcreteType).every(function (type) {
126
- return hasTypenameSelection(byConcreteType[type]);
127
- }))) {
128
- (function () {
129
- var typenameAliases = new Set();
130
-
131
- var _loop = function _loop(concreteType) {
132
- types.push(groupRefs([].concat((0, _toConsumableArray2["default"])(Array.from(baseFields.values())), (0, _toConsumableArray2["default"])(byConcreteType[concreteType]))).map(function (selection) {
133
- if (selection.schemaName === '__typename') {
134
- typenameAliases.add(selection.key);
135
- }
136
-
137
- return makeProp(schema, selection, state, unmasked, concreteType);
138
- }));
139
- };
140
-
141
- for (var concreteType in byConcreteType) {
142
- _loop(concreteType);
143
- } // It might be some other type then the listed concrete types. Ideally, we
144
- // would set the type to diff(string, set of listed concrete types), but
145
- // this doesn't exist in Flow at the time.
146
-
147
-
148
- types.push(Array.from(typenameAliases).map(function (typenameAlias) {
149
- var otherProp = readOnlyObjectTypeProperty(typenameAlias, t.stringLiteralTypeAnnotation('%other'));
150
- otherProp.leadingComments = lineComments("This will never be '%other', but we need some", 'value in case none of the concrete values match.');
151
- return otherProp;
152
- }));
153
- })();
154
- } else {
155
- var selectionMap = selectionsToMap(Array.from(baseFields.values()));
156
-
157
- for (var concreteType in byConcreteType) {
158
- selectionMap = mergeSelections(selectionMap, selectionsToMap(byConcreteType[concreteType].map(function (sel) {
159
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, sel), {}, {
160
- conditional: true
161
- });
162
- })));
163
- }
164
-
165
- var selectionMapValues = groupRefs(Array.from(selectionMap.values())).map(function (sel) {
166
- return isTypenameSelection(sel) && sel.concreteType ? makeProp(schema, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, sel), {}, {
167
- conditional: false
168
- }), state, unmasked, sel.concreteType) : makeProp(schema, sel, state, unmasked);
169
- });
170
- types.push(selectionMapValues);
171
- }
172
-
173
- return unionTypeAnnotation(types.map(function (props) {
174
- if (fragmentTypeName) {
175
- props.push(readOnlyObjectTypeProperty('$refType', t.genericTypeAnnotation(t.identifier(fragmentTypeName))));
176
- }
177
-
178
- return unmasked ? inexactObjectTypeAnnotation(props) : exactObjectTypeAnnotation(props);
179
- }));
180
- }
181
-
182
- function mergeSelection(a, b) {
183
- var shouldSetConditional = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
184
-
185
- if (!a) {
186
- if (shouldSetConditional) {
187
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, b), {}, {
188
- conditional: true
189
- });
190
- }
191
-
192
- return b;
193
- }
194
-
195
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, a), {}, {
196
- nodeSelections: a.nodeSelections ? mergeSelections(a.nodeSelections, nullthrows(b.nodeSelections), shouldSetConditional) : null,
197
- conditional: a.conditional && b.conditional
198
- });
199
- }
200
-
201
- function mergeSelections(a, b) {
202
- var shouldSetConditional = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
203
- var merged = new Map();
204
-
205
- var _iterator = (0, _createForOfIteratorHelper2["default"])(a.entries()),
206
- _step;
207
-
208
- try {
209
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
210
- var _step$value = _step.value,
211
- key = _step$value[0],
212
- value = _step$value[1];
213
- merged.set(key, value);
214
- }
215
- } catch (err) {
216
- _iterator.e(err);
217
- } finally {
218
- _iterator.f();
219
- }
220
-
221
- var _iterator2 = (0, _createForOfIteratorHelper2["default"])(b.entries()),
222
- _step2;
223
-
224
- try {
225
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
226
- var _step2$value = _step2.value,
227
- _key = _step2$value[0],
228
- _value = _step2$value[1];
229
- merged.set(_key, mergeSelection(a.get(_key), _value, shouldSetConditional));
230
- }
231
- } catch (err) {
232
- _iterator2.e(err);
233
- } finally {
234
- _iterator2.f();
235
- }
236
-
237
- return merged;
238
- }
239
-
240
- function isPlural(node) {
241
- return Boolean(node.metadata && node.metadata.plural);
242
- }
243
-
244
- function createVisitor(schema, options) {
245
- var state = {
246
- customScalars: options.customScalars,
247
- enumsHasteModule: options.enumsHasteModule,
248
- generatedFragments: new Set(),
249
- generatedInputObjectTypes: {},
250
- optionalInputFields: options.optionalInputFields,
251
- usedEnums: {},
252
- usedFragments: new Set(),
253
- useHaste: options.useHaste,
254
- useSingleArtifactDirectory: options.useSingleArtifactDirectory,
255
- noFutureProofEnums: options.noFutureProofEnums,
256
- matchFields: new Map(),
257
- runtimeImports: new Set()
258
- };
259
- return {
260
- leave: {
261
- Root: function Root(node) {
262
- var _node$metadata;
263
-
264
- var inputVariablesType = generateInputVariablesType(schema, node, state);
265
- var inputObjectTypes = generateInputObjectTypes(state);
266
- var responseTypeDefinition = selectionsToBabel(schema,
267
- /* $FlowFixMe: selections have already been transformed */
268
- node.selections, state, false);
269
-
270
- if (((_node$metadata = node.metadata) === null || _node$metadata === void 0 ? void 0 : _node$metadata.childrenCanBubbleNull) === true) {
271
- responseTypeDefinition = t.nullableTypeAnnotation(responseTypeDefinition);
272
- }
273
-
274
- var responseType = exportType("".concat(node.name, "Response"), responseTypeDefinition);
275
- var operationTypes = [t.objectTypeProperty(t.identifier('variables'), t.genericTypeAnnotation(t.identifier("".concat(node.name, "Variables")))), t.objectTypeProperty(t.identifier('response'), t.genericTypeAnnotation(t.identifier("".concat(node.name, "Response"))))]; // Generate raw response type
276
-
277
- var rawResponseType;
278
- var normalizationIR = options.normalizationIR;
279
-
280
- if (normalizationIR && node.directives.some(function (d) {
281
- return d.name === DIRECTIVE_NAME;
282
- })) {
283
- rawResponseType = IRVisitor.visit(normalizationIR, createRawResponseTypeVisitor(schema, state));
284
- }
285
-
286
- var refetchableFragmentName = getRefetchableQueryParentFragmentName(state, node.metadata);
287
-
288
- if (refetchableFragmentName != null) {
289
- state.runtimeImports.add('FragmentReference');
290
- }
291
-
292
- var babelNodes = [];
293
-
294
- if (state.runtimeImports.size) {
295
- babelNodes.push(importTypes(Array.from(state.runtimeImports).sort(), 'relay-runtime'));
296
- }
297
-
298
- babelNodes.push.apply(babelNodes, (0, _toConsumableArray2["default"])(refetchableFragmentName ? generateFragmentRefsForRefetchable(refetchableFragmentName) : getFragmentImports(state)).concat((0, _toConsumableArray2["default"])(getEnumDefinitions(schema, state)), (0, _toConsumableArray2["default"])(inputObjectTypes), [inputVariablesType, responseType]));
299
-
300
- if (rawResponseType) {
301
- var _iterator3 = (0, _createForOfIteratorHelper2["default"])(state.matchFields),
302
- _step3;
303
-
304
- try {
305
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
306
- var _step3$value = _step3.value,
307
- key = _step3$value[0],
308
- ast = _step3$value[1];
309
- babelNodes.push(exportType(key, ast));
310
- }
311
- } catch (err) {
312
- _iterator3.e(err);
313
- } finally {
314
- _iterator3.f();
315
- }
316
-
317
- operationTypes.push(t.objectTypeProperty(t.identifier('rawResponse'), t.genericTypeAnnotation(t.identifier("".concat(node.name, "RawResponse")))));
318
- babelNodes.push(rawResponseType);
319
- }
320
-
321
- babelNodes.push(exportType(node.name, exactObjectTypeAnnotation(operationTypes)));
322
- return t.program(babelNodes);
323
- },
324
- Fragment: function Fragment(node) {
325
- var _node$metadata2;
326
-
327
- var selections = flattenArray( // $FlowFixMe[incompatible-cast] : selections have already been transformed
328
- node.selections);
329
- var numConecreteSelections = selections.filter(function (s) {
330
- return s.concreteType;
331
- }).length;
332
- selections = selections.map(function (selection) {
333
- if (numConecreteSelections <= 1 && isTypenameSelection(selection) && !schema.isAbstractType(node.type)) {
334
- return [(0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, selection), {}, {
335
- concreteType: schema.getTypeString(node.type)
336
- })];
337
- }
338
-
339
- return [selection];
340
- });
341
- state.generatedFragments.add(node.name);
342
- var fragmentTypes = getFragmentTypes(node.name, getRefetchableQueryPath(state, node.directives));
343
- var refTypeName = getRefTypeName(node.name);
344
- var refTypeDataProperty = readOnlyObjectTypeProperty('$data', t.genericTypeAnnotation(t.identifier("".concat(node.name, "$data"))));
345
- refTypeDataProperty.optional = true;
346
- var refTypeFragmentRefProperty = readOnlyObjectTypeProperty('$fragmentRefs', t.genericTypeAnnotation(t.identifier(getOldFragmentTypeName(node.name))));
347
- var isPluralFragment = isPlural(node);
348
- var refType = inexactObjectTypeAnnotation([refTypeDataProperty, refTypeFragmentRefProperty]);
349
- var dataTypeName = getDataTypeName(node.name);
350
- var dataType = t.genericTypeAnnotation(t.identifier(node.name));
351
- var unmasked = node.metadata != null && node.metadata.mask === false;
352
- var baseType = selectionsToBabel(schema, selections, state, unmasked, unmasked ? undefined : getOldFragmentTypeName(node.name));
353
- var type = isPluralFragment ? readOnlyArrayOfType(baseType) : baseType;
354
-
355
- if (((_node$metadata2 = node.metadata) === null || _node$metadata2 === void 0 ? void 0 : _node$metadata2.childrenCanBubbleNull) === true) {
356
- type = t.nullableTypeAnnotation(type);
357
- }
358
-
359
- state.runtimeImports.add('FragmentReference');
360
- return t.program([].concat((0, _toConsumableArray2["default"])(getFragmentImports(state)), (0, _toConsumableArray2["default"])(getEnumDefinitions(schema, state)), [importTypes(Array.from(state.runtimeImports).sort(), 'relay-runtime')], (0, _toConsumableArray2["default"])(fragmentTypes), [exportType(node.name, type), exportType(dataTypeName, dataType), exportType(refTypeName, isPluralFragment ? readOnlyArrayOfType(refType) : refType)]));
361
- },
362
- InlineFragment: function InlineFragment(node) {
363
- return flattenArray( // $FlowFixMe[incompatible-cast] : selections have already been transformed
364
- node.selections).map(function (typeSelection) {
365
- return schema.isAbstractType(node.typeCondition) ? (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, typeSelection), {}, {
366
- conditional: true
367
- }) : (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, typeSelection), {}, {
368
- concreteType: schema.getTypeString(node.typeCondition)
369
- });
370
- });
371
- },
372
- Condition: function Condition(node) {
373
- return flattenArray( // $FlowFixMe[incompatible-cast] : selections have already been transformed
374
- node.selections).map(function (selection) {
375
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, selection), {}, {
376
- conditional: true
377
- });
378
- });
379
- },
380
- ScalarField: function ScalarField(node) {
381
- return visitScalarField(schema, node, state);
382
- },
383
- LinkedField: function LinkedField(node) {
384
- return visitLinkedField(schema, node);
385
- },
386
- ModuleImport: function ModuleImport(node) {
387
- return [{
388
- key: '__fragmentPropName',
389
- conditional: true,
390
- value: transformScalarType(schema, schema.expectStringType(), state)
391
- }, {
392
- key: '__module_component',
393
- conditional: true,
394
- value: transformScalarType(schema, schema.expectStringType(), state)
395
- }, {
396
- key: '__fragments_' + node.name,
397
- ref: node.name
398
- }];
399
- },
400
- FragmentSpread: function FragmentSpread(node) {
401
- state.usedFragments.add(node.name);
402
- return [{
403
- key: '__fragments_' + node.name,
404
- ref: node.name
405
- }];
406
- }
407
- }
408
- };
409
- }
410
-
411
- function visitNodeWithSelectionsOnly(node) {
412
- return flattenArray( // $FlowFixMe[incompatible-cast] : selections have already been transformed
413
- node.selections);
414
- }
415
-
416
- function visitScalarField(schema, node, state) {
417
- var _node$metadata3;
418
-
419
- var requiredMetadata = (_node$metadata3 = node.metadata) === null || _node$metadata3 === void 0 ? void 0 : _node$metadata3.required;
420
- var nodeType = requiredMetadata != null ? schema.getNonNullType(node.type) : node.type;
421
- return [{
422
- key: node.alias,
423
- schemaName: node.name,
424
- value: transformScalarType(schema, nodeType, state)
425
- }];
426
- }
427
-
428
- function getLinkedFieldNodeType(schema, node) {
429
- var _node$metadata4, _node$metadata5;
430
-
431
- var requiredMetadata = (_node$metadata4 = node.metadata) === null || _node$metadata4 === void 0 ? void 0 : _node$metadata4.required;
432
-
433
- if (requiredMetadata != null) {
434
- return schema.getNonNullType(node.type);
435
- }
436
-
437
- if (((_node$metadata5 = node.metadata) === null || _node$metadata5 === void 0 ? void 0 : _node$metadata5.childrenCanBubbleNull) === true) {
438
- if (schema.isList(node.type)) {
439
- // In a plural field, nulls bubble up to the item, resulting in a list of nullable items.
440
- return schema.mapListItemType(node.type, function (inner) {
441
- return schema.getNullableType(inner);
442
- });
443
- } else if (schema.isNonNull(node.type)) {
444
- var nullable = schema.getNullableType(node.type);
445
-
446
- if (schema.isList(nullable)) {
447
- return schema.getNonNullType(schema.mapListItemType(nullable, function (inner) {
448
- return schema.getNullableType(inner);
449
- }));
450
- }
451
-
452
- return nullable;
453
- }
454
-
455
- return node.type;
456
- }
457
-
458
- return node.type;
459
- }
460
-
461
- function visitLinkedField(schema, node) {
462
- return [{
463
- key: node.alias,
464
- schemaName: node.name,
465
- nodeType: getLinkedFieldNodeType(schema, node),
466
- nodeSelections: selectionsToMap(flattenArray( // $FlowFixMe[incompatible-cast] : selections have already been transformed
467
- node.selections),
468
- /*
469
- * append concreteType to key so overlapping fields with different
470
- * concreteTypes don't get overwritten by each other
471
- */
472
- true)
473
- }];
474
- }
475
-
476
- function makeRawResponseProp(schema, _ref2, state, concreteType) {
477
- var key = _ref2.key,
478
- schemaName = _ref2.schemaName,
479
- value = _ref2.value,
480
- conditional = _ref2.conditional,
481
- nodeType = _ref2.nodeType,
482
- nodeSelections = _ref2.nodeSelections,
483
- kind = _ref2.kind;
484
-
485
- if (kind === 'ModuleImport') {
486
- return t.objectTypeSpreadProperty(t.genericTypeAnnotation(t.identifier(key)));
487
- }
488
-
489
- if (schemaName === '__typename' && concreteType) {
490
- value = t.stringLiteralTypeAnnotation(concreteType);
491
- } else if (nodeType) {
492
- value = transformScalarType(schema, nodeType, state, selectionsToRawResponseBabel(schema, [Array.from(nullthrows(nodeSelections).values())], state, schema.isAbstractType(nodeType) || schema.isWrapper(nodeType) ? null : schema.getTypeString(nodeType)));
493
- }
494
-
495
- var typeProperty = readOnlyObjectTypeProperty(key, value);
496
-
497
- if (conditional) {
498
- typeProperty.optional = true;
499
- }
500
-
501
- return typeProperty;
502
- } // Trasform the codegen IR selections into Babel flow types
503
-
504
-
505
- function selectionsToRawResponseBabel(schema, selections, state, nodeTypeName) {
506
- var baseFields = [];
507
- var byConcreteType = {};
508
- flattenArray(selections).forEach(function (selection) {
509
- var concreteType = selection.concreteType;
510
-
511
- if (concreteType) {
512
- var _byConcreteType$concr2;
513
-
514
- byConcreteType[concreteType] = (_byConcreteType$concr2 = byConcreteType[concreteType]) !== null && _byConcreteType$concr2 !== void 0 ? _byConcreteType$concr2 : [];
515
- byConcreteType[concreteType].push(selection);
516
- } else {
517
- baseFields.push(selection);
518
- }
519
- });
520
- var types = [];
521
-
522
- if (Object.keys(byConcreteType).length) {
523
- var baseFieldsMap = selectionsToMap(baseFields);
524
-
525
- var _loop2 = function _loop2(concreteType) {
526
- var mergedSeletions = Array.from(mergeSelections(baseFieldsMap, selectionsToMap(byConcreteType[concreteType]), false).values());
527
- types.push(exactObjectTypeAnnotation(mergedSeletions.map(function (selection) {
528
- return makeRawResponseProp(schema, selection, state, concreteType);
529
- })));
530
- appendLocal3DPayload(types, mergedSeletions, schema, state, concreteType);
531
- };
532
-
533
- for (var concreteType in byConcreteType) {
534
- _loop2(concreteType);
535
- }
536
- }
537
-
538
- if (baseFields.length > 0) {
539
- types.push(exactObjectTypeAnnotation(baseFields.map(function (selection) {
540
- return makeRawResponseProp(schema, selection, state, nodeTypeName);
541
- })));
542
- appendLocal3DPayload(types, baseFields, schema, state, nodeTypeName);
543
- }
544
-
545
- return unionTypeAnnotation(types);
546
- }
547
-
548
- function appendLocal3DPayload(types, selections, schema, state, currentType) {
549
- var moduleImport = selections.find(function (sel) {
550
- return sel.kind === 'ModuleImport';
551
- });
552
-
553
- if (moduleImport) {
554
- // Generate an extra opaque type for client 3D fields
555
- state.runtimeImports.add('Local3DPayload');
556
- types.push(t.genericTypeAnnotation(t.identifier('Local3DPayload'), t.typeParameterInstantiation([t.stringLiteralTypeAnnotation(nullthrows(moduleImport.documentName)), exactObjectTypeAnnotation(selections.filter(function (sel) {
557
- return sel.schemaName !== 'js';
558
- }).map(function (selection) {
559
- return makeRawResponseProp(schema, selection, state, currentType);
560
- }))])));
561
- }
562
- } // Visitor for generating raw response type
563
-
564
-
565
- function createRawResponseTypeVisitor(schema, state) {
566
- return {
567
- leave: {
568
- Root: function Root(node) {
569
- return exportType("".concat(node.name, "RawResponse"), selectionsToRawResponseBabel(schema, // $FlowFixMe[incompatible-cast] : selections have already been transformed
570
- node.selections, state, null));
571
- },
572
- InlineFragment: function InlineFragment(node) {
573
- var typeCondition = node.typeCondition;
574
- return flattenArray( // $FlowFixMe[incompatible-cast] : selections have already been transformed
575
- node.selections).map(function (typeSelection) {
576
- return schema.isAbstractType(typeCondition) ? typeSelection : (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, typeSelection), {}, {
577
- concreteType: schema.getTypeString(typeCondition)
578
- });
579
- });
580
- },
581
- ScalarField: function ScalarField(node) {
582
- return visitScalarField(schema, node, state);
583
- },
584
- ClientExtension: function ClientExtension(node) {
585
- return flattenArray( // $FlowFixMe[incompatible-cast] : selections have already been transformed
586
- node.selections).map(function (sel) {
587
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, sel), {}, {
588
- conditional: true
589
- });
590
- });
591
- },
592
- LinkedField: function LinkedField(node) {
593
- return visitLinkedField(schema, node);
594
- },
595
- Condition: visitNodeWithSelectionsOnly,
596
- Defer: visitNodeWithSelectionsOnly,
597
- Stream: visitNodeWithSelectionsOnly,
598
- ModuleImport: function ModuleImport(node) {
599
- return visitRawResposneModuleImport(schema, node, state);
600
- },
601
- FragmentSpread: function FragmentSpread(node) {
602
- !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'A fragment spread is found when traversing the AST, ' + 'make sure you are passing the codegen IR') : invariant(false) : void 0;
603
- }
604
- }
605
- };
606
- } // Dedupe the generated type of module selections to reduce file size
607
-
608
-
609
- function visitRawResposneModuleImport(schema, node, state) {
610
- var selections = node.selections,
611
- key = node.name;
612
- var moduleSelections = selections.filter( // $FlowFixMe[prop-missing] selections have already been transformed
613
- function (sel) {
614
- return sel.length && sel[0].schemaName === 'js';
615
- }).map(function (arr) {
616
- return arr[0];
617
- });
618
-
619
- if (!state.matchFields.has(key)) {
620
- var ast = selectionsToRawResponseBabel(schema, // $FlowFixMe[incompatible-cast] : selections have already been transformed
621
- node.selections.filter(function (sel) {
622
- return sel.length > 1 || sel[0].schemaName !== 'js';
623
- }), state, null);
624
- state.matchFields.set(key, ast);
625
- }
626
-
627
- return [].concat((0, _toConsumableArray2["default"])(moduleSelections), [{
628
- key: key,
629
- kind: 'ModuleImport',
630
- documentName: node.key
631
- }]);
632
- }
633
-
634
- function selectionsToMap(selections, appendType) {
635
- var map = new Map();
636
- selections.forEach(function (selection) {
637
- var key = appendType && selection.concreteType ? "".concat(selection.key, "::").concat(selection.concreteType) : selection.key;
638
- var previousSel = map.get(key);
639
- map.set(key, previousSel ? mergeSelection(previousSel, selection) : selection);
640
- });
641
- return map;
642
- }
643
-
644
- function flattenArray(arrayOfArrays) {
645
- var result = [];
646
- arrayOfArrays.forEach(function (array) {
647
- result.push.apply(result, (0, _toConsumableArray2["default"])(array));
648
- });
649
- return result;
650
- }
651
-
652
- function generateInputObjectTypes(state) {
653
- return Object.keys(state.generatedInputObjectTypes).map(function (typeIdentifier) {
654
- var inputObjectType = state.generatedInputObjectTypes[typeIdentifier];
655
- !(typeof inputObjectType !== 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayCompilerFlowGenerator: Expected input object type to have been' + ' defined before calling `generateInputObjectTypes`') : invariant(false) : void 0;
656
- return exportType(typeIdentifier, inputObjectType);
657
- });
658
- }
659
-
660
- function generateInputVariablesType(schema, node, state) {
661
- return exportType("".concat(node.name, "Variables"), exactObjectTypeAnnotation(node.argumentDefinitions.map(function (arg) {
662
- var property = t.objectTypeProperty(t.identifier(arg.name), transformInputType(schema, arg.type, state));
663
-
664
- if (!schema.isNonNull(arg.type)) {
665
- property.optional = true;
666
- }
667
-
668
- return property;
669
- })));
670
- }
671
-
672
- function groupRefs(props) {
673
- var result = [];
674
- var refs = [];
675
- props.forEach(function (prop) {
676
- if (prop.ref) {
677
- refs.push(prop.ref);
678
- } else {
679
- result.push(prop);
680
- }
681
- });
682
-
683
- if (refs.length > 0) {
684
- var value = intersectionTypeAnnotation(refs.map(function (ref) {
685
- return t.genericTypeAnnotation(t.identifier(getOldFragmentTypeName(ref)));
686
- }));
687
- result.push({
688
- key: '$fragmentRefs',
689
- conditional: false,
690
- value: value
691
- });
692
- }
693
-
694
- return result;
695
- }
696
-
697
- function getFragmentImports(state) {
698
- var imports = [];
699
-
700
- if (state.usedFragments.size > 0) {
701
- var usedFragments = Array.from(state.usedFragments).sort();
702
-
703
- var _iterator4 = (0, _createForOfIteratorHelper2["default"])(usedFragments),
704
- _step4;
705
-
706
- try {
707
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
708
- var usedFragment = _step4.value;
709
- var fragmentTypeName = getOldFragmentTypeName(usedFragment);
710
-
711
- if (!state.generatedFragments.has(usedFragment)) {
712
- if (state.useHaste) {
713
- // TODO(T22653277) support non-haste environments when importing
714
- // fragments
715
- imports.push(importTypes([fragmentTypeName], usedFragment + '.graphql'));
716
- } else if (state.useSingleArtifactDirectory) {
717
- imports.push(importTypes([fragmentTypeName], './' + usedFragment + '.graphql'));
718
- } else {
719
- imports.push(anyTypeAlias(fragmentTypeName));
720
- }
721
- }
722
- }
723
- } catch (err) {
724
- _iterator4.e(err);
725
- } finally {
726
- _iterator4.f();
727
- }
728
- }
729
-
730
- return imports;
731
- }
732
-
733
- function getEnumDefinitions(schema, _ref3) {
734
- var enumsHasteModule = _ref3.enumsHasteModule,
735
- usedEnums = _ref3.usedEnums,
736
- noFutureProofEnums = _ref3.noFutureProofEnums;
737
- var enumNames = Object.keys(usedEnums).sort();
738
-
739
- if (enumNames.length === 0) {
740
- return [];
741
- }
742
-
743
- if (typeof enumsHasteModule === 'string') {
744
- return [importTypes(enumNames, enumsHasteModule)];
745
- }
746
-
747
- if (typeof enumsHasteModule === 'function') {
748
- return enumNames.map(function (enumName) {
749
- return importTypes([enumName], enumsHasteModule(enumName));
750
- });
751
- }
752
-
753
- return enumNames.map(function (name) {
754
- var values = [].concat(schema.getEnumValues(usedEnums[name]));
755
- values.sort();
756
-
757
- if (!noFutureProofEnums) {
758
- values.push('%future added value');
759
- }
760
-
761
- return exportType(name, t.unionTypeAnnotation(values.map(function (value) {
762
- return t.stringLiteralTypeAnnotation(value);
763
- })));
764
- });
765
- } // If it's a @refetchable fragment, we generate the $fragmentRef in generated
766
- // query, and import it in the fragment to avoid circular dependencies
767
-
768
-
769
- function getRefetchableQueryParentFragmentName(state, metadata) {
770
- if (!(metadata === null || metadata === void 0 ? void 0 : metadata.isRefetchableQuery) || !state.useHaste && !state.useSingleArtifactDirectory) {
771
- return null;
772
- }
773
-
774
- var derivedFrom = metadata === null || metadata === void 0 ? void 0 : metadata.derivedFrom;
775
-
776
- if (derivedFrom != null && typeof derivedFrom === 'string') {
777
- return derivedFrom;
778
- }
779
-
780
- return null;
781
- }
782
-
783
- function getRefetchableQueryPath(state, directives) {
784
- var _directives$find;
785
-
786
- var refetchableQuery;
787
-
788
- if (!state.useHaste && !state.useSingleArtifactDirectory) {
789
- return;
790
- }
791
-
792
- var refetchableArgs = (_directives$find = directives.find(function (d) {
793
- return d.name === 'refetchable';
794
- })) === null || _directives$find === void 0 ? void 0 : _directives$find.args;
795
-
796
- if (!refetchableArgs) {
797
- return;
798
- }
799
-
800
- var argument = refetchableArgs.find(function (arg) {
801
- return arg.kind === 'Argument' && arg.name === 'queryName';
802
- });
803
-
804
- if (argument && argument.value && argument.value.kind === 'Literal' && typeof argument.value.value === 'string') {
805
- refetchableQuery = argument.value.value;
806
-
807
- if (!state.useHaste) {
808
- refetchableQuery = './' + refetchableQuery;
809
- }
810
-
811
- refetchableQuery += '.graphql';
812
- }
813
-
814
- return refetchableQuery;
815
- }
816
-
817
- function generateFragmentRefsForRefetchable(name) {
818
- var oldFragmentTypeName = getOldFragmentTypeName(name);
819
- var newFragmentTypeName = getNewFragmentTypeName(name);
820
- return [declareExportOpaqueType(oldFragmentTypeName, 'FragmentReference'), declareExportOpaqueType(newFragmentTypeName, oldFragmentTypeName)];
821
- }
822
-
823
- function getFragmentTypes(name, refetchableQueryPath) {
824
- var oldFragmentTypeName = getOldFragmentTypeName(name);
825
- var newFragmentTypeName = getNewFragmentTypeName(name);
826
-
827
- if (refetchableQueryPath) {
828
- return [importTypes([oldFragmentTypeName, newFragmentTypeName], refetchableQueryPath), exportTypes([oldFragmentTypeName, newFragmentTypeName])];
829
- }
830
-
831
- return [declareExportOpaqueType(oldFragmentTypeName, 'FragmentReference'), declareExportOpaqueType(newFragmentTypeName, oldFragmentTypeName)];
832
- }
833
-
834
- function getOldFragmentTypeName(name) {
835
- return "".concat(name, "$ref");
836
- }
837
-
838
- function getNewFragmentTypeName(name) {
839
- return "".concat(name, "$fragmentType");
840
- }
841
-
842
- function getRefTypeName(name) {
843
- return "".concat(name, "$key");
844
- }
845
-
846
- function getDataTypeName(name) {
847
- return "".concat(name, "$data");
848
- }
849
-
850
- var FLOW_TRANSFORMS = [RelayDirectiveTransform.transform, MaskTransform.transform, MatchTransform.transform, RequiredFieldTransform.transform, FlattenTransform.transformWithOptions({}), RefetchableFragmentTransform.transform];
851
- var DIRECTIVE_NAME = 'raw_response_type';
852
- module.exports = {
853
- generate: Profiler.instrument(generate, 'RelayFlowGenerator.generate'),
854
- transforms: FLOW_TRANSFORMS,
855
- SCHEMA_EXTENSION: "directive @".concat(DIRECTIVE_NAME, " on QUERY | MUTATION | SUBSCRIPTION")
856
- };