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,351 +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 CompilerContext = require('./CompilerContext');
20
-
21
- var _require = require('./CompilerError'),
22
- createCompilerError = _require.createCompilerError;
23
-
24
- var IRVisitor = require('./IRVisitor');
25
-
26
- var SchemaUtils = require('./SchemaUtils');
27
-
28
- /**
29
- * Returns a transformed version of the input context where each document's
30
- * argument definitions are updated to accurately describe the root variables
31
- * used (or reachable) from that document:
32
- * - Fragment argument definitions are updated to include local argument
33
- * definitions and any root variables that are referenced
34
- * by the fragment (or any fragments it transitively spreads).
35
- * - Root argument definitions are updated to reflect the variables
36
- * referenced locally and all root variables referenced by any
37
- * fragments it (transitively) spreads.
38
- */
39
- function inferRootArgumentDefinitions(context) {
40
- // This transform does two main tasks:
41
- // - Determine the set of root variables referenced locally in each
42
- // fragment. Note that RootArgumentDefinitions in the fragment's
43
- // argumentDefinitions can contain spurious entries for legacy
44
- // reasons. Instead of using those the fragment is traversed
45
- // to reanalyze variable usage.
46
- // - Determine the set of root variables that are transitively referenced
47
- // by each fragment, ie the union of all root variables used in the
48
- // fragment and any fragments it transitively spreads.
49
- // Cache fragments as they are transformed to avoid duplicate processing.
50
- // Because @argument values don't matter (only variable names/types),
51
- // each reachable fragment only has to be checked once.
52
- var transformed = new Map();
53
- var nextContext = new CompilerContext(context.getSchema());
54
- return nextContext.addAll(Array.from(context.documents(), function (node) {
55
- switch (node.kind) {
56
- case 'Fragment':
57
- {
58
- var argumentDefinitions = transformFragmentArguments(context, transformed, node);
59
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, node), {}, {
60
- argumentDefinitions: Array.from(argumentDefinitions.values())
61
- });
62
- }
63
-
64
- case 'Root':
65
- {
66
- return transformRoot(context, transformed, node);
67
- }
68
-
69
- case 'SplitOperation':
70
- {
71
- return node;
72
- }
73
-
74
- default:
75
- {
76
- node;
77
- throw createCompilerError("inferRootArgumentDefinitions: Unsupported kind '".concat(node.kind, "'."));
78
- }
79
- }
80
- }));
81
- }
82
-
83
- function transformRoot(context, transformed, root) {
84
- // Ignore argument definitions, determine what root variables are
85
- // transitively referenced
86
- var argumentDefinitions = new Map();
87
- var localArgumentDefinitions = new Map();
88
-
89
- var _iterator = (0, _createForOfIteratorHelper2["default"])(root.argumentDefinitions.entries()),
90
- _step;
91
-
92
- try {
93
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
94
- var _step$value = _step.value,
95
- name = _step$value[0],
96
- argDef = _step$value[1];
97
-
98
- if (argDef.kind === 'LocalArgumentDefinition') {
99
- localArgumentDefinitions.set(name, argDef);
100
- }
101
- }
102
- } catch (err) {
103
- _iterator.e(err);
104
- } finally {
105
- _iterator.f();
106
- }
107
-
108
- visit(context, transformed, argumentDefinitions, root);
109
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, root), {}, {
110
- argumentDefinitions: Array.from(argumentDefinitions.values(), function (argDef) {
111
- var _localDefinition$type, _localDefinition$defa;
112
-
113
- if (argDef.kind !== 'RootArgumentDefinition') {
114
- throw createCompilerError("inferRootArgumentDefinitions: Expected inferred variable '$".concat(argDef.name, "' to be a root variables."), [argDef.loc]);
115
- }
116
-
117
- var localDefinition = localArgumentDefinitions.get(argDef.name);
118
- var type = (_localDefinition$type = localDefinition === null || localDefinition === void 0 ? void 0 : localDefinition.type) !== null && _localDefinition$type !== void 0 ? _localDefinition$type : argDef.type;
119
- return {
120
- defaultValue: (_localDefinition$defa = localDefinition === null || localDefinition === void 0 ? void 0 : localDefinition.defaultValue) !== null && _localDefinition$defa !== void 0 ? _localDefinition$defa : null,
121
- kind: 'LocalArgumentDefinition',
122
- loc: argDef.loc,
123
- name: argDef.name,
124
- type: type
125
- };
126
- })
127
- });
128
- }
129
-
130
- function transformFragmentArguments(context, transformed, fragment) {
131
- var name = fragment.name;
132
- var transformedArguments = transformed.get(name);
133
-
134
- if (transformedArguments != null) {
135
- return transformedArguments;
136
- } // Start with only the explicitly defined local arguments, recover the
137
- // correct set of root variables excluding invalid @arguments values.
138
-
139
-
140
- var argumentDefinitions = new Map();
141
- fragment.argumentDefinitions.forEach(function (argDef) {
142
- if (argDef.kind === 'LocalArgumentDefinition') {
143
- argumentDefinitions.set(argDef.name, argDef);
144
- }
145
- }); // Break cycles by initially caching a version that only has local
146
- // arguments. If the current fragment is reached again, it won't have
147
- // any root variables to add to its parents. The traversal below will
148
- // find any root variables and update the cached version of the
149
- // fragment.
150
-
151
- transformed.set(name, argumentDefinitions);
152
- visit(context, transformed, argumentDefinitions, fragment);
153
- transformed.set(name, argumentDefinitions);
154
- return argumentDefinitions;
155
- }
156
-
157
- function visit(context, transformed, argumentDefinitions, node) {
158
- IRVisitor.visit(node, {
159
- FragmentSpread: function FragmentSpread(fragmentSpread) {
160
- var fragment = context.getFragment(fragmentSpread.name, fragmentSpread.loc);
161
- var referencedFragmentArguments = transformFragmentArguments(context, transformed, fragment); // Detect root variables being passed as the value of @arguments;
162
- // recover the expected type from the corresponding argument definitions.
163
-
164
- fragmentSpread.args.forEach(function (arg) {
165
- var argDef = referencedFragmentArguments.get(arg.name);
166
-
167
- if (argDef != null && arg.value.kind === 'Variable' && !argumentDefinitions.has(arg.value.variableName)) {
168
- argumentDefinitions.set(arg.value.variableName, {
169
- kind: 'RootArgumentDefinition',
170
- loc: {
171
- kind: 'Derived',
172
- source: arg.loc
173
- },
174
- name: arg.value.variableName,
175
- type: argDef.type
176
- });
177
- }
178
- }); // Merge any root variables referenced by the spread fragment
179
- // into this (parent) fragment's arguments.
180
-
181
- var _iterator2 = (0, _createForOfIteratorHelper2["default"])(referencedFragmentArguments.values()),
182
- _step2;
183
-
184
- try {
185
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
186
- var argDef = _step2.value;
187
-
188
- if (argDef.kind === 'RootArgumentDefinition') {
189
- argumentDefinitions.set(argDef.name, argDef);
190
- }
191
- }
192
- } catch (err) {
193
- _iterator2.e(err);
194
- } finally {
195
- _iterator2.f();
196
- }
197
- },
198
- Argument: function Argument(argument) {
199
- if (argument.value.kind === 'Literal') {
200
- return false;
201
- }
202
-
203
- var values = [argument.value];
204
-
205
- while (values.length > 0) {
206
- var currentValue = values.pop();
207
-
208
- if (currentValue.kind === 'Variable') {
209
- var _currentValue$type;
210
-
211
- var type = (_currentValue$type = currentValue.type) !== null && _currentValue$type !== void 0 ? _currentValue$type : argument.type;
212
-
213
- if (type == null) {
214
- continue;
215
- }
216
-
217
- if (!argumentDefinitions.has(currentValue.variableName)) {
218
- // root variable
219
- argumentDefinitions.set(currentValue.variableName, {
220
- kind: 'RootArgumentDefinition',
221
- loc: {
222
- kind: 'Derived',
223
- source: argument.loc
224
- },
225
- name: currentValue.variableName,
226
- type: type
227
- });
228
- }
229
- } else if (currentValue.kind === 'ObjectValue') {
230
- currentValue.fields.forEach(function (fieldValue) {
231
- if (fieldValue.value.kind !== 'Literal') {
232
- values.push(fieldValue.value);
233
- }
234
- });
235
- } else if (currentValue.kind === 'ListValue') {
236
- currentValue.items.forEach(function (listValue) {
237
- if (listValue.kind !== 'Literal') {
238
- values.push(listValue);
239
- }
240
- });
241
- }
242
- }
243
-
244
- return false;
245
- },
246
- Condition: function Condition(condition) {
247
- var _variable$type;
248
-
249
- var variable = condition.condition;
250
-
251
- if (variable.kind !== 'Variable') {
252
- return;
253
- }
254
-
255
- var type = (_variable$type = variable.type) !== null && _variable$type !== void 0 ? _variable$type : SchemaUtils.getNonNullBooleanInput(context.getSchema());
256
-
257
- if (!argumentDefinitions.has(variable.variableName)) {
258
- // root variable
259
- argumentDefinitions.set(variable.variableName, {
260
- kind: 'RootArgumentDefinition',
261
- loc: {
262
- kind: 'Derived',
263
- source: variable.loc
264
- },
265
- name: variable.variableName,
266
- type: type
267
- });
268
- }
269
- },
270
- Defer: function Defer(defer) {
271
- var _variable$type2;
272
-
273
- var variable = defer["if"];
274
-
275
- if (variable == null || variable.kind !== 'Variable') {
276
- return;
277
- }
278
-
279
- var type = (_variable$type2 = variable.type) !== null && _variable$type2 !== void 0 ? _variable$type2 : SchemaUtils.getNonNullBooleanInput(context.getSchema());
280
-
281
- if (!argumentDefinitions.has(variable.variableName)) {
282
- // root variable
283
- argumentDefinitions.set(variable.variableName, {
284
- kind: 'RootArgumentDefinition',
285
- loc: {
286
- kind: 'Derived',
287
- source: variable.loc
288
- },
289
- name: variable.variableName,
290
- type: type
291
- });
292
- }
293
- },
294
- Stream: function Stream(stream) {
295
- [stream["if"], stream.initialCount].forEach(function (variable) {
296
- var _variable$type3;
297
-
298
- if (variable == null || variable.kind !== 'Variable') {
299
- return;
300
- }
301
-
302
- var type = (_variable$type3 = variable.type) !== null && _variable$type3 !== void 0 ? _variable$type3 : SchemaUtils.getNonNullBooleanInput(context.getSchema());
303
-
304
- if (!argumentDefinitions.has(variable.variableName)) {
305
- // root variable
306
- argumentDefinitions.set(variable.variableName, {
307
- kind: 'RootArgumentDefinition',
308
- loc: {
309
- kind: 'Derived',
310
- source: variable.loc
311
- },
312
- name: variable.variableName,
313
- type: type
314
- });
315
- }
316
- });
317
- },
318
- LinkedField: function LinkedField(field) {
319
- if (!field.handles) {
320
- return;
321
- }
322
-
323
- field.handles.forEach(function (handle) {
324
- var _variable$type4;
325
-
326
- var variable = handle.dynamicKey;
327
-
328
- if (variable == null) {
329
- return;
330
- }
331
-
332
- var type = (_variable$type4 = variable.type) !== null && _variable$type4 !== void 0 ? _variable$type4 : SchemaUtils.getNullableStringInput(context.getSchema());
333
-
334
- if (!argumentDefinitions.has(variable.variableName)) {
335
- // root variable
336
- argumentDefinitions.set(variable.variableName, {
337
- kind: 'RootArgumentDefinition',
338
- loc: {
339
- kind: 'Derived',
340
- source: variable.loc
341
- },
342
- name: variable.variableName,
343
- type: type
344
- });
345
- }
346
- });
347
- }
348
- });
349
- }
350
-
351
- module.exports = inferRootArgumentDefinitions;
package/lib/index.js DELETED
@@ -1,178 +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 _require = require('./bin/RelayCompilerMain'),
14
- main = _require.main;
15
-
16
- var CodegenDirectory = require('./codegen/CodegenDirectory');
17
-
18
- var CodegenRunner = require('./codegen/CodegenRunner');
19
-
20
- var CodegenWatcher = require('./codegen/CodegenWatcher');
21
-
22
- var compileRelayArtifacts = require('./codegen/compileRelayArtifacts');
23
-
24
- var RelayCodeGenerator = require('./codegen/RelayCodeGenerator');
25
-
26
- var RelayFileWriter = require('./codegen/RelayFileWriter');
27
-
28
- var _require2 = require('./codegen/SourceControl'),
29
- SourceControlMercurial = _require2.SourceControlMercurial;
30
-
31
- var writeRelayGeneratedFile = require('./codegen/writeRelayGeneratedFile');
32
-
33
- var ASTCache = require('./core/ASTCache');
34
-
35
- var ASTConvert = require('./core/ASTConvert');
36
-
37
- var CompilerContext = require('./core/CompilerContext');
38
-
39
- var CompilerError = require('./core/CompilerError');
40
-
41
- var DotGraphQLParser = require('./core/DotGraphQLParser');
42
-
43
- var filterContextForNode = require('./core/filterContextForNode');
44
-
45
- var getIdentifierForArgumentValue = require('./core/getIdentifierForArgumentValue');
46
-
47
- var getLiteralArgumentValues = require('./core/getLiteralArgumentValues');
48
-
49
- var getNormalizationOperationName = require('./core/getNormalizationOperationName');
50
-
51
- var GraphQLCompilerProfiler = require('./core/GraphQLCompilerProfiler');
52
-
53
- var _require3 = require('./core/GraphQLDerivedFromMetadata'),
54
- getReaderSourceDefinitionName = _require3.getReaderSourceDefinitionName;
55
-
56
- var GraphQLWatchmanClient = require('./core/GraphQLWatchmanClient');
57
-
58
- var IRPrinter = require('./core/IRPrinter');
59
-
60
- var IRTransformer = require('./core/IRTransformer');
61
-
62
- var IRVisitor = require('./core/IRVisitor');
63
-
64
- var JSModuleParser = require('./core/JSModuleParser');
65
-
66
- var RelayFindGraphQLTags = require('./core/RelayFindGraphQLTags');
67
-
68
- var RelayIRTransforms = require('./core/RelayIRTransforms');
69
-
70
- var RelayParser = require('./core/RelayParser');
71
-
72
- var RelaySchema = require('./core/Schema');
73
-
74
- var SchemaUtils = require('./core/SchemaUtils');
75
-
76
- var FindGraphQLTags = require('./language/javascript/FindGraphQLTags');
77
-
78
- var _require4 = require('./language/javascript/formatGeneratedModule'),
79
- formatGeneratedModule = _require4.formatGeneratedCommonjsModule;
80
-
81
- var RelayFlowGenerator = require('./language/javascript/RelayFlowGenerator');
82
-
83
- var ConsoleReporter = require('./reporters/ConsoleReporter');
84
-
85
- var MultiReporter = require('./reporters/MultiReporter');
86
-
87
- var Artifacts = require('./runner/Artifacts');
88
-
89
- var BufferedFilesystem = require('./runner/BufferedFilesystem');
90
-
91
- var compileArtifacts = require('./runner/compileArtifacts');
92
-
93
- var extractAST = require('./runner/extractAST');
94
-
95
- var getChangedNodeNames = require('./runner/getChangedNodeNames');
96
-
97
- var getSchemaInstance = require('./runner/getSchemaInstance');
98
-
99
- var GraphQLASTNodeGroup = require('./runner/GraphQLASTNodeGroup');
100
-
101
- var GraphQLASTUtils = require('./runner/GraphQLASTUtils');
102
-
103
- var GraphQLNodeMap = require('./runner/GraphQLNodeMap');
104
-
105
- var Sources = require('./runner/Sources');
106
-
107
- var StrictMap = require('./runner/StrictMap');
108
-
109
- var CodeMarker = require('./util/CodeMarker');
110
-
111
- var getDefinitionNodeHash = require('./util/getDefinitionNodeHash');
112
-
113
- var md5 = require('./util/md5');
114
-
115
- var Rollout = require('./util/Rollout');
116
-
117
- var TimeReporter = require('./util/TimeReporter');
118
-
119
- module.exports = {
120
- relayCompiler: main,
121
- ASTConvert: ASTConvert,
122
- CodegenDirectory: CodegenDirectory,
123
- CodegenRunner: CodegenRunner,
124
- CodegenWatcher: CodegenWatcher,
125
- CodeMarker: CodeMarker,
126
- CompilerContext: CompilerContext,
127
- CompilerError: CompilerError,
128
- ConsoleReporter: ConsoleReporter,
129
- DotGraphQLParser: DotGraphQLParser,
130
- ASTCache: ASTCache,
131
- IRTransformer: IRTransformer,
132
- IRVisitor: IRVisitor,
133
- Printer: IRPrinter,
134
- Profiler: GraphQLCompilerProfiler,
135
- Rollout: Rollout,
136
- SchemaUtils: SchemaUtils,
137
- SourceControlMercurial: SourceControlMercurial,
138
- WatchmanClient: GraphQLWatchmanClient,
139
- filterContextForNode: filterContextForNode,
140
- getIdentifierForArgumentValue: getIdentifierForArgumentValue,
141
- getNormalizationOperationName: getNormalizationOperationName,
142
- getLiteralArgumentValues: getLiteralArgumentValues,
143
- Parser: RelayParser,
144
- Schema: RelaySchema,
145
- CodeGenerator: RelayCodeGenerator,
146
- FlowGenerator: RelayFlowGenerator,
147
- FileWriter: RelayFileWriter,
148
- IRTransforms: RelayIRTransforms,
149
- JSModuleParser: JSModuleParser,
150
- MultiReporter: MultiReporter,
151
- Runner: CodegenRunner,
152
- TimeReporter: TimeReporter,
153
- compileRelayArtifacts: compileRelayArtifacts,
154
- formatGeneratedModule: formatGeneratedModule,
155
- convertASTDocuments: ASTConvert.convertASTDocuments,
156
- transformASTSchema: ASTConvert.transformASTSchema,
157
- getReaderSourceDefinitionName: getReaderSourceDefinitionName,
158
- writeRelayGeneratedFile: writeRelayGeneratedFile,
159
- Sources: Sources,
160
- __internal: {
161
- Artifacts: Artifacts,
162
- BufferedFilesystem: BufferedFilesystem,
163
- GraphQLASTNodeGroup: GraphQLASTNodeGroup,
164
- GraphQLASTUtils: GraphQLASTUtils,
165
- GraphQLNodeMap: GraphQLNodeMap,
166
- FindGraphQLTags: FindGraphQLTags,
167
- StrictMap: StrictMap,
168
- RelayFindGraphQLTags: RelayFindGraphQLTags,
169
- compileArtifacts: compileArtifacts,
170
- extractFromJS: extractAST.extractFromJS,
171
- getChangedNodeNames: getChangedNodeNames,
172
- getDefinitionNodeHash: getDefinitionNodeHash,
173
- getSchemaInstance: getSchemaInstance,
174
- md5: md5,
175
- parseExecutableNode: extractAST.parseExecutableNode,
176
- toASTRecord: extractAST.toASTRecord
177
- }
178
- };
@@ -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
- *
8
- * @format
9
- */
10
- // flowlint ambiguous-object-type:error
11
- 'use strict';
12
-
13
- var _require = require('relay-runtime'),
14
- RelayConcreteNode = _require.RelayConcreteNode;
15
- /**
16
- * A language plugin allows relay-compiler to both read and write files for any
17
- * language.
18
- *
19
- * When reading, the plugin is expected to parse and return GraphQL tags; and
20
- * when writing the plugin is responsible for generating type information about
21
- * the GraphQL selections made as well as generating the contents of the
22
- * artifact file.
23
- *
24
- * This interface describes the details relay-compiler requires to be able to
25
- * use the plugin and is expected to be returned by a {PluginInitializer}.
26
- */
@@ -1,126 +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 Profiler = require('../../core/GraphQLCompilerProfiler');
14
-
15
- var babylon = require('@babel/parser');
16
-
17
- var util = require('util'); // Attempt to be as inclusive as possible of source text.
18
-
19
-
20
- var BABYLON_OPTIONS = {
21
- allowImportExportEverywhere: true,
22
- allowReturnOutsideFunction: true,
23
- allowSuperOutsideMethod: true,
24
- sourceType: 'module',
25
- plugins: ['asyncGenerators', 'classProperties', ['decorators', {
26
- decoratorsBeforeExport: true
27
- }], 'doExpressions', 'dynamicImport', 'exportExtensions', ['flow', {
28
- enums: true
29
- }], 'functionBind', 'functionSent', 'jsx', 'nullishCoalescingOperator', 'objectRestSpread', 'optionalChaining', 'optionalCatchBinding'],
30
- strictMode: false
31
- };
32
-
33
- function find(text) {
34
- var result = []; // $FlowFixMe Discovered when typing babel/parser
35
-
36
- var ast = babylon.parse(text, BABYLON_OPTIONS);
37
- var visitors = {
38
- TaggedTemplateExpression: function TaggedTemplateExpression(node) {
39
- if (isGraphQLTag(node.tag)) {
40
- result.push({
41
- keyName: null,
42
- template: node.quasi.quasis[0].value.raw,
43
- sourceLocationOffset: getSourceLocationOffset(node.quasi)
44
- });
45
- }
46
- }
47
- };
48
- visit(ast, visitors);
49
- return result;
50
- }
51
-
52
- var IGNORED_KEYS = {
53
- comments: true,
54
- end: true,
55
- leadingComments: true,
56
- loc: true,
57
- name: true,
58
- start: true,
59
- trailingComments: true,
60
- type: true
61
- };
62
-
63
- function isGraphQLTag(tag) {
64
- return tag.type === 'Identifier' && tag.name === 'graphql';
65
- }
66
-
67
- function getTemplateNode(quasi) {
68
- var quasis = quasi.quasis;
69
- !(quasis && quasis.length === 1) ? process.env.NODE_ENV !== "production" ? invariant(false, 'FindGraphQLTags: Substitutions are not allowed in graphql tags.') : invariant(false) : void 0;
70
- return quasis[0];
71
- }
72
-
73
- function getSourceLocationOffset(quasi) {
74
- var loc = getTemplateNode(quasi).loc.start;
75
- return {
76
- line: loc.line,
77
- column: loc.column + 1 // babylon is 0-indexed, graphql expects 1-indexed
78
-
79
- };
80
- }
81
-
82
- function invariant(condition, msg) {
83
- if (!condition) {
84
- for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
85
- args[_key - 2] = arguments[_key];
86
- }
87
-
88
- throw new Error(util.format.apply(util, [msg].concat(args)));
89
- }
90
- }
91
-
92
- function visit(node, visitors) {
93
- // $FlowFixMe Discovered when typing babel
94
- var fn = visitors[node.type];
95
-
96
- if (fn != null) {
97
- fn(node);
98
- return;
99
- }
100
-
101
- traverse(node, visitors);
102
- }
103
-
104
- function traverse(node, visitors) {
105
- for (var key in node) {
106
- if (IGNORED_KEYS[key]) {
107
- continue;
108
- }
109
-
110
- var prop = node[key];
111
-
112
- if (prop && typeof prop === 'object' && typeof prop.type === 'string') {
113
- visit(prop, visitors);
114
- } else if (Array.isArray(prop)) {
115
- prop.forEach(function (item) {
116
- if (item && typeof item === 'object' && typeof item.type === 'string') {
117
- visit(item, visitors);
118
- }
119
- });
120
- }
121
- }
122
- }
123
-
124
- module.exports = {
125
- find: Profiler.instrument(find, 'FindGraphQLTags.find')
126
- };