relay-compiler 11.0.1 → 13.0.0-rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (260) hide show
  1. package/cli.js +23 -0
  2. package/index.js +21 -3
  3. package/linux-x64/relay +0 -0
  4. package/macos-arm64/relay +0 -0
  5. package/macos-x64/relay +0 -0
  6. package/package.json +2 -25
  7. package/win-x64/relay.exe +0 -0
  8. package/bin/RelayCompilerBin.js.flow +0 -169
  9. package/bin/RelayCompilerMain.js.flow +0 -515
  10. package/bin/__fixtures__/plugin-module.js.flow +0 -17
  11. package/bin/relay-compiler +0 -19007
  12. package/codegen/CodegenDirectory.js.flow +0 -375
  13. package/codegen/CodegenRunner.js.flow +0 -432
  14. package/codegen/CodegenTypes.js.flow +0 -28
  15. package/codegen/CodegenWatcher.js.flow +0 -254
  16. package/codegen/NormalizationCodeGenerator.js.flow +0 -571
  17. package/codegen/ReaderCodeGenerator.js.flow +0 -512
  18. package/codegen/RelayCodeGenerator.js.flow +0 -85
  19. package/codegen/RelayFileWriter.js.flow +0 -367
  20. package/codegen/SourceControl.js.flow +0 -58
  21. package/codegen/compileRelayArtifacts.js.flow +0 -182
  22. package/codegen/createPrintRequireModuleDependency.js.flow +0 -21
  23. package/codegen/sortObjectByKey.js.flow +0 -25
  24. package/codegen/writeRelayGeneratedFile.js.flow +0 -239
  25. package/core/ASTCache.js.flow +0 -74
  26. package/core/ASTConvert.js.flow +0 -233
  27. package/core/CompilerContext.js.flow +0 -191
  28. package/core/CompilerError.js.flow +0 -255
  29. package/core/DotGraphQLParser.js.flow +0 -39
  30. package/core/GraphQLCompilerProfiler.js.flow +0 -341
  31. package/core/GraphQLDerivedFromMetadata.js.flow +0 -36
  32. package/core/GraphQLWatchmanClient.js.flow +0 -111
  33. package/core/IR.js.flow +0 -326
  34. package/core/IRPrinter.js.flow +0 -478
  35. package/core/IRTransformer.js.flow +0 -377
  36. package/core/IRValidator.js.flow +0 -260
  37. package/core/IRVisitor.js.flow +0 -150
  38. package/core/JSModuleParser.js.flow +0 -24
  39. package/core/RelayCompilerScope.js.flow +0 -199
  40. package/core/RelayFindGraphQLTags.js.flow +0 -119
  41. package/core/RelayGraphQLEnumsGenerator.js.flow +0 -55
  42. package/core/RelayIRTransforms.js.flow +0 -138
  43. package/core/RelayParser.js.flow +0 -1734
  44. package/core/RelaySourceModuleParser.js.flow +0 -135
  45. package/core/Schema.js.flow +0 -2037
  46. package/core/SchemaUtils.js.flow +0 -120
  47. package/core/filterContextForNode.js.flow +0 -50
  48. package/core/getFieldDefinition.js.flow +0 -156
  49. package/core/getIdentifierForArgumentValue.js.flow +0 -49
  50. package/core/getIdentifierForSelection.js.flow +0 -69
  51. package/core/getLiteralArgumentValues.js.flow +0 -32
  52. package/core/getNormalizationOperationName.js.flow +0 -19
  53. package/core/inferRootArgumentDefinitions.js.flow +0 -323
  54. package/index.js.flow +0 -200
  55. package/language/RelayLanguagePluginInterface.js.flow +0 -283
  56. package/language/javascript/FindGraphQLTags.js.flow +0 -137
  57. package/language/javascript/RelayFlowBabelFactories.js.flow +0 -176
  58. package/language/javascript/RelayFlowGenerator.js.flow +0 -1100
  59. package/language/javascript/RelayFlowTypeTransformers.js.flow +0 -184
  60. package/language/javascript/RelayLanguagePluginJavaScript.js.flow +0 -34
  61. package/language/javascript/formatGeneratedModule.js.flow +0 -65
  62. package/lib/bin/RelayCompilerBin.js +0 -143
  63. package/lib/bin/RelayCompilerMain.js +0 -486
  64. package/lib/bin/__fixtures__/plugin-module.js +0 -16
  65. package/lib/codegen/CodegenDirectory.js +0 -336
  66. package/lib/codegen/CodegenRunner.js +0 -433
  67. package/lib/codegen/CodegenTypes.js +0 -11
  68. package/lib/codegen/CodegenWatcher.js +0 -271
  69. package/lib/codegen/NormalizationCodeGenerator.js +0 -481
  70. package/lib/codegen/ReaderCodeGenerator.js +0 -472
  71. package/lib/codegen/RelayCodeGenerator.js +0 -68
  72. package/lib/codegen/RelayFileWriter.js +0 -270
  73. package/lib/codegen/SourceControl.js +0 -60
  74. package/lib/codegen/compileRelayArtifacts.js +0 -157
  75. package/lib/codegen/createPrintRequireModuleDependency.js +0 -19
  76. package/lib/codegen/sortObjectByKey.js +0 -41
  77. package/lib/codegen/writeRelayGeneratedFile.js +0 -208
  78. package/lib/core/ASTCache.js +0 -70
  79. package/lib/core/ASTConvert.js +0 -198
  80. package/lib/core/CompilerContext.js +0 -165
  81. package/lib/core/CompilerError.js +0 -251
  82. package/lib/core/DotGraphQLParser.js +0 -40
  83. package/lib/core/GraphQLCompilerProfiler.js +0 -299
  84. package/lib/core/GraphQLDerivedFromMetadata.js +0 -31
  85. package/lib/core/GraphQLWatchmanClient.js +0 -150
  86. package/lib/core/IR.js +0 -11
  87. package/lib/core/IRPrinter.js +0 -389
  88. package/lib/core/IRTransformer.js +0 -345
  89. package/lib/core/IRValidator.js +0 -226
  90. package/lib/core/IRVisitor.js +0 -45
  91. package/lib/core/JSModuleParser.js +0 -18
  92. package/lib/core/RelayCompilerScope.js +0 -149
  93. package/lib/core/RelayFindGraphQLTags.js +0 -79
  94. package/lib/core/RelayGraphQLEnumsGenerator.js +0 -50
  95. package/lib/core/RelayIRTransforms.js +0 -109
  96. package/lib/core/RelayParser.js +0 -1382
  97. package/lib/core/RelaySourceModuleParser.js +0 -104
  98. package/lib/core/Schema.js +0 -1877
  99. package/lib/core/SchemaUtils.js +0 -98
  100. package/lib/core/filterContextForNode.js +0 -49
  101. package/lib/core/getFieldDefinition.js +0 -145
  102. package/lib/core/getIdentifierForArgumentValue.js +0 -53
  103. package/lib/core/getIdentifierForSelection.js +0 -48
  104. package/lib/core/getLiteralArgumentValues.js +0 -26
  105. package/lib/core/getNormalizationOperationName.js +0 -17
  106. package/lib/core/inferRootArgumentDefinitions.js +0 -351
  107. package/lib/index.js +0 -178
  108. package/lib/language/RelayLanguagePluginInterface.js +0 -14
  109. package/lib/language/javascript/FindGraphQLTags.js +0 -126
  110. package/lib/language/javascript/RelayFlowBabelFactories.js +0 -160
  111. package/lib/language/javascript/RelayFlowGenerator.js +0 -857
  112. package/lib/language/javascript/RelayFlowTypeTransformers.js +0 -119
  113. package/lib/language/javascript/RelayLanguagePluginJavaScript.js +0 -30
  114. package/lib/language/javascript/formatGeneratedModule.js +0 -36
  115. package/lib/reporters/ConsoleReporter.js +0 -61
  116. package/lib/reporters/MultiReporter.js +0 -45
  117. package/lib/reporters/Reporter.js +0 -11
  118. package/lib/runner/Artifacts.js +0 -323
  119. package/lib/runner/BufferedFilesystem.js +0 -261
  120. package/lib/runner/GraphQLASTNodeGroup.js +0 -256
  121. package/lib/runner/GraphQLASTUtils.js +0 -23
  122. package/lib/runner/GraphQLNodeMap.js +0 -81
  123. package/lib/runner/Sources.js +0 -271
  124. package/lib/runner/StrictMap.js +0 -134
  125. package/lib/runner/compileArtifacts.js +0 -39
  126. package/lib/runner/extractAST.js +0 -77
  127. package/lib/runner/getChangedNodeNames.js +0 -82
  128. package/lib/runner/getSchemaInstance.js +0 -30
  129. package/lib/runner/types.js +0 -12
  130. package/lib/transforms/ApplyFragmentArgumentTransform.js +0 -393
  131. package/lib/transforms/ClientExtensionsTransform.js +0 -221
  132. package/lib/transforms/ConnectionTransform.js +0 -639
  133. package/lib/transforms/DeclarativeConnectionMutationTransform.js +0 -218
  134. package/lib/transforms/DeferStreamTransform.js +0 -246
  135. package/lib/transforms/DisallowIdAsAlias.js +0 -40
  136. package/lib/transforms/DisallowTypenameOnRoot.js +0 -53
  137. package/lib/transforms/FieldHandleTransform.js +0 -79
  138. package/lib/transforms/FilterCompilerDirectivesTransform.js +0 -29
  139. package/lib/transforms/FilterDirectivesTransform.js +0 -41
  140. package/lib/transforms/FlattenTransform.js +0 -306
  141. package/lib/transforms/GenerateIDFieldTransform.js +0 -135
  142. package/lib/transforms/GenerateTypeNameTransform.js +0 -149
  143. package/lib/transforms/InlineDataFragmentTransform.js +0 -100
  144. package/lib/transforms/InlineFragmentsTransform.js +0 -61
  145. package/lib/transforms/MaskTransform.js +0 -117
  146. package/lib/transforms/MatchTransform.js +0 -434
  147. package/lib/transforms/ReactFlightComponentTransform.js +0 -158
  148. package/lib/transforms/RefetchableFragmentTransform.js +0 -249
  149. package/lib/transforms/RelayDirectiveTransform.js +0 -83
  150. package/lib/transforms/RequiredFieldTransform.js +0 -369
  151. package/lib/transforms/SkipClientExtensionsTransform.js +0 -46
  152. package/lib/transforms/SkipHandleFieldTransform.js +0 -44
  153. package/lib/transforms/SkipRedundantNodesTransform.js +0 -254
  154. package/lib/transforms/SkipSplitOperationTransform.js +0 -32
  155. package/lib/transforms/SkipUnreachableNodeTransform.js +0 -158
  156. package/lib/transforms/SkipUnusedVariablesTransform.js +0 -74
  157. package/lib/transforms/SplitModuleImportTransform.js +0 -82
  158. package/lib/transforms/TestOperationTransform.js +0 -144
  159. package/lib/transforms/TransformUtils.js +0 -21
  160. package/lib/transforms/ValidateGlobalVariablesTransform.js +0 -91
  161. package/lib/transforms/ValidateRequiredArgumentsTransform.js +0 -114
  162. package/lib/transforms/ValidateServerOnlyDirectivesTransform.js +0 -108
  163. package/lib/transforms/ValidateUnusedVariablesTransform.js +0 -96
  164. package/lib/transforms/query-generators/FetchableQueryGenerator.js +0 -157
  165. package/lib/transforms/query-generators/NodeQueryGenerator.js +0 -166
  166. package/lib/transforms/query-generators/QueryQueryGenerator.js +0 -48
  167. package/lib/transforms/query-generators/ViewerQueryGenerator.js +0 -77
  168. package/lib/transforms/query-generators/index.js +0 -60
  169. package/lib/transforms/query-generators/utils.js +0 -92
  170. package/lib/util/CodeMarker.js +0 -80
  171. package/lib/util/DefaultHandleKey.js +0 -15
  172. package/lib/util/RelayCompilerCache.js +0 -98
  173. package/lib/util/Rollout.js +0 -40
  174. package/lib/util/TimeReporter.js +0 -83
  175. package/lib/util/areEqualOSS.js +0 -133
  176. package/lib/util/argumentContainsVariables.js +0 -37
  177. package/lib/util/dedupeJSONStringify.js +0 -160
  178. package/lib/util/generateAbstractTypeRefinementKey.js +0 -24
  179. package/lib/util/getDefinitionNodeHash.js +0 -22
  180. package/lib/util/getModuleName.js +0 -32
  181. package/lib/util/joinArgumentDefinitions.js +0 -66
  182. package/lib/util/md5.js +0 -17
  183. package/lib/util/murmurHash.js +0 -86
  184. package/lib/util/nullthrowsOSS.js +0 -23
  185. package/lib/util/orList.js +0 -36
  186. package/lib/util/partitionArray.js +0 -35
  187. package/relay-compiler.js +0 -17
  188. package/relay-compiler.min.js +0 -22
  189. package/reporters/ConsoleReporter.js.flow +0 -81
  190. package/reporters/MultiReporter.js.flow +0 -43
  191. package/reporters/Reporter.js.flow +0 -19
  192. package/runner/Artifacts.js.flow +0 -219
  193. package/runner/BufferedFilesystem.js.flow +0 -194
  194. package/runner/GraphQLASTNodeGroup.js.flow +0 -176
  195. package/runner/GraphQLASTUtils.js.flow +0 -26
  196. package/runner/GraphQLNodeMap.js.flow +0 -55
  197. package/runner/Sources.js.flow +0 -228
  198. package/runner/StrictMap.js.flow +0 -96
  199. package/runner/compileArtifacts.js.flow +0 -76
  200. package/runner/extractAST.js.flow +0 -100
  201. package/runner/getChangedNodeNames.js.flow +0 -48
  202. package/runner/getSchemaInstance.js.flow +0 -36
  203. package/runner/types.js.flow +0 -37
  204. package/transforms/ApplyFragmentArgumentTransform.js.flow +0 -526
  205. package/transforms/ClientExtensionsTransform.js.flow +0 -225
  206. package/transforms/ConnectionTransform.js.flow +0 -855
  207. package/transforms/DeclarativeConnectionMutationTransform.js.flow +0 -247
  208. package/transforms/DeferStreamTransform.js.flow +0 -265
  209. package/transforms/DisallowIdAsAlias.js.flow +0 -47
  210. package/transforms/DisallowTypenameOnRoot.js.flow +0 -45
  211. package/transforms/FieldHandleTransform.js.flow +0 -79
  212. package/transforms/FilterCompilerDirectivesTransform.js.flow +0 -33
  213. package/transforms/FilterDirectivesTransform.js.flow +0 -45
  214. package/transforms/FlattenTransform.js.flow +0 -457
  215. package/transforms/GenerateIDFieldTransform.js.flow +0 -152
  216. package/transforms/GenerateTypeNameTransform.js.flow +0 -161
  217. package/transforms/InlineDataFragmentTransform.js.flow +0 -125
  218. package/transforms/InlineFragmentsTransform.js.flow +0 -71
  219. package/transforms/MaskTransform.js.flow +0 -126
  220. package/transforms/MatchTransform.js.flow +0 -589
  221. package/transforms/ReactFlightComponentTransform.js.flow +0 -195
  222. package/transforms/RefetchableFragmentTransform.js.flow +0 -272
  223. package/transforms/RelayDirectiveTransform.js.flow +0 -97
  224. package/transforms/RequiredFieldTransform.js.flow +0 -415
  225. package/transforms/SkipClientExtensionsTransform.js.flow +0 -54
  226. package/transforms/SkipHandleFieldTransform.js.flow +0 -44
  227. package/transforms/SkipRedundantNodesTransform.js.flow +0 -258
  228. package/transforms/SkipSplitOperationTransform.js.flow +0 -37
  229. package/transforms/SkipUnreachableNodeTransform.js.flow +0 -149
  230. package/transforms/SkipUnusedVariablesTransform.js.flow +0 -59
  231. package/transforms/SplitModuleImportTransform.js.flow +0 -98
  232. package/transforms/TestOperationTransform.js.flow +0 -142
  233. package/transforms/TransformUtils.js.flow +0 -26
  234. package/transforms/ValidateGlobalVariablesTransform.js.flow +0 -81
  235. package/transforms/ValidateRequiredArgumentsTransform.js.flow +0 -127
  236. package/transforms/ValidateServerOnlyDirectivesTransform.js.flow +0 -112
  237. package/transforms/ValidateUnusedVariablesTransform.js.flow +0 -89
  238. package/transforms/query-generators/FetchableQueryGenerator.js.flow +0 -189
  239. package/transforms/query-generators/NodeQueryGenerator.js.flow +0 -219
  240. package/transforms/query-generators/QueryQueryGenerator.js.flow +0 -57
  241. package/transforms/query-generators/ViewerQueryGenerator.js.flow +0 -97
  242. package/transforms/query-generators/index.js.flow +0 -90
  243. package/transforms/query-generators/utils.js.flow +0 -76
  244. package/util/CodeMarker.js.flow +0 -79
  245. package/util/DefaultHandleKey.js.flow +0 -17
  246. package/util/RelayCompilerCache.js.flow +0 -88
  247. package/util/Rollout.js.flow +0 -39
  248. package/util/TimeReporter.js.flow +0 -79
  249. package/util/areEqualOSS.js.flow +0 -123
  250. package/util/argumentContainsVariables.js.flow +0 -38
  251. package/util/dedupeJSONStringify.js.flow +0 -152
  252. package/util/generateAbstractTypeRefinementKey.js.flow +0 -29
  253. package/util/getDefinitionNodeHash.js.flow +0 -25
  254. package/util/getModuleName.js.flow +0 -39
  255. package/util/joinArgumentDefinitions.js.flow +0 -105
  256. package/util/md5.js.flow +0 -22
  257. package/util/murmurHash.js.flow +0 -94
  258. package/util/nullthrowsOSS.js.flow +0 -25
  259. package/util/orList.js.flow +0 -37
  260. package/util/partitionArray.js.flow +0 -37
@@ -1,434 +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 IRTransformer = require('../core/IRTransformer');
20
-
21
- var getLiteralArgumentValues = require('../core/getLiteralArgumentValues');
22
-
23
- var getNormalizationOperationName = require('../core/getNormalizationOperationName');
24
-
25
- var _require = require('../core/CompilerError'),
26
- createCompilerError = _require.createCompilerError,
27
- createUserError = _require.createUserError;
28
-
29
- var _require2 = require('relay-runtime'),
30
- getModuleComponentKey = _require2.getModuleComponentKey,
31
- getModuleOperationKey = _require2.getModuleOperationKey;
32
-
33
- var SUPPORTED_ARGUMENT_NAME = 'supported';
34
- var JS_FIELD_TYPE = 'JSDependency';
35
- var JS_FIELD_MODULE_ARG = 'module';
36
- var JS_FIELD_ID_ARG = 'id';
37
- var JS_FIELD_NAME = 'js';
38
- var SCHEMA_EXTENSION = "\n directive @match(key: String) on FIELD\n\n directive @module(\n name: String!\n ) on FRAGMENT_SPREAD\n";
39
-
40
- /**
41
- * This transform rewrites LinkedField nodes with @match and rewrites them
42
- * into `LinkedField` nodes with a `supported` argument.
43
- */
44
- function matchTransform(context) {
45
- return IRTransformer.transform(context, {
46
- // TODO: type IRTransformer to allow changing result type
47
- FragmentSpread: visitFragmentSpread,
48
- LinkedField: visitLinkedField,
49
- InlineFragment: visitInlineFragment,
50
- ScalarField: visitScalarField
51
- }, function (node) {
52
- return {
53
- documentName: node.name,
54
- matchesForPath: new Map(),
55
- moduleKey: null,
56
- parentType: node.type,
57
- path: []
58
- };
59
- });
60
- }
61
-
62
- function visitInlineFragment(node, state) {
63
- return this.traverse(node, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, state), {}, {
64
- parentType: node.typeCondition
65
- }));
66
- }
67
-
68
- function visitScalarField(field) {
69
- var context = this.getContext();
70
- var schema = context.getSchema();
71
-
72
- if (field.name === JS_FIELD_NAME) {
73
- var jsModuleType = schema.getTypeFromString(JS_FIELD_TYPE);
74
-
75
- if (jsModuleType == null || !schema.isServerType(jsModuleType)) {
76
- throw new createUserError("'".concat(JS_FIELD_NAME, "' should be defined on the server schema."), [field.loc]);
77
- }
78
-
79
- if (schema.isScalar(jsModuleType) && schema.areEqualTypes(schema.getRawType(field.type), jsModuleType)) {
80
- throw new createUserError("Direct use of the '".concat(JS_FIELD_NAME, "' field is not allowed, use ") + '@match/@module instead.', [field.loc]);
81
- }
82
- }
83
-
84
- return field;
85
- }
86
-
87
- function visitLinkedField(node, state) {
88
- var context = this.getContext();
89
- var schema = context.getSchema();
90
- var matchDirective = node.directives.find(function (directive) {
91
- return directive.name === 'match';
92
- });
93
- var moduleKey = null;
94
-
95
- if (matchDirective != null) {
96
- var _getLiteralArgumentVa = getLiteralArgumentValues(matchDirective.args);
97
-
98
- moduleKey = _getLiteralArgumentVa.key;
99
-
100
- if (moduleKey != null && (typeof moduleKey !== 'string' || !moduleKey.startsWith(state.documentName))) {
101
- var _matchDirective$args$;
102
-
103
- throw createUserError("Expected the 'key' argument of @match to be a literal string starting " + "with the document name, e.g. '".concat(state.documentName, "_<localName>'."), [((_matchDirective$args$ = matchDirective.args.find(function (arg) {
104
- return arg.name === 'key';
105
- })) !== null && _matchDirective$args$ !== void 0 ? _matchDirective$args$ : matchDirective).loc]);
106
- }
107
- }
108
-
109
- state.path.push(node);
110
- var transformedNode = this.traverse(node, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, state), {}, {
111
- moduleKey: moduleKey,
112
- parentType: node.type
113
- }));
114
- state.path.pop();
115
-
116
- if (matchDirective == null) {
117
- return transformedNode;
118
- }
119
-
120
- var parentType = state.parentType;
121
- var rawType = schema.getRawType(parentType);
122
-
123
- if (!(schema.isInterface(rawType) || schema.isObject(rawType))) {
124
- throw createUserError("@match used on incompatible field '".concat(transformedNode.name, "'.") + '@match may only be used with fields whose parent type is an ' + "interface or object, got invalid type '".concat(schema.getTypeString(parentType), "'."), [node.loc]);
125
- }
126
-
127
- var currentField = schema.getFieldConfig(schema.expectField(schema.assertCompositeType(rawType), transformedNode.name));
128
- var supportedArgumentDefinition = currentField.args.find(function (_ref) {
129
- var name = _ref.name;
130
- return name === SUPPORTED_ARGUMENT_NAME;
131
- });
132
-
133
- if (supportedArgumentDefinition == null) {
134
- if (moduleKey == null) {
135
- throw createUserError('@match on a field without the `supported` argument is a no-op, please remove the `@match`.', [node.loc]);
136
- }
137
-
138
- return transformedNode;
139
- }
140
-
141
- var supportedArgType = schema.getNullableType(supportedArgumentDefinition.type);
142
- var supportedArgOfType = supportedArgType != null && schema.isList(supportedArgType) ? schema.getListItemType(supportedArgType) : null;
143
-
144
- if (supportedArgType == null || supportedArgOfType == null || !schema.isString(schema.getNullableType(supportedArgOfType))) {
145
- throw createUserError("@match used on incompatible field '".concat(transformedNode.name, "'. ") + '@match may only be used with fields that accept a ' + "'supported: [String!]!' argument.", [node.loc]);
146
- }
147
-
148
- var rawFieldType = schema.getRawType(transformedNode.type);
149
-
150
- if (!schema.isAbstractType(rawFieldType)) {
151
- throw createUserError("@match used on incompatible field '".concat(transformedNode.name, "'.") + '@match may only be used with fields that return a union or interface.', [node.loc]);
152
- }
153
-
154
- var seenTypes = new Map();
155
- var selections = [];
156
- transformedNode.selections.forEach(function (matchSelection) {
157
- if (matchSelection.kind === 'ScalarField' && matchSelection.name === '__typename') {
158
- selections.push(matchSelection);
159
- return;
160
- }
161
-
162
- var moduleImport = matchSelection.kind === 'InlineFragment' ? matchSelection.selections[0] : null;
163
-
164
- if (matchSelection.kind !== 'InlineFragment' || moduleImport == null || moduleImport.kind !== 'ModuleImport') {
165
- throw createUserError('Invalid @match selection: all selections should be ' + 'fragment spreads with @module.', [matchSelection.loc]);
166
- }
167
-
168
- var matchedType = matchSelection.typeCondition;
169
- seenTypes.set(matchedType, matchSelection);
170
- selections.push(matchSelection);
171
- });
172
-
173
- if (seenTypes.size === 0) {
174
- throw createUserError('Invalid @match selection: expected at least one @module selection. ' + "Remove @match or add a '...Fragment @module()' selection.", [matchDirective.loc]);
175
- }
176
-
177
- var supportedArg = transformedNode.args.find(function (arg) {
178
- return arg.name === SUPPORTED_ARGUMENT_NAME;
179
- });
180
-
181
- if (supportedArg != null) {
182
- throw createUserError("Invalid @match selection: the '".concat(SUPPORTED_ARGUMENT_NAME, "' argument ") + 'is automatically added and cannot be supplied explicitly.', [supportedArg.loc]);
183
- }
184
-
185
- return {
186
- kind: 'LinkedField',
187
- alias: transformedNode.alias,
188
- args: [].concat((0, _toConsumableArray2["default"])(transformedNode.args), [{
189
- kind: 'Argument',
190
- name: SUPPORTED_ARGUMENT_NAME,
191
- type: supportedArgumentDefinition.type,
192
- value: {
193
- kind: 'Literal',
194
- loc: node.loc,
195
- value: Array.from(seenTypes.keys()).map(function (type) {
196
- return schema.getTypeString(type);
197
- })
198
- },
199
- loc: node.loc
200
- }]),
201
- connection: false,
202
- directives: [],
203
- handles: null,
204
- loc: node.loc,
205
- metadata: null,
206
- name: transformedNode.name,
207
- type: transformedNode.type,
208
- selections: selections
209
- };
210
- } // Transform @module
211
-
212
-
213
- function visitFragmentSpread(spread, _ref2) {
214
- var _moduleDirective$args2, _moduleDirective$args3, _moduleDirective$args4, _moduleDirective$args5, _moduleDirective$args6, _moduleDirective$args7;
215
-
216
- var documentName = _ref2.documentName,
217
- path = _ref2.path,
218
- matchesForPath = _ref2.matchesForPath,
219
- moduleKeyFromParent = _ref2.moduleKey;
220
- var transformedNode = this.traverse(spread);
221
- var moduleDirective = transformedNode.directives.find(function (directive) {
222
- return directive.name === 'module';
223
- });
224
-
225
- if (moduleDirective == null) {
226
- return transformedNode;
227
- }
228
-
229
- if (spread.args.length !== 0) {
230
- var _spread$args$;
231
-
232
- throw createUserError('@module does not support @arguments.', [(_spread$args$ = spread.args[0]) === null || _spread$args$ === void 0 ? void 0 : _spread$args$.loc].filter(Boolean));
233
- }
234
-
235
- var context = this.getContext();
236
- var schema = context.getSchema();
237
- var jsModuleType = schema.asScalarFieldType(schema.getTypeFromString(JS_FIELD_TYPE));
238
-
239
- if (jsModuleType == null || !schema.isServerType(jsModuleType)) {
240
- throw new createUserError("'".concat(JS_FIELD_NAME, "' should be defined on the server schema."), [spread.loc]);
241
- }
242
-
243
- if (!schema.isScalar(jsModuleType)) {
244
- throw createUserError('Using @module requires the schema to define a scalar ' + "'".concat(JS_FIELD_TYPE, "' type."));
245
- }
246
-
247
- var fragment = context.getFragment(spread.name, spread.loc);
248
-
249
- if (!schema.isObject(fragment.type)) {
250
- throw createUserError("@module used on invalid fragment spread '...".concat(spread.name, "'. @module ") + 'may only be used with fragments on a concrete (object) type, ' + "but the fragment has abstract type '".concat(schema.getTypeString(fragment.type), "'."), [spread.loc, fragment.loc]);
251
- }
252
-
253
- var field = schema.getFieldByName(fragment.type, JS_FIELD_NAME);
254
-
255
- if (!field) {
256
- throw createUserError("@module used on invalid fragment spread '...".concat(spread.name, "'. @module ") + "requires the fragment type '".concat(schema.getTypeString(fragment.type), "' to have a ") + "'".concat(JS_FIELD_NAME, "(").concat(JS_FIELD_MODULE_ARG, ": String! ") + "[".concat(JS_FIELD_ID_ARG, ": String]): ").concat(JS_FIELD_TYPE, "' field (your ") + "schema may choose to omit the 'id' argument but if present it " + "must accept a 'String').", [moduleDirective.loc]);
257
- }
258
-
259
- var jsField = schema.getFieldConfig(field);
260
- var jsFieldModuleArg = jsField ? jsField.args.find(function (arg) {
261
- return arg.name === JS_FIELD_MODULE_ARG;
262
- }) : null;
263
- var jsFieldIdArg = jsField ? jsField.args.find(function (arg) {
264
- return arg.name === JS_FIELD_ID_ARG;
265
- }) : null;
266
-
267
- if (jsFieldModuleArg == null || !schema.isString(schema.getNullableType(jsFieldModuleArg.type)) || jsFieldIdArg != null && !schema.isString(jsFieldIdArg.type) || jsField.type !== jsModuleType) {
268
- throw createUserError("@module used on invalid fragment spread '...".concat(spread.name, "'. @module ") + "requires the fragment type '".concat(schema.getTypeString(fragment.type), "' to have a ") + "'".concat(JS_FIELD_NAME, "(").concat(JS_FIELD_MODULE_ARG, ": String! ") + "[".concat(JS_FIELD_ID_ARG, ": String]): ").concat(JS_FIELD_TYPE, "' field (your ") + "schema may choose to omit the 'id' argument but if present it " + "must accept a 'String').", [moduleDirective.loc]);
269
- }
270
-
271
- if (spread.directives.length !== 1) {
272
- throw createUserError("@module used on invalid fragment spread '...".concat(spread.name, "'. @module ") + 'may not have additional directives.', [spread.loc]);
273
- }
274
-
275
- var _getLiteralArgumentVa2 = getLiteralArgumentValues(moduleDirective.args),
276
- moduleName = _getLiteralArgumentVa2.name;
277
-
278
- if (typeof moduleName !== 'string') {
279
- var _moduleDirective$args;
280
-
281
- throw createUserError("Expected the 'name' argument of @module to be a literal string", [((_moduleDirective$args = moduleDirective.args.find(function (arg) {
282
- return arg.name === 'name';
283
- })) !== null && _moduleDirective$args !== void 0 ? _moduleDirective$args : spread).loc]);
284
- }
285
-
286
- var parentField = path[path.length - 1];
287
- var moduleKey = moduleKeyFromParent !== null && moduleKeyFromParent !== void 0 ? moduleKeyFromParent : documentName;
288
- var aliasPath = path.map(function (x) {
289
- return x.alias;
290
- }).join('.');
291
- var moduleId = aliasPath === '' ? documentName : "".concat(documentName, ".").concat(aliasPath);
292
- var typeName = schema.getTypeString(fragment.type);
293
- var matches = matchesForPath.get(aliasPath);
294
-
295
- if (matches == null) {
296
- var _parentField$loc;
297
-
298
- if (matchesForPath.size !== 0) {
299
- var existingMatchWithKey = Array.from(matchesForPath.values()).find(function (entry) {
300
- return entry.key === moduleKey;
301
- });
302
-
303
- if (existingMatchWithKey != null) {
304
- if (parentField == null) {
305
- throw createCompilerError('Cannot have @module selections at multiple paths unless the selections are within fields.', [spread.loc]);
306
- }
307
-
308
- throw createUserError('Invalid @module selection: documents with multiple fields ' + "containing 3D selections must specify a unique 'key' value " + "for each field: use '".concat(parentField.alias, " @match(key: \"").concat(documentName, "_<localName>\")'."), [parentField.loc]);
309
- }
310
- }
311
-
312
- matches = {
313
- key: moduleKey,
314
- location: (_parentField$loc = parentField === null || parentField === void 0 ? void 0 : parentField.loc) !== null && _parentField$loc !== void 0 ? _parentField$loc : spread.loc,
315
- types: new Map()
316
- };
317
- matchesForPath.set(aliasPath, matches);
318
- }
319
-
320
- if (moduleKey !== matches.key) {
321
- var _parentField$loc2;
322
-
323
- // The user can't override the key locally (per @module),
324
- // so this is just an internal sanity check
325
- throw createCompilerError('Invalid @module selection: expected all selections at path ' + "'".concat(aliasPath, " to have the same 'key', got '").concat(moduleKey, "' and '").concat(matches.key, "'."), [(_parentField$loc2 = parentField === null || parentField === void 0 ? void 0 : parentField.loc) !== null && _parentField$loc2 !== void 0 ? _parentField$loc2 : spread.loc]);
326
- }
327
-
328
- var previousMatchForType = matches.types.get(typeName);
329
-
330
- if (previousMatchForType != null && (previousMatchForType.fragment !== spread.name || previousMatchForType.module !== moduleName)) {
331
- throw createUserError('Invalid @module selection: concrete type ' + "'".concat(typeName, "' was matched multiple times at path ") + "'".concat(aliasPath, "' but with a different fragment or module name."), [spread.loc, previousMatchForType.location]);
332
- }
333
-
334
- matches.types.set(typeName, {
335
- location: spread.loc,
336
- fragment: spread.name,
337
- module: moduleName
338
- });
339
- var normalizationName = getNormalizationOperationName(spread.name) + '.graphql';
340
- var componentKey = getModuleComponentKey(moduleKey);
341
- var componentField = {
342
- alias: componentKey,
343
- args: [{
344
- kind: 'Argument',
345
- name: JS_FIELD_MODULE_ARG,
346
- type: jsFieldModuleArg.type,
347
- value: {
348
- kind: 'Literal',
349
- loc: (_moduleDirective$args2 = (_moduleDirective$args3 = moduleDirective.args[0]) === null || _moduleDirective$args3 === void 0 ? void 0 : _moduleDirective$args3.loc) !== null && _moduleDirective$args2 !== void 0 ? _moduleDirective$args2 : moduleDirective.loc,
350
- value: moduleName
351
- },
352
- loc: moduleDirective.loc
353
- }, jsFieldIdArg != null ? {
354
- kind: 'Argument',
355
- name: JS_FIELD_ID_ARG,
356
- type: jsFieldIdArg.type,
357
- value: {
358
- kind: 'Literal',
359
- loc: (_moduleDirective$args4 = (_moduleDirective$args5 = moduleDirective.args[0]) === null || _moduleDirective$args5 === void 0 ? void 0 : _moduleDirective$args5.loc) !== null && _moduleDirective$args4 !== void 0 ? _moduleDirective$args4 : moduleDirective.loc,
360
- value: moduleId
361
- },
362
- loc: moduleDirective.loc
363
- } : null].filter(Boolean),
364
- directives: [],
365
- handles: null,
366
- kind: 'ScalarField',
367
- loc: moduleDirective.loc,
368
- metadata: {
369
- skipNormalizationNode: true
370
- },
371
- name: JS_FIELD_NAME,
372
- type: jsModuleType
373
- };
374
- var operationKey = getModuleOperationKey(moduleKey);
375
- var operationField = {
376
- alias: operationKey,
377
- args: [{
378
- kind: 'Argument',
379
- name: JS_FIELD_MODULE_ARG,
380
- type: jsFieldModuleArg.type,
381
- value: {
382
- kind: 'Literal',
383
- loc: moduleDirective.loc,
384
- value: normalizationName
385
- },
386
- loc: moduleDirective.loc
387
- }, jsFieldIdArg != null ? {
388
- kind: 'Argument',
389
- name: JS_FIELD_ID_ARG,
390
- type: jsFieldIdArg.type,
391
- value: {
392
- kind: 'Literal',
393
- loc: (_moduleDirective$args6 = (_moduleDirective$args7 = moduleDirective.args[0]) === null || _moduleDirective$args7 === void 0 ? void 0 : _moduleDirective$args7.loc) !== null && _moduleDirective$args6 !== void 0 ? _moduleDirective$args6 : moduleDirective.loc,
394
- value: moduleId
395
- },
396
- loc: moduleDirective.loc
397
- } : null].filter(Boolean),
398
- directives: [],
399
- handles: null,
400
- kind: 'ScalarField',
401
- loc: moduleDirective.loc,
402
- metadata: {
403
- skipNormalizationNode: true
404
- },
405
- name: JS_FIELD_NAME,
406
- type: jsModuleType
407
- };
408
- return {
409
- kind: 'InlineFragment',
410
- directives: [],
411
- loc: moduleDirective.loc,
412
- metadata: null,
413
- selections: [{
414
- kind: 'ModuleImport',
415
- loc: moduleDirective.loc,
416
- key: moduleKey,
417
- id: moduleId,
418
- module: moduleName,
419
- sourceDocument: documentName,
420
- name: spread.name,
421
- selections: [(0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, spread), {}, {
422
- directives: spread.directives.filter(function (directive) {
423
- return directive !== moduleDirective;
424
- })
425
- }), operationField, componentField]
426
- }],
427
- typeCondition: fragment.type
428
- };
429
- }
430
-
431
- module.exports = {
432
- SCHEMA_EXTENSION: SCHEMA_EXTENSION,
433
- transform: matchTransform
434
- };
@@ -1,158 +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
- * @emails oncall+relay
10
- */
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 IRTransformer = require('../core/IRTransformer');
18
-
19
- var _require = require('../core/CompilerError'),
20
- createUserError = _require.createUserError,
21
- createCompilerError = _require.createCompilerError;
22
-
23
- var _require2 = require('relay-runtime'),
24
- RelayFeatureFlags = _require2.RelayFeatureFlags;
25
-
26
- var FLIGHT_FIELD_COMPONENT_ARGUMENT_TYPE = 'String';
27
- var FLIGHT_FIELD_COMPONENT_ARGUMENT_NAME = 'component';
28
- var FLIGHT_FIELD_PROPS_ARGUMENT_NAME = 'props';
29
- var FLIGHT_FIELD_PROPS_TYPE = 'ReactFlightProps';
30
- var FLIGHT_FIELD_RETURN_TYPE = 'ReactFlightComponent';
31
-
32
- /**
33
- * Experimental transform for React Flight.
34
- */
35
- function reactFlightComponentTransform(context) {
36
- var schema = context.getSchema();
37
- var propsType = schema.getTypeFromString(FLIGHT_FIELD_PROPS_TYPE);
38
- propsType = propsType ? schema.asInputType(propsType) : null;
39
- var componentType = schema.getTypeFromString(FLIGHT_FIELD_RETURN_TYPE);
40
- componentType = componentType ? schema.asScalarFieldType(componentType) : null;
41
-
42
- if (!RelayFeatureFlags.ENABLE_REACT_FLIGHT_COMPONENT_FIELD || propsType == null || componentType == null) {
43
- return context;
44
- }
45
-
46
- var types = {
47
- propsType: propsType,
48
- componentType: componentType
49
- };
50
- return IRTransformer.transform(context, {
51
- ScalarField: visitScalarField,
52
- LinkedField: visitLinkedField,
53
- InlineFragment: visitInlineFragment
54
- }, function (node) {
55
- return {
56
- parentType: node.type,
57
- types: types
58
- };
59
- });
60
- }
61
-
62
- function visitInlineFragment(fragment, state) {
63
- var _fragment$typeConditi;
64
-
65
- return this.traverse(fragment, {
66
- parentType: (_fragment$typeConditi = fragment.typeCondition) !== null && _fragment$typeConditi !== void 0 ? _fragment$typeConditi : state.parentType,
67
- types: state.types
68
- });
69
- }
70
-
71
- function visitLinkedField(field, state) {
72
- return this.traverse(field, {
73
- parentType: field.type,
74
- types: state.types
75
- });
76
- }
77
-
78
- function visitScalarField(field, state) {
79
- // use the return type to quickly determine if this is a flight field
80
- var schema = this.getContext().getSchema();
81
-
82
- if (schema.getRawType(field.type) !== state.types.componentType) {
83
- return field;
84
- } // get the name of the component that provides this field
85
-
86
-
87
- var clientField = schema.getFieldByName(state.parentType, field.name);
88
-
89
- if (clientField == null) {
90
- throw createCompilerError("Definition not found for field '".concat(schema.getTypeString(state.parentType), ".").concat(field.name, "'"), [field.loc]);
91
- }
92
-
93
- var componentDirective = clientField.directives.find(function (directive) {
94
- return directive.name === 'react_flight_component';
95
- });
96
- var componentNameArg = componentDirective === null || componentDirective === void 0 ? void 0 : componentDirective.args.find(function (arg) {
97
- return arg.name === 'name';
98
- });
99
-
100
- if (componentNameArg == null || componentNameArg.value.kind !== 'StringValue' || typeof componentNameArg.value.value !== 'string') {
101
- throw createUserError('Invalid Flight field, expected the schema extension to specify ' + "the component's module name with the '@react_flight_component' directive", [field.loc]);
102
- }
103
-
104
- var componentName = componentNameArg.value.value; // validate that the parent type has a `flight(component, props)` field
105
-
106
- var flightField = schema.getFieldByName(state.parentType, 'flight');
107
-
108
- if (flightField == null) {
109
- throw createUserError("Invalid Flight field, expected the parent type '".concat(schema.getTypeString(state.parentType), "' ") + "to define a 'flight(component: String, props: ReactFlightProps): ReactFlightComponent' field", [field.loc]);
110
- }
111
-
112
- var componentArg = flightField.args.get(FLIGHT_FIELD_COMPONENT_ARGUMENT_NAME);
113
- var propsArg = flightField.args.get(FLIGHT_FIELD_PROPS_ARGUMENT_NAME);
114
-
115
- if (componentArg == null || propsArg == null || schema.getRawType(componentArg.type) !== schema.getTypeFromString(FLIGHT_FIELD_COMPONENT_ARGUMENT_TYPE) || schema.getRawType(propsArg.type) !== state.types.propsType || schema.getRawType(flightField.type) !== state.types.componentType) {
116
- throw createUserError("Invalid Flight field, expected the parent type '".concat(schema.getTypeString(state.parentType), "' ") + "to define a 'flight(component: String, props: ReactFlightProps): ReactFlightComponent' field", [field.loc]);
117
- }
118
-
119
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, field), {}, {
120
- name: 'flight',
121
- args: [{
122
- kind: 'Argument',
123
- loc: field.loc,
124
- name: FLIGHT_FIELD_COMPONENT_ARGUMENT_NAME,
125
- type: schema.getTypeFromString(FLIGHT_FIELD_COMPONENT_ARGUMENT_TYPE),
126
- value: {
127
- kind: 'Literal',
128
- value: componentName,
129
- loc: field.loc
130
- }
131
- }, {
132
- kind: 'Argument',
133
- loc: field.loc,
134
- name: FLIGHT_FIELD_PROPS_ARGUMENT_NAME,
135
- type: state.types.propsType,
136
- value: {
137
- kind: 'ObjectValue',
138
- fields: field.args.map(function (arg) {
139
- return {
140
- kind: 'ObjectFieldValue',
141
- loc: arg.loc,
142
- name: arg.name,
143
- value: arg.value
144
- };
145
- }),
146
- loc: field.loc
147
- }
148
- }],
149
- metadata: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, field.metadata || {}), {}, {
150
- flight: true
151
- }),
152
- type: state.types.componentType
153
- });
154
- }
155
-
156
- module.exports = {
157
- transform: reactFlightComponentTransform
158
- };