relay-compiler 12.0.0 → 13.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (262) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +108 -0
  3. package/cli.js +23 -0
  4. package/index.js +22 -4
  5. package/linux-x64/relay +0 -0
  6. package/macos-arm64/relay +0 -0
  7. package/macos-x64/relay +0 -0
  8. package/package.json +2 -26
  9. package/win-x64/relay.exe +0 -0
  10. package/bin/RelayCompilerBin.js.flow +0 -169
  11. package/bin/RelayCompilerMain.js.flow +0 -515
  12. package/bin/__fixtures__/plugin-module.js.flow +0 -17
  13. package/bin/relay-compiler +0 -19066
  14. package/codegen/CodegenDirectory.js.flow +0 -375
  15. package/codegen/CodegenRunner.js.flow +0 -432
  16. package/codegen/CodegenTypes.js.flow +0 -28
  17. package/codegen/CodegenWatcher.js.flow +0 -254
  18. package/codegen/NormalizationCodeGenerator.js.flow +0 -566
  19. package/codegen/ReaderCodeGenerator.js.flow +0 -512
  20. package/codegen/RelayCodeGenerator.js.flow +0 -85
  21. package/codegen/RelayFileWriter.js.flow +0 -367
  22. package/codegen/SourceControl.js.flow +0 -58
  23. package/codegen/compileRelayArtifacts.js.flow +0 -182
  24. package/codegen/createPrintRequireModuleDependency.js.flow +0 -19
  25. package/codegen/sortObjectByKey.js.flow +0 -25
  26. package/codegen/writeRelayGeneratedFile.js.flow +0 -239
  27. package/core/ASTCache.js.flow +0 -74
  28. package/core/ASTConvert.js.flow +0 -233
  29. package/core/CompilerContext.js.flow +0 -191
  30. package/core/CompilerError.js.flow +0 -255
  31. package/core/DotGraphQLParser.js.flow +0 -39
  32. package/core/GraphQLCompilerProfiler.js.flow +0 -341
  33. package/core/GraphQLDerivedFromMetadata.js.flow +0 -36
  34. package/core/GraphQLWatchmanClient.js.flow +0 -111
  35. package/core/IR.js.flow +0 -326
  36. package/core/IRPrinter.js.flow +0 -478
  37. package/core/IRTransformer.js.flow +0 -377
  38. package/core/IRValidator.js.flow +0 -260
  39. package/core/IRVisitor.js.flow +0 -150
  40. package/core/JSModuleParser.js.flow +0 -24
  41. package/core/RelayCompilerScope.js.flow +0 -199
  42. package/core/RelayFindGraphQLTags.js.flow +0 -119
  43. package/core/RelayGraphQLEnumsGenerator.js.flow +0 -55
  44. package/core/RelayIRTransforms.js.flow +0 -138
  45. package/core/RelayParser.js.flow +0 -1734
  46. package/core/RelaySourceModuleParser.js.flow +0 -135
  47. package/core/Schema.js.flow +0 -2037
  48. package/core/SchemaUtils.js.flow +0 -120
  49. package/core/filterContextForNode.js.flow +0 -50
  50. package/core/getFieldDefinition.js.flow +0 -156
  51. package/core/getIdentifierForArgumentValue.js.flow +0 -49
  52. package/core/getIdentifierForSelection.js.flow +0 -69
  53. package/core/getLiteralArgumentValues.js.flow +0 -32
  54. package/core/getNormalizationOperationName.js.flow +0 -19
  55. package/core/inferRootArgumentDefinitions.js.flow +0 -323
  56. package/index.js.flow +0 -200
  57. package/language/RelayLanguagePluginInterface.js.flow +0 -283
  58. package/language/javascript/FindGraphQLTags.js.flow +0 -137
  59. package/language/javascript/RelayFlowBabelFactories.js.flow +0 -176
  60. package/language/javascript/RelayFlowGenerator.js.flow +0 -1100
  61. package/language/javascript/RelayFlowTypeTransformers.js.flow +0 -184
  62. package/language/javascript/RelayLanguagePluginJavaScript.js.flow +0 -34
  63. package/language/javascript/formatGeneratedModule.js.flow +0 -65
  64. package/lib/bin/RelayCompilerBin.js +0 -143
  65. package/lib/bin/RelayCompilerMain.js +0 -486
  66. package/lib/bin/__fixtures__/plugin-module.js +0 -16
  67. package/lib/codegen/CodegenDirectory.js +0 -336
  68. package/lib/codegen/CodegenRunner.js +0 -433
  69. package/lib/codegen/CodegenTypes.js +0 -11
  70. package/lib/codegen/CodegenWatcher.js +0 -271
  71. package/lib/codegen/NormalizationCodeGenerator.js +0 -480
  72. package/lib/codegen/ReaderCodeGenerator.js +0 -472
  73. package/lib/codegen/RelayCodeGenerator.js +0 -68
  74. package/lib/codegen/RelayFileWriter.js +0 -270
  75. package/lib/codegen/SourceControl.js +0 -60
  76. package/lib/codegen/compileRelayArtifacts.js +0 -157
  77. package/lib/codegen/createPrintRequireModuleDependency.js +0 -19
  78. package/lib/codegen/sortObjectByKey.js +0 -41
  79. package/lib/codegen/writeRelayGeneratedFile.js +0 -208
  80. package/lib/core/ASTCache.js +0 -70
  81. package/lib/core/ASTConvert.js +0 -198
  82. package/lib/core/CompilerContext.js +0 -165
  83. package/lib/core/CompilerError.js +0 -251
  84. package/lib/core/DotGraphQLParser.js +0 -40
  85. package/lib/core/GraphQLCompilerProfiler.js +0 -299
  86. package/lib/core/GraphQLDerivedFromMetadata.js +0 -31
  87. package/lib/core/GraphQLWatchmanClient.js +0 -150
  88. package/lib/core/IR.js +0 -11
  89. package/lib/core/IRPrinter.js +0 -389
  90. package/lib/core/IRTransformer.js +0 -345
  91. package/lib/core/IRValidator.js +0 -226
  92. package/lib/core/IRVisitor.js +0 -45
  93. package/lib/core/JSModuleParser.js +0 -18
  94. package/lib/core/RelayCompilerScope.js +0 -149
  95. package/lib/core/RelayFindGraphQLTags.js +0 -79
  96. package/lib/core/RelayGraphQLEnumsGenerator.js +0 -50
  97. package/lib/core/RelayIRTransforms.js +0 -109
  98. package/lib/core/RelayParser.js +0 -1382
  99. package/lib/core/RelaySourceModuleParser.js +0 -104
  100. package/lib/core/Schema.js +0 -1877
  101. package/lib/core/SchemaUtils.js +0 -98
  102. package/lib/core/filterContextForNode.js +0 -49
  103. package/lib/core/getFieldDefinition.js +0 -145
  104. package/lib/core/getIdentifierForArgumentValue.js +0 -53
  105. package/lib/core/getIdentifierForSelection.js +0 -48
  106. package/lib/core/getLiteralArgumentValues.js +0 -26
  107. package/lib/core/getNormalizationOperationName.js +0 -17
  108. package/lib/core/inferRootArgumentDefinitions.js +0 -351
  109. package/lib/index.js +0 -178
  110. package/lib/language/RelayLanguagePluginInterface.js +0 -14
  111. package/lib/language/javascript/FindGraphQLTags.js +0 -126
  112. package/lib/language/javascript/RelayFlowBabelFactories.js +0 -160
  113. package/lib/language/javascript/RelayFlowGenerator.js +0 -857
  114. package/lib/language/javascript/RelayFlowTypeTransformers.js +0 -119
  115. package/lib/language/javascript/RelayLanguagePluginJavaScript.js +0 -30
  116. package/lib/language/javascript/formatGeneratedModule.js +0 -36
  117. package/lib/reporters/ConsoleReporter.js +0 -61
  118. package/lib/reporters/MultiReporter.js +0 -45
  119. package/lib/reporters/Reporter.js +0 -11
  120. package/lib/runner/Artifacts.js +0 -323
  121. package/lib/runner/BufferedFilesystem.js +0 -261
  122. package/lib/runner/GraphQLASTNodeGroup.js +0 -256
  123. package/lib/runner/GraphQLASTUtils.js +0 -23
  124. package/lib/runner/GraphQLNodeMap.js +0 -81
  125. package/lib/runner/Sources.js +0 -271
  126. package/lib/runner/StrictMap.js +0 -134
  127. package/lib/runner/compileArtifacts.js +0 -39
  128. package/lib/runner/extractAST.js +0 -77
  129. package/lib/runner/getChangedNodeNames.js +0 -82
  130. package/lib/runner/getSchemaInstance.js +0 -30
  131. package/lib/runner/types.js +0 -12
  132. package/lib/transforms/ApplyFragmentArgumentTransform.js +0 -393
  133. package/lib/transforms/ClientExtensionsTransform.js +0 -222
  134. package/lib/transforms/ConnectionTransform.js +0 -643
  135. package/lib/transforms/DeclarativeConnectionMutationTransform.js +0 -221
  136. package/lib/transforms/DeferStreamTransform.js +0 -247
  137. package/lib/transforms/DisallowIdAsAlias.js +0 -41
  138. package/lib/transforms/DisallowTypenameOnRoot.js +0 -53
  139. package/lib/transforms/FieldHandleTransform.js +0 -81
  140. package/lib/transforms/FilterCompilerDirectivesTransform.js +0 -29
  141. package/lib/transforms/FilterDirectivesTransform.js +0 -41
  142. package/lib/transforms/FlattenTransform.js +0 -308
  143. package/lib/transforms/GenerateIDFieldTransform.js +0 -137
  144. package/lib/transforms/GenerateTypeNameTransform.js +0 -155
  145. package/lib/transforms/InlineDataFragmentTransform.js +0 -104
  146. package/lib/transforms/InlineFragmentsTransform.js +0 -63
  147. package/lib/transforms/MaskTransform.js +0 -121
  148. package/lib/transforms/MatchTransform.js +0 -438
  149. package/lib/transforms/ReactFlightComponentTransform.js +0 -161
  150. package/lib/transforms/RefetchableFragmentTransform.js +0 -249
  151. package/lib/transforms/RelayDirectiveTransform.js +0 -85
  152. package/lib/transforms/RequiredFieldTransform.js +0 -373
  153. package/lib/transforms/SkipClientExtensionsTransform.js +0 -49
  154. package/lib/transforms/SkipHandleFieldTransform.js +0 -45
  155. package/lib/transforms/SkipRedundantNodesTransform.js +0 -255
  156. package/lib/transforms/SkipSplitOperationTransform.js +0 -32
  157. package/lib/transforms/SkipUnreachableNodeTransform.js +0 -158
  158. package/lib/transforms/SkipUnusedVariablesTransform.js +0 -74
  159. package/lib/transforms/SplitModuleImportTransform.js +0 -85
  160. package/lib/transforms/TestOperationTransform.js +0 -145
  161. package/lib/transforms/TransformUtils.js +0 -21
  162. package/lib/transforms/ValidateGlobalVariablesTransform.js +0 -91
  163. package/lib/transforms/ValidateRequiredArgumentsTransform.js +0 -118
  164. package/lib/transforms/ValidateServerOnlyDirectivesTransform.js +0 -111
  165. package/lib/transforms/ValidateUnusedVariablesTransform.js +0 -96
  166. package/lib/transforms/query-generators/FetchableQueryGenerator.js +0 -157
  167. package/lib/transforms/query-generators/NodeQueryGenerator.js +0 -166
  168. package/lib/transforms/query-generators/QueryQueryGenerator.js +0 -48
  169. package/lib/transforms/query-generators/ViewerQueryGenerator.js +0 -77
  170. package/lib/transforms/query-generators/index.js +0 -60
  171. package/lib/transforms/query-generators/utils.js +0 -92
  172. package/lib/util/CodeMarker.js +0 -80
  173. package/lib/util/DefaultHandleKey.js +0 -15
  174. package/lib/util/RelayCompilerCache.js +0 -98
  175. package/lib/util/Rollout.js +0 -40
  176. package/lib/util/TimeReporter.js +0 -83
  177. package/lib/util/areEqualArgValues.js +0 -135
  178. package/lib/util/argumentContainsVariables.js +0 -37
  179. package/lib/util/dedupeJSONStringify.js +0 -160
  180. package/lib/util/generateAbstractTypeRefinementKey.js +0 -24
  181. package/lib/util/getDefinitionNodeHash.js +0 -22
  182. package/lib/util/getModuleName.js +0 -32
  183. package/lib/util/joinArgumentDefinitions.js +0 -66
  184. package/lib/util/md5.js +0 -17
  185. package/lib/util/murmurHash.js +0 -86
  186. package/lib/util/nullthrowsOSS.js +0 -23
  187. package/lib/util/orList.js +0 -36
  188. package/lib/util/partitionArray.js +0 -35
  189. package/relay-compiler.js +0 -17
  190. package/relay-compiler.min.js +0 -22
  191. package/reporters/ConsoleReporter.js.flow +0 -81
  192. package/reporters/MultiReporter.js.flow +0 -43
  193. package/reporters/Reporter.js.flow +0 -19
  194. package/runner/Artifacts.js.flow +0 -219
  195. package/runner/BufferedFilesystem.js.flow +0 -194
  196. package/runner/GraphQLASTNodeGroup.js.flow +0 -176
  197. package/runner/GraphQLASTUtils.js.flow +0 -26
  198. package/runner/GraphQLNodeMap.js.flow +0 -55
  199. package/runner/Sources.js.flow +0 -228
  200. package/runner/StrictMap.js.flow +0 -96
  201. package/runner/compileArtifacts.js.flow +0 -76
  202. package/runner/extractAST.js.flow +0 -100
  203. package/runner/getChangedNodeNames.js.flow +0 -48
  204. package/runner/getSchemaInstance.js.flow +0 -36
  205. package/runner/types.js.flow +0 -37
  206. package/transforms/ApplyFragmentArgumentTransform.js.flow +0 -526
  207. package/transforms/ClientExtensionsTransform.js.flow +0 -226
  208. package/transforms/ConnectionTransform.js.flow +0 -859
  209. package/transforms/DeclarativeConnectionMutationTransform.js.flow +0 -250
  210. package/transforms/DeferStreamTransform.js.flow +0 -266
  211. package/transforms/DisallowIdAsAlias.js.flow +0 -48
  212. package/transforms/DisallowTypenameOnRoot.js.flow +0 -45
  213. package/transforms/FieldHandleTransform.js.flow +0 -81
  214. package/transforms/FilterCompilerDirectivesTransform.js.flow +0 -33
  215. package/transforms/FilterDirectivesTransform.js.flow +0 -45
  216. package/transforms/FlattenTransform.js.flow +0 -462
  217. package/transforms/GenerateIDFieldTransform.js.flow +0 -154
  218. package/transforms/GenerateTypeNameTransform.js.flow +0 -167
  219. package/transforms/InlineDataFragmentTransform.js.flow +0 -129
  220. package/transforms/InlineFragmentsTransform.js.flow +0 -73
  221. package/transforms/MaskTransform.js.flow +0 -130
  222. package/transforms/MatchTransform.js.flow +0 -593
  223. package/transforms/ReactFlightComponentTransform.js.flow +0 -198
  224. package/transforms/RefetchableFragmentTransform.js.flow +0 -272
  225. package/transforms/RelayDirectiveTransform.js.flow +0 -99
  226. package/transforms/RequiredFieldTransform.js.flow +0 -419
  227. package/transforms/SkipClientExtensionsTransform.js.flow +0 -57
  228. package/transforms/SkipHandleFieldTransform.js.flow +0 -45
  229. package/transforms/SkipRedundantNodesTransform.js.flow +0 -259
  230. package/transforms/SkipSplitOperationTransform.js.flow +0 -37
  231. package/transforms/SkipUnreachableNodeTransform.js.flow +0 -149
  232. package/transforms/SkipUnusedVariablesTransform.js.flow +0 -59
  233. package/transforms/SplitModuleImportTransform.js.flow +0 -101
  234. package/transforms/TestOperationTransform.js.flow +0 -143
  235. package/transforms/TransformUtils.js.flow +0 -26
  236. package/transforms/ValidateGlobalVariablesTransform.js.flow +0 -81
  237. package/transforms/ValidateRequiredArgumentsTransform.js.flow +0 -131
  238. package/transforms/ValidateServerOnlyDirectivesTransform.js.flow +0 -115
  239. package/transforms/ValidateUnusedVariablesTransform.js.flow +0 -89
  240. package/transforms/query-generators/FetchableQueryGenerator.js.flow +0 -189
  241. package/transforms/query-generators/NodeQueryGenerator.js.flow +0 -219
  242. package/transforms/query-generators/QueryQueryGenerator.js.flow +0 -57
  243. package/transforms/query-generators/ViewerQueryGenerator.js.flow +0 -97
  244. package/transforms/query-generators/index.js.flow +0 -90
  245. package/transforms/query-generators/utils.js.flow +0 -76
  246. package/util/CodeMarker.js.flow +0 -79
  247. package/util/DefaultHandleKey.js.flow +0 -17
  248. package/util/RelayCompilerCache.js.flow +0 -88
  249. package/util/Rollout.js.flow +0 -39
  250. package/util/TimeReporter.js.flow +0 -79
  251. package/util/areEqualArgValues.js.flow +0 -126
  252. package/util/argumentContainsVariables.js.flow +0 -38
  253. package/util/dedupeJSONStringify.js.flow +0 -152
  254. package/util/generateAbstractTypeRefinementKey.js.flow +0 -29
  255. package/util/getDefinitionNodeHash.js.flow +0 -25
  256. package/util/getModuleName.js.flow +0 -39
  257. package/util/joinArgumentDefinitions.js.flow +0 -105
  258. package/util/md5.js.flow +0 -22
  259. package/util/murmurHash.js.flow +0 -94
  260. package/util/nullthrowsOSS.js.flow +0 -25
  261. package/util/orList.js.flow +0 -37
  262. package/util/partitionArray.js.flow +0 -37
@@ -1,643 +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 RelayParser = require('../core/RelayParser');
22
-
23
- var SchemaUtils = require('../core/SchemaUtils');
24
-
25
- var getLiteralArgumentValues = require('../core/getLiteralArgumentValues');
26
-
27
- var _require = require('../core/CompilerError'),
28
- createCompilerError = _require.createCompilerError,
29
- createUserError = _require.createUserError;
30
-
31
- var _require2 = require('graphql'),
32
- parse = _require2.parse;
33
-
34
- var _require3 = require('relay-runtime'),
35
- ConnectionInterface = _require3.ConnectionInterface,
36
- RelayFeatureFlags = _require3.RelayFeatureFlags;
37
-
38
- var AFTER = 'after';
39
- var BEFORE = 'before';
40
- var FIRST = 'first';
41
- var KEY = 'key';
42
- var LAST = 'last';
43
- var CONNECTION = 'connection';
44
- var STREAM_CONNECTION = 'stream_connection';
45
- var HANDLER = 'handler';
46
- /**
47
- * @public
48
- *
49
- * Transforms fields with the `@connection` directive:
50
- * - Verifies that the field type is connection-like.
51
- * - Adds a `handle` property to the field, either the user-provided `handle`
52
- * argument or the default value "connection".
53
- * - Inserts a sub-fragment on the field to ensure that standard connection
54
- * fields are fetched (e.g. cursors, node ids, page info).
55
- */
56
-
57
- function connectionTransform(context) {
58
- return IRTransformer.transform(context, {
59
- Fragment: visitFragmentOrRoot,
60
- LinkedField: visitLinkedField,
61
- Root: visitFragmentOrRoot
62
- }, function (node) {
63
- return {
64
- documentName: node.name,
65
- path: [],
66
- connectionMetadata: []
67
- };
68
- });
69
- }
70
-
71
- var SCHEMA_EXTENSION = "\n directive @connection(\n key: String!\n filters: [String]\n handler: String\n dynamicKey_UNSTABLE: String\n ) on FIELD\n\n directive @stream_connection(\n key: String!\n filters: [String]\n handler: String\n initial_count: Int!\n if: Boolean = true\n use_customized_batch: Boolean = false\n dynamicKey_UNSTABLE: String\n ) on FIELD\n";
72
- /**
73
- * @internal
74
- */
75
-
76
- function visitFragmentOrRoot(node, options) {
77
- // $FlowFixMe[incompatible-use]
78
- var transformedNode = this.traverse(node, options);
79
- var connectionMetadata = options.connectionMetadata;
80
-
81
- if (connectionMetadata.length) {
82
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, transformedNode), {}, {
83
- metadata: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, transformedNode.metadata), {}, {
84
- connection: connectionMetadata
85
- })
86
- });
87
- }
88
-
89
- return transformedNode;
90
- }
91
- /**
92
- * @internal
93
- */
94
-
95
-
96
- function visitLinkedField(field, options) {
97
- var _connectionArguments$;
98
-
99
- // $FlowFixMe[incompatible-use]
100
- var context = this.getContext();
101
- var schema = context.getSchema();
102
- var nullableType = schema.getNullableType(field.type);
103
- var isPlural = schema.isList(nullableType);
104
- var path = options.path.concat(isPlural ? null : field.alias || field.name); // $FlowFixMe[incompatible-use]
105
-
106
- var transformedField = this.traverse(field, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, options), {}, {
107
- path: path
108
- }));
109
- var connectionDirective = field.directives.find(function (directive) {
110
- return directive.name === CONNECTION || directive.name === STREAM_CONNECTION;
111
- });
112
-
113
- if (!connectionDirective) {
114
- return transformedField;
115
- }
116
-
117
- if (!schema.isObject(nullableType) && !schema.isInterface(nullableType)) {
118
- throw new createUserError("@".concat(connectionDirective.name, " used on invalid field '").concat(field.name, "'. ") + 'Expected the return type to be a non-plural interface or object, ' + "got '".concat(schema.getTypeString(field.type), "'."), [transformedField.loc]);
119
- }
120
-
121
- validateConnectionSelection(transformedField);
122
- validateConnectionType(schema, transformedField, schema.assertCompositeType(nullableType), connectionDirective);
123
- var connectionArguments = buildConnectionArguments(transformedField, connectionDirective);
124
- var connectionMetadata = buildConnectionMetadata(transformedField, path, connectionArguments.stream != null);
125
- options.connectionMetadata.push(connectionMetadata);
126
- var handle = {
127
- name: (_connectionArguments$ = connectionArguments.handler) !== null && _connectionArguments$ !== void 0 ? _connectionArguments$ : CONNECTION,
128
- key: connectionArguments.key,
129
- dynamicKey: connectionArguments.dynamicKey,
130
- filters: connectionArguments.filters
131
- };
132
- var direction = connectionMetadata.direction;
133
-
134
- if (direction != null) {
135
- var selections = transformConnectionSelections( // $FlowFixMe[incompatible-use]
136
- this.getContext(), transformedField, schema.assertCompositeType(nullableType), direction, connectionArguments, connectionDirective.loc, options.documentName);
137
- transformedField = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, transformedField), {}, {
138
- selections: selections
139
- });
140
- }
141
-
142
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, transformedField), {}, {
143
- directives: transformedField.directives.filter(function (directive) {
144
- return directive !== connectionDirective;
145
- }),
146
- connection: true,
147
- handles: transformedField.handles ? [].concat((0, _toConsumableArray2["default"])(transformedField.handles), [handle]) : [handle]
148
- });
149
- }
150
-
151
- function buildConnectionArguments(field, connectionDirective) {
152
- var _getLiteralArgumentVa = getLiteralArgumentValues(connectionDirective.args),
153
- handler = _getLiteralArgumentVa.handler,
154
- key = _getLiteralArgumentVa.key,
155
- label = _getLiteralArgumentVa.label,
156
- literalFilters = _getLiteralArgumentVa.filters;
157
-
158
- if (handler != null && typeof handler !== 'string') {
159
- var _handleArg$value$loc, _handleArg$value;
160
-
161
- var handleArg = connectionDirective.args.find(function (arg) {
162
- return arg.name === 'handler';
163
- });
164
- throw createUserError("Expected the ".concat(HANDLER, " argument to @").concat(connectionDirective.name, " to ") + "be a string literal for field ".concat(field.name, "."), [(_handleArg$value$loc = handleArg === null || handleArg === void 0 ? void 0 : (_handleArg$value = handleArg.value) === null || _handleArg$value === void 0 ? void 0 : _handleArg$value.loc) !== null && _handleArg$value$loc !== void 0 ? _handleArg$value$loc : connectionDirective.loc]);
165
- }
166
-
167
- if (typeof key !== 'string') {
168
- var _keyArg$value$loc, _keyArg$value;
169
-
170
- var keyArg = connectionDirective.args.find(function (arg) {
171
- return arg.name === 'key';
172
- });
173
- throw createUserError("Expected the ".concat(KEY, " argument to @").concat(connectionDirective.name, " to be a ") + "string literal for field ".concat(field.name, "."), [(_keyArg$value$loc = keyArg === null || keyArg === void 0 ? void 0 : (_keyArg$value = keyArg.value) === null || _keyArg$value === void 0 ? void 0 : _keyArg$value.loc) !== null && _keyArg$value$loc !== void 0 ? _keyArg$value$loc : connectionDirective.loc]);
174
- }
175
-
176
- var postfix = field.alias || field.name;
177
-
178
- if (!key.endsWith('_' + postfix)) {
179
- var _keyArg$value$loc2, _keyArg$value2;
180
-
181
- var _keyArg = connectionDirective.args.find(function (arg) {
182
- return arg.name === 'key';
183
- });
184
-
185
- throw createUserError("Expected the ".concat(KEY, " argument to @").concat(connectionDirective.name, " to be of ") + "form <SomeName>_".concat(postfix, ", got '").concat(key, "'. ") + 'For a detailed explanation, check out ' + 'https://relay.dev/docs/en/pagination-container#connection', [(_keyArg$value$loc2 = _keyArg === null || _keyArg === void 0 ? void 0 : (_keyArg$value2 = _keyArg.value) === null || _keyArg$value2 === void 0 ? void 0 : _keyArg$value2.loc) !== null && _keyArg$value$loc2 !== void 0 ? _keyArg$value$loc2 : connectionDirective.loc]);
186
- }
187
-
188
- if (literalFilters != null && (!Array.isArray(literalFilters) || literalFilters.some(function (filter) {
189
- return typeof filter !== 'string';
190
- }))) {
191
- var _filtersArg$value$loc, _filtersArg$value;
192
-
193
- var filtersArg = connectionDirective.args.find(function (arg) {
194
- return arg.name === 'filters';
195
- });
196
- throw createUserError("Expected the 'filters' argument to @".concat(connectionDirective.name, " to be ") + 'a string literal.', [(_filtersArg$value$loc = filtersArg === null || filtersArg === void 0 ? void 0 : (_filtersArg$value = filtersArg.value) === null || _filtersArg$value === void 0 ? void 0 : _filtersArg$value.loc) !== null && _filtersArg$value$loc !== void 0 ? _filtersArg$value$loc : connectionDirective.loc]);
197
- }
198
-
199
- var filters = literalFilters;
200
-
201
- if (filters == null) {
202
- var generatedFilters = field.args.filter(function (arg) {
203
- return !ConnectionInterface.isConnectionCall({
204
- name: arg.name,
205
- value: null
206
- });
207
- }).map(function (arg) {
208
- return arg.name;
209
- });
210
- filters = generatedFilters.length !== 0 ? generatedFilters : null;
211
- }
212
-
213
- var stream = null;
214
-
215
- if (connectionDirective.name === STREAM_CONNECTION) {
216
- var initialCountArg = connectionDirective.args.find(function (arg) {
217
- return arg.name === 'initial_count';
218
- });
219
- var useCustomizedBatchArg = connectionDirective.args.find(function (arg) {
220
- return arg.name === 'use_customized_batch';
221
- });
222
- var ifArg = connectionDirective.args.find(function (arg) {
223
- return arg.name === 'if';
224
- });
225
- stream = {
226
- "if": ifArg,
227
- initialCount: initialCountArg,
228
- useCustomizedBatch: useCustomizedBatchArg,
229
- label: key
230
- };
231
- }
232
-
233
- var dynamicKeyArg = connectionDirective.args.find(function (arg) {
234
- return arg.name === 'dynamicKey_UNSTABLE';
235
- });
236
- var dynamicKey = null;
237
-
238
- if (dynamicKeyArg != null) {
239
- if (RelayFeatureFlags.ENABLE_VARIABLE_CONNECTION_KEY && dynamicKeyArg.value.kind === 'Variable') {
240
- dynamicKey = dynamicKeyArg.value;
241
- } else {
242
- throw createUserError("Unsupported 'dynamicKey_UNSTABLE' argument to @".concat(connectionDirective.name, ". This argument is only valid when the feature flag is enabled and ") + 'the variable must be a variable', [connectionDirective.loc]);
243
- }
244
- }
245
-
246
- return {
247
- handler: handler,
248
- key: key,
249
- dynamicKey: dynamicKey,
250
- filters: filters,
251
- stream: stream
252
- };
253
- }
254
-
255
- function buildConnectionMetadata(field, path, stream) {
256
- var pathHasPlural = path.includes(null);
257
- var firstArg = findArg(field, FIRST);
258
- var lastArg = findArg(field, LAST);
259
- var direction = null;
260
- var countArg = null;
261
- var cursorArg = null;
262
-
263
- if (firstArg && !lastArg) {
264
- direction = 'forward';
265
- countArg = firstArg;
266
- cursorArg = findArg(field, AFTER);
267
- } else if (lastArg && !firstArg) {
268
- direction = 'backward';
269
- countArg = lastArg;
270
- cursorArg = findArg(field, BEFORE);
271
- } else if (lastArg && firstArg) {
272
- direction = 'bidirectional'; // TODO(T26511885) Maybe add connection metadata to this case
273
- }
274
-
275
- var countVariable = countArg && countArg.value.kind === 'Variable' ? countArg.value.variableName : null;
276
- var cursorVariable = cursorArg && cursorArg.value.kind === 'Variable' ? cursorArg.value.variableName : null;
277
-
278
- if (stream) {
279
- return {
280
- count: countVariable,
281
- cursor: cursorVariable,
282
- direction: direction,
283
- path: pathHasPlural ? null : path,
284
- stream: true
285
- };
286
- }
287
-
288
- return {
289
- count: countVariable,
290
- cursor: cursorVariable,
291
- direction: direction,
292
- path: pathHasPlural ? null : path
293
- };
294
- }
295
- /**
296
- * @internal
297
- *
298
- * Transforms the selections on a connection field, generating fields necessary
299
- * for pagination (edges.cursor, pageInfo, etc) and adding/merging them with
300
- * existing selections.
301
- */
302
-
303
-
304
- function transformConnectionSelections(context, field, nullableType, direction, connectionArguments, directiveLocation, documentName) {
305
- var schema = context.getSchema();
306
- var derivedFieldLocation = {
307
- kind: 'Derived',
308
- source: field.loc
309
- };
310
- var derivedDirectiveLocation = {
311
- kind: 'Derived',
312
- source: directiveLocation
313
- };
314
-
315
- var _ConnectionInterface$ = ConnectionInterface.get(),
316
- CURSOR = _ConnectionInterface$.CURSOR,
317
- EDGES = _ConnectionInterface$.EDGES,
318
- END_CURSOR = _ConnectionInterface$.END_CURSOR,
319
- HAS_NEXT_PAGE = _ConnectionInterface$.HAS_NEXT_PAGE,
320
- HAS_PREV_PAGE = _ConnectionInterface$.HAS_PREV_PAGE,
321
- NODE = _ConnectionInterface$.NODE,
322
- PAGE_INFO = _ConnectionInterface$.PAGE_INFO,
323
- START_CURSOR = _ConnectionInterface$.START_CURSOR; // Find existing edges/pageInfo selections
324
-
325
-
326
- var edgesSelection;
327
- var pageInfoSelection;
328
- field.selections.forEach(function (selection) {
329
- if (selection.kind === 'LinkedField') {
330
- if (selection.name === EDGES) {
331
- if (edgesSelection != null) {
332
- throw createCompilerError("ConnectionTransform: Unexpected duplicate field '".concat(EDGES, "'."), [edgesSelection.loc, selection.loc]);
333
- }
334
-
335
- edgesSelection = selection;
336
- return;
337
- } else if (selection.name === PAGE_INFO) {
338
- if (pageInfoSelection != null) {
339
- throw createCompilerError("ConnectionTransform: Unexpected duplicate field '".concat(PAGE_INFO, "'."), [pageInfoSelection.loc, selection.loc]);
340
- }
341
-
342
- pageInfoSelection = selection;
343
- return;
344
- }
345
- }
346
- }); // If streaming is enabled, construct directives to apply to the edges/
347
- // pageInfo fields
348
-
349
- var streamDirective;
350
- var stream = connectionArguments.stream;
351
-
352
- if (stream != null) {
353
- streamDirective = {
354
- args: [stream["if"], stream.initialCount, stream.useCustomizedBatch, {
355
- kind: 'Argument',
356
- loc: derivedDirectiveLocation,
357
- name: 'label',
358
- type: SchemaUtils.getNullableStringInput(schema),
359
- value: {
360
- kind: 'Literal',
361
- loc: derivedDirectiveLocation,
362
- value: stream.label
363
- }
364
- }].filter(Boolean),
365
- kind: 'Directive',
366
- loc: derivedDirectiveLocation,
367
- name: 'stream'
368
- };
369
- } // For backwards compatibility with earlier versions of this transform,
370
- // edges/pageInfo have to be generated as non-aliased fields (since product
371
- // code may be accessing the non-aliased response keys). But for streaming
372
- // mode we need to generate @stream/@defer directives on these fields *and*
373
- // we prefer to avoid generating extra selections (we want one payload per
374
- // item, not two as could happen with separate @stream directives on the
375
- // aliased and non-aliased edges fields). So we keep things simple by
376
- // disallowing aliases on edges/pageInfo in streaming mode.
377
-
378
-
379
- if (edgesSelection && edgesSelection.alias !== edgesSelection.name) {
380
- if (stream) {
381
- throw createUserError("@stream_connection does not support aliasing the '".concat(EDGES, "' field."), [edgesSelection.loc]);
382
- }
383
-
384
- edgesSelection = null;
385
- }
386
-
387
- if (pageInfoSelection && pageInfoSelection.alias !== pageInfoSelection.name) {
388
- if (stream) {
389
- throw createUserError("@stream_connection does not support aliasing the '".concat(PAGE_INFO, "' field."), [pageInfoSelection.loc]);
390
- }
391
-
392
- pageInfoSelection = null;
393
- } // Separately create transformed versions of edges/pageInfo so that we can
394
- // later replace the originals at the same point within the selection array
395
-
396
-
397
- var transformedEdgesSelection = edgesSelection;
398
- var transformedPageInfoSelection = pageInfoSelection;
399
- var edgesType = schema.getFieldConfig(schema.expectField(nullableType, EDGES)).type;
400
- var pageInfoType = schema.getFieldConfig(schema.expectField(nullableType, PAGE_INFO)).type;
401
-
402
- if (transformedEdgesSelection == null) {
403
- transformedEdgesSelection = {
404
- alias: EDGES,
405
- args: [],
406
- connection: false,
407
- directives: [],
408
- handles: null,
409
- kind: 'LinkedField',
410
- loc: derivedFieldLocation,
411
- metadata: null,
412
- name: EDGES,
413
- selections: [],
414
- type: schema.assertLinkedFieldType(edgesType)
415
- };
416
- }
417
-
418
- if (transformedPageInfoSelection == null) {
419
- transformedPageInfoSelection = {
420
- alias: PAGE_INFO,
421
- args: [],
422
- connection: false,
423
- directives: [],
424
- handles: null,
425
- kind: 'LinkedField',
426
- loc: derivedFieldLocation,
427
- metadata: null,
428
- name: PAGE_INFO,
429
- selections: [],
430
- type: schema.assertLinkedFieldType(pageInfoType)
431
- };
432
- } // Generate (additional) fields on pageInfo and add to the transformed
433
- // pageInfo field
434
-
435
-
436
- var pageInfoRawType = schema.getRawType(pageInfoType);
437
- var pageInfoText;
438
-
439
- if (direction === 'forward') {
440
- pageInfoText = "fragment PageInfo on ".concat(schema.getTypeString(pageInfoRawType), " {\n ").concat(END_CURSOR, "\n ").concat(HAS_NEXT_PAGE, "\n }");
441
- } else if (direction === 'backward') {
442
- pageInfoText = "fragment PageInfo on ".concat(schema.getTypeString(pageInfoRawType), " {\n ").concat(HAS_PREV_PAGE, "\n ").concat(START_CURSOR, "\n }");
443
- } else {
444
- pageInfoText = "fragment PageInfo on ".concat(schema.getTypeString(pageInfoRawType), " {\n ").concat(END_CURSOR, "\n ").concat(HAS_NEXT_PAGE, "\n ").concat(HAS_PREV_PAGE, "\n ").concat(START_CURSOR, "\n }");
445
- }
446
-
447
- var pageInfoAst = parse(pageInfoText);
448
- var pageInfoFragment = RelayParser.transform(schema, [pageInfoAst.definitions[0]])[0];
449
-
450
- if (transformedPageInfoSelection.kind !== 'LinkedField') {
451
- throw createCompilerError('ConnectionTransform: Expected generated pageInfo selection to be ' + 'a LinkedField', [field.loc]);
452
- }
453
-
454
- transformedPageInfoSelection = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, transformedPageInfoSelection), {}, {
455
- selections: [].concat((0, _toConsumableArray2["default"])(transformedPageInfoSelection.selections), [{
456
- directives: [],
457
- kind: 'InlineFragment',
458
- loc: derivedFieldLocation,
459
- metadata: null,
460
- selections: pageInfoFragment.selections,
461
- typeCondition: pageInfoFragment.type
462
- }])
463
- }); // When streaming the pageInfo field has to be deferred
464
-
465
- if (stream != null) {
466
- var _stream$if$value, _stream$if;
467
-
468
- transformedPageInfoSelection = {
469
- "if": (_stream$if$value = (_stream$if = stream["if"]) === null || _stream$if === void 0 ? void 0 : _stream$if.value) !== null && _stream$if$value !== void 0 ? _stream$if$value : null,
470
- label: "".concat(documentName, "$defer$").concat(stream.label, "$").concat(PAGE_INFO),
471
- kind: 'Defer',
472
- loc: derivedFieldLocation,
473
- selections: [transformedPageInfoSelection]
474
- };
475
- } // Generate additional fields on edges and append to the transformed edges
476
- // selection
477
-
478
-
479
- var edgeText = "\n fragment Edges on ".concat(schema.getTypeString(schema.getRawType(edgesType)), " {\n ").concat(CURSOR, "\n ").concat(NODE, " {\n __typename # rely on GenerateRequisiteFieldTransform to add \"id\"\n }\n }\n ");
480
- var edgeAst = parse(edgeText);
481
- var edgeFragment = RelayParser.transform(schema, [edgeAst.definitions[0]])[0]; // When streaming the edges field needs @stream
482
-
483
- transformedEdgesSelection = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, transformedEdgesSelection), {}, {
484
- directives: streamDirective != null ? [].concat((0, _toConsumableArray2["default"])(transformedEdgesSelection.directives), [streamDirective]) : transformedEdgesSelection.directives,
485
- selections: [].concat((0, _toConsumableArray2["default"])(transformedEdgesSelection.selections), [{
486
- directives: [],
487
- kind: 'InlineFragment',
488
- loc: derivedFieldLocation,
489
- metadata: null,
490
- selections: edgeFragment.selections,
491
- typeCondition: edgeFragment.type
492
- }])
493
- }); // Copy the original selections, replacing edges/pageInfo (if present)
494
- // with the generated locations. This is to maintain the original field
495
- // ordering.
496
-
497
- var selections = field.selections.map(function (selection) {
498
- if (transformedEdgesSelection != null && edgesSelection != null && selection === edgesSelection) {
499
- return transformedEdgesSelection;
500
- } else if (transformedPageInfoSelection != null && pageInfoSelection != null && selection === pageInfoSelection) {
501
- return transformedPageInfoSelection;
502
- } else {
503
- return selection;
504
- }
505
- }); // If edges/pageInfo were missing, append the generated versions instead.
506
-
507
- if (edgesSelection == null && transformedEdgesSelection != null) {
508
- selections.push(transformedEdgesSelection);
509
- }
510
-
511
- if (pageInfoSelection == null && transformedPageInfoSelection != null) {
512
- selections.push(transformedPageInfoSelection);
513
- }
514
-
515
- return selections;
516
- }
517
-
518
- function findArg(field, argName) {
519
- return field.args && field.args.find(function (arg) {
520
- return arg.name === argName;
521
- });
522
- }
523
- /**
524
- * @internal
525
- *
526
- * Validates that the selection is a valid connection:
527
- * - Specifies a first or last argument to prevent accidental, unconstrained
528
- * data access.
529
- * - Has an `edges` selection, otherwise there is nothing to paginate.
530
- *
531
- * TODO: This implementation requires the edges field to be a direct selection
532
- * and not contained within an inline fragment or fragment spread. It's
533
- * technically possible to remove this restriction if this pattern becomes
534
- * common/necessary.
535
- */
536
-
537
-
538
- function validateConnectionSelection(field) {
539
- var _ConnectionInterface$2 = ConnectionInterface.get(),
540
- EDGES = _ConnectionInterface$2.EDGES;
541
-
542
- if (!findArg(field, FIRST) && !findArg(field, LAST)) {
543
- throw createUserError("Expected field '".concat(field.name, "' to have a '").concat(FIRST, "' or '").concat(LAST, "' ") + 'argument.', [field.loc]);
544
- }
545
-
546
- if (!field.selections.some(function (selection) {
547
- return selection.kind === 'LinkedField' && selection.name === EDGES;
548
- })) {
549
- throw createUserError("Expected field '".concat(field.name, "' to have an '").concat(EDGES, "' selection."), [field.loc]);
550
- }
551
- }
552
- /**
553
- * @internal
554
- *
555
- * Validates that the type satisfies the Connection specification:
556
- * - The type has an edges field, and edges have scalar `cursor` and object
557
- * `node` fields.
558
- * - The type has a page info field which is an object with the correct
559
- * subfields.
560
- */
561
-
562
-
563
- function validateConnectionType(schema, field, nullableType, connectionDirective) {
564
- var directiveName = connectionDirective.name;
565
-
566
- var _ConnectionInterface$3 = ConnectionInterface.get(),
567
- CURSOR = _ConnectionInterface$3.CURSOR,
568
- EDGES = _ConnectionInterface$3.EDGES,
569
- END_CURSOR = _ConnectionInterface$3.END_CURSOR,
570
- HAS_NEXT_PAGE = _ConnectionInterface$3.HAS_NEXT_PAGE,
571
- HAS_PREV_PAGE = _ConnectionInterface$3.HAS_PREV_PAGE,
572
- NODE = _ConnectionInterface$3.NODE,
573
- PAGE_INFO = _ConnectionInterface$3.PAGE_INFO,
574
- START_CURSOR = _ConnectionInterface$3.START_CURSOR;
575
-
576
- var typeName = schema.getTypeString(nullableType);
577
-
578
- if (!schema.hasField(nullableType, EDGES)) {
579
- throw createUserError("@".concat(directiveName, " used on invalid field '").concat(field.name, "'. Expected the ") + "field type '".concat(typeName, "' to have an '").concat(EDGES, "' field"), [field.loc]);
580
- }
581
-
582
- var edges = schema.getFieldConfig(schema.expectField(nullableType, EDGES));
583
- var edgesType = schema.getNullableType(edges.type);
584
-
585
- if (!schema.isList(edgesType)) {
586
- throw createUserError("@".concat(directiveName, " used on invalid field '").concat(field.name, "'. Expected the ") + "field type '".concat(typeName, "' to have an '").concat(EDGES, "' field that returns ") + 'a list of objects.', [field.loc]);
587
- }
588
-
589
- var edgeType = schema.getNullableType(schema.getListItemType(edgesType));
590
-
591
- if (!schema.isObject(edgeType) && !schema.isInterface(edgeType)) {
592
- throw createUserError("@".concat(directiveName, " used on invalid field '").concat(field.name, "'. Expected the ") + "field type '".concat(typeName, "' to have an '").concat(EDGES, "' field that returns ") + 'a list of objects.', [field.loc]);
593
- }
594
-
595
- edgeType = schema.assertCompositeType(edgeType);
596
-
597
- if (!schema.hasField(edgeType, NODE)) {
598
- throw createUserError("@".concat(directiveName, " used on invalid field '").concat(field.name, "'. Expected the ") + "field type '".concat(typeName, "' to have an '").concat(EDGES, " { ").concat(NODE, " }' field ") + 'that returns an object, interface, or union.', [field.loc]);
599
- }
600
-
601
- var node = schema.getFieldConfig(schema.expectField(edgeType, NODE));
602
- var nodeType = schema.getNullableType(node.type);
603
-
604
- if (!(schema.isAbstractType(nodeType) || schema.isObject(nodeType))) {
605
- throw createUserError("@".concat(directiveName, " used on invalid field '").concat(field.name, "'. Expected the ") + "field type '".concat(typeName, "' to have an '").concat(EDGES, " { ").concat(NODE, " }' field ") + 'that returns an object, interface, or union.', [field.loc]);
606
- }
607
-
608
- if (!schema.hasField(edgeType, CURSOR)) {
609
- throw createUserError("@".concat(directiveName, " used on invalid field '").concat(field.name, "'. Expected the ") + "field type '".concat(typeName, "' to have an '").concat(EDGES, " { ").concat(CURSOR, " }' field ") + 'that returns a scalar value.', [field.loc]);
610
- }
611
-
612
- var cursor = schema.getFieldConfig(schema.expectField(edgeType, CURSOR));
613
-
614
- if (!schema.isScalar(schema.getNullableType(cursor.type))) {
615
- throw createUserError("@".concat(directiveName, " used on invalid field '").concat(field.name, "'. Expected the ") + "field type '".concat(typeName, "' to have an '").concat(EDGES, " { ").concat(CURSOR, " }' field ") + 'that returns a scalar value.', [field.loc]);
616
- }
617
-
618
- if (!schema.hasField(nullableType, PAGE_INFO)) {
619
- throw createUserError("@".concat(directiveName, " used on invalid field '").concat(field.name, "'. Expected the ") + "field type '".concat(typeName, "' to have a '").concat(PAGE_INFO, "' field that returns ") + 'an object.', [field.loc]);
620
- }
621
-
622
- var pageInfo = schema.getFieldConfig(schema.expectField(nullableType, PAGE_INFO));
623
- var pageInfoType = schema.getNullableType(pageInfo.type);
624
-
625
- if (!schema.isObject(pageInfoType)) {
626
- throw createUserError("@".concat(directiveName, " used on invalid field '").concat(field.name, "'. Expected the ") + "field type '".concat(typeName, "' to have a '").concat(PAGE_INFO, "' field that ") + 'returns an object.', [field.loc]);
627
- }
628
-
629
- [END_CURSOR, HAS_NEXT_PAGE, HAS_PREV_PAGE, START_CURSOR].forEach(function (fieldName) {
630
- var pageInfoField = schema.getFieldConfig(schema.expectField(schema.assertObjectType(pageInfoType), fieldName));
631
-
632
- if (!schema.isScalar(schema.getNullableType(pageInfoField.type))) {
633
- throw createUserError("@".concat(directiveName, " used on invalid field '").concat(field.name, "'. Expected ") + "the field type '".concat(typeName, "' to have a '").concat(PAGE_INFO, " { ").concat(fieldName, " }' ") + 'field returns a scalar.', [field.loc]);
634
- }
635
- });
636
- }
637
-
638
- module.exports = {
639
- buildConnectionMetadata: buildConnectionMetadata,
640
- CONNECTION: CONNECTION,
641
- SCHEMA_EXTENSION: SCHEMA_EXTENSION,
642
- transform: connectionTransform
643
- };