relay-compiler 12.0.0 → 13.0.0-rc.0

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