relay-compiler 0.0.0-main-f0b65f0b → 0.0.0-main-e0026a71

Sign up to get free protection for your applications and to get access to all the features.
Files changed (263) hide show
  1. package/cli.js +23 -0
  2. package/index.js +19 -3
  3. package/linux-x64/relay +0 -0
  4. package/macos-x64/relay +0 -0
  5. package/package.json +2 -24
  6. package/win-x64/relay.exe +0 -0
  7. package/bin/RelayCompilerBin.js.flow +0 -168
  8. package/bin/RelayCompilerMain.js.flow +0 -515
  9. package/bin/__fixtures__/plugin-module.js.flow +0 -17
  10. package/bin/relay-compiler +0 -19068
  11. package/codegen/CodegenDirectory.js.flow +0 -372
  12. package/codegen/CodegenRunner.js.flow +0 -424
  13. package/codegen/CodegenTypes.js.flow +0 -28
  14. package/codegen/CodegenWatcher.js.flow +0 -250
  15. package/codegen/NormalizationCodeGenerator.js.flow +0 -566
  16. package/codegen/ReaderCodeGenerator.js.flow +0 -510
  17. package/codegen/RelayCodeGenerator.js.flow +0 -85
  18. package/codegen/RelayFileWriter.js.flow +0 -365
  19. package/codegen/SourceControl.js.flow +0 -58
  20. package/codegen/compileRelayArtifacts.js.flow +0 -181
  21. package/codegen/createPrintRequireModuleDependency.js.flow +0 -19
  22. package/codegen/sortObjectByKey.js.flow +0 -25
  23. package/codegen/writeRelayGeneratedFile.js.flow +0 -235
  24. package/core/ASTCache.js.flow +0 -73
  25. package/core/ASTConvert.js.flow +0 -230
  26. package/core/CompilerContext.js.flow +0 -189
  27. package/core/CompilerError.js.flow +0 -255
  28. package/core/DotGraphQLParser.js.flow +0 -37
  29. package/core/GraphQLCompilerProfiler.js.flow +0 -341
  30. package/core/GraphQLDerivedFromMetadata.js.flow +0 -36
  31. package/core/GraphQLWatchmanClient.js.flow +0 -109
  32. package/core/IR.js.flow +0 -326
  33. package/core/IRPrinter.js.flow +0 -472
  34. package/core/IRTransformer.js.flow +0 -376
  35. package/core/IRValidator.js.flow +0 -259
  36. package/core/IRVisitor.js.flow +0 -150
  37. package/core/JSModuleParser.js.flow +0 -24
  38. package/core/RelayCompilerScope.js.flow +0 -199
  39. package/core/RelayFindGraphQLTags.js.flow +0 -118
  40. package/core/RelayGraphQLEnumsGenerator.js.flow +0 -55
  41. package/core/RelayIRTransforms.js.flow +0 -138
  42. package/core/RelayParser.js.flow +0 -1741
  43. package/core/RelaySourceModuleParser.js.flow +0 -133
  44. package/core/Schema.js.flow +0 -2035
  45. package/core/SchemaUtils.js.flow +0 -120
  46. package/core/filterContextForNode.js.flow +0 -49
  47. package/core/getFieldDefinition.js.flow +0 -156
  48. package/core/getIdentifierForArgumentValue.js.flow +0 -49
  49. package/core/getIdentifierForSelection.js.flow +0 -68
  50. package/core/getLiteralArgumentValues.js.flow +0 -32
  51. package/core/getNormalizationOperationName.js.flow +0 -19
  52. package/core/inferRootArgumentDefinitions.js.flow +0 -322
  53. package/index.js.flow +0 -198
  54. package/language/RelayLanguagePluginInterface.js.flow +0 -283
  55. package/language/javascript/FindGraphQLTags.js.flow +0 -136
  56. package/language/javascript/RelayFlowBabelFactories.js.flow +0 -176
  57. package/language/javascript/RelayFlowGenerator.js.flow +0 -1096
  58. package/language/javascript/RelayFlowTypeTransformers.js.flow +0 -181
  59. package/language/javascript/RelayLanguagePluginJavaScript.js.flow +0 -33
  60. package/language/javascript/formatGeneratedModule.js.flow +0 -65
  61. package/lib/bin/RelayCompilerBin.js +0 -143
  62. package/lib/bin/RelayCompilerMain.js +0 -488
  63. package/lib/bin/__fixtures__/plugin-module.js +0 -16
  64. package/lib/codegen/CodegenDirectory.js +0 -335
  65. package/lib/codegen/CodegenRunner.js +0 -433
  66. package/lib/codegen/CodegenTypes.js +0 -11
  67. package/lib/codegen/CodegenWatcher.js +0 -271
  68. package/lib/codegen/NormalizationCodeGenerator.js +0 -487
  69. package/lib/codegen/ReaderCodeGenerator.js +0 -473
  70. package/lib/codegen/RelayCodeGenerator.js +0 -75
  71. package/lib/codegen/RelayFileWriter.js +0 -270
  72. package/lib/codegen/SourceControl.js +0 -60
  73. package/lib/codegen/compileRelayArtifacts.js +0 -157
  74. package/lib/codegen/createPrintRequireModuleDependency.js +0 -19
  75. package/lib/codegen/sortObjectByKey.js +0 -41
  76. package/lib/codegen/writeRelayGeneratedFile.js +0 -206
  77. package/lib/core/ASTCache.js +0 -70
  78. package/lib/core/ASTConvert.js +0 -198
  79. package/lib/core/CompilerContext.js +0 -165
  80. package/lib/core/CompilerError.js +0 -252
  81. package/lib/core/DotGraphQLParser.js +0 -40
  82. package/lib/core/GraphQLCompilerProfiler.js +0 -299
  83. package/lib/core/GraphQLDerivedFromMetadata.js +0 -31
  84. package/lib/core/GraphQLWatchmanClient.js +0 -150
  85. package/lib/core/IR.js +0 -11
  86. package/lib/core/IRPrinter.js +0 -388
  87. package/lib/core/IRTransformer.js +0 -345
  88. package/lib/core/IRValidator.js +0 -226
  89. package/lib/core/IRVisitor.js +0 -45
  90. package/lib/core/JSModuleParser.js +0 -18
  91. package/lib/core/RelayCompilerScope.js +0 -183
  92. package/lib/core/RelayFindGraphQLTags.js +0 -79
  93. package/lib/core/RelayGraphQLEnumsGenerator.js +0 -50
  94. package/lib/core/RelayIRTransforms.js +0 -109
  95. package/lib/core/RelayParser.js +0 -1381
  96. package/lib/core/RelaySourceModuleParser.js +0 -104
  97. package/lib/core/Schema.js +0 -1877
  98. package/lib/core/SchemaUtils.js +0 -98
  99. package/lib/core/filterContextForNode.js +0 -50
  100. package/lib/core/getFieldDefinition.js +0 -145
  101. package/lib/core/getIdentifierForArgumentValue.js +0 -54
  102. package/lib/core/getIdentifierForSelection.js +0 -49
  103. package/lib/core/getLiteralArgumentValues.js +0 -26
  104. package/lib/core/getNormalizationOperationName.js +0 -17
  105. package/lib/core/inferRootArgumentDefinitions.js +0 -351
  106. package/lib/index.js +0 -178
  107. package/lib/language/RelayLanguagePluginInterface.js +0 -26
  108. package/lib/language/javascript/FindGraphQLTags.js +0 -126
  109. package/lib/language/javascript/RelayFlowBabelFactories.js +0 -160
  110. package/lib/language/javascript/RelayFlowGenerator.js +0 -856
  111. package/lib/language/javascript/RelayFlowTypeTransformers.js +0 -119
  112. package/lib/language/javascript/RelayLanguagePluginJavaScript.js +0 -30
  113. package/lib/language/javascript/formatGeneratedModule.js +0 -36
  114. package/lib/reporters/ConsoleReporter.js +0 -61
  115. package/lib/reporters/MultiReporter.js +0 -45
  116. package/lib/reporters/Reporter.js +0 -11
  117. package/lib/runner/Artifacts.js +0 -323
  118. package/lib/runner/BufferedFilesystem.js +0 -262
  119. package/lib/runner/GraphQLASTNodeGroup.js +0 -256
  120. package/lib/runner/GraphQLASTUtils.js +0 -23
  121. package/lib/runner/GraphQLNodeMap.js +0 -81
  122. package/lib/runner/Sources.js +0 -271
  123. package/lib/runner/StrictMap.js +0 -134
  124. package/lib/runner/compileArtifacts.js +0 -39
  125. package/lib/runner/extractAST.js +0 -77
  126. package/lib/runner/getChangedNodeNames.js +0 -82
  127. package/lib/runner/getSchemaInstance.js +0 -30
  128. package/lib/runner/types.js +0 -12
  129. package/lib/test-utils/TestSchema.js +0 -27
  130. package/lib/test-utils/parseGraphQLText.js +0 -30
  131. package/lib/transforms/ApplyFragmentArgumentTransform.js +0 -393
  132. package/lib/transforms/ClientExtensionsTransform.js +0 -221
  133. package/lib/transforms/ConnectionTransform.js +0 -639
  134. package/lib/transforms/DeclarativeConnectionMutationTransform.js +0 -218
  135. package/lib/transforms/DeferStreamTransform.js +0 -246
  136. package/lib/transforms/DisallowIdAsAlias.js +0 -40
  137. package/lib/transforms/DisallowTypenameOnRoot.js +0 -53
  138. package/lib/transforms/FieldHandleTransform.js +0 -79
  139. package/lib/transforms/FilterCompilerDirectivesTransform.js +0 -29
  140. package/lib/transforms/FilterDirectivesTransform.js +0 -42
  141. package/lib/transforms/FlattenTransform.js +0 -306
  142. package/lib/transforms/GenerateIDFieldTransform.js +0 -135
  143. package/lib/transforms/GenerateTypeNameTransform.js +0 -149
  144. package/lib/transforms/InlineDataFragmentTransform.js +0 -100
  145. package/lib/transforms/InlineFragmentsTransform.js +0 -61
  146. package/lib/transforms/MaskTransform.js +0 -117
  147. package/lib/transforms/MatchTransform.js +0 -434
  148. package/lib/transforms/ReactFlightComponentTransform.js +0 -158
  149. package/lib/transforms/RefetchableFragmentTransform.js +0 -249
  150. package/lib/transforms/RelayDirectiveTransform.js +0 -83
  151. package/lib/transforms/RequiredFieldTransform.js +0 -369
  152. package/lib/transforms/SkipClientExtensionsTransform.js +0 -46
  153. package/lib/transforms/SkipHandleFieldTransform.js +0 -45
  154. package/lib/transforms/SkipRedundantNodesTransform.js +0 -261
  155. package/lib/transforms/SkipSplitOperationTransform.js +0 -32
  156. package/lib/transforms/SkipUnreachableNodeTransform.js +0 -158
  157. package/lib/transforms/SkipUnusedVariablesTransform.js +0 -75
  158. package/lib/transforms/SplitModuleImportTransform.js +0 -82
  159. package/lib/transforms/TestOperationTransform.js +0 -144
  160. package/lib/transforms/TransformUtils.js +0 -21
  161. package/lib/transforms/ValidateGlobalVariablesTransform.js +0 -92
  162. package/lib/transforms/ValidateRequiredArgumentsTransform.js +0 -114
  163. package/lib/transforms/ValidateServerOnlyDirectivesTransform.js +0 -108
  164. package/lib/transforms/ValidateUnusedVariablesTransform.js +0 -96
  165. package/lib/transforms/query-generators/FetchableQueryGenerator.js +0 -157
  166. package/lib/transforms/query-generators/NodeQueryGenerator.js +0 -166
  167. package/lib/transforms/query-generators/QueryQueryGenerator.js +0 -48
  168. package/lib/transforms/query-generators/ViewerQueryGenerator.js +0 -77
  169. package/lib/transforms/query-generators/index.js +0 -60
  170. package/lib/transforms/query-generators/utils.js +0 -92
  171. package/lib/util/CodeMarker.js +0 -80
  172. package/lib/util/DefaultHandleKey.js +0 -15
  173. package/lib/util/RelayCompilerCache.js +0 -97
  174. package/lib/util/Rollout.js +0 -40
  175. package/lib/util/TimeReporter.js +0 -83
  176. package/lib/util/areEqualArgValues.js +0 -135
  177. package/lib/util/argumentContainsVariables.js +0 -37
  178. package/lib/util/dedupeJSONStringify.js +0 -160
  179. package/lib/util/generateAbstractTypeRefinementKey.js +0 -24
  180. package/lib/util/getDefinitionNodeHash.js +0 -22
  181. package/lib/util/getModuleName.js +0 -32
  182. package/lib/util/joinArgumentDefinitions.js +0 -67
  183. package/lib/util/md5.js +0 -17
  184. package/lib/util/murmurHash.js +0 -86
  185. package/lib/util/nullthrowsOSS.js +0 -23
  186. package/lib/util/orList.js +0 -36
  187. package/lib/util/partitionArray.js +0 -35
  188. package/relay-compiler.js +0 -17
  189. package/relay-compiler.min.js +0 -22
  190. package/reporters/ConsoleReporter.js.flow +0 -81
  191. package/reporters/MultiReporter.js.flow +0 -43
  192. package/reporters/Reporter.js.flow +0 -19
  193. package/runner/Artifacts.js.flow +0 -215
  194. package/runner/BufferedFilesystem.js.flow +0 -194
  195. package/runner/GraphQLASTNodeGroup.js.flow +0 -174
  196. package/runner/GraphQLASTUtils.js.flow +0 -26
  197. package/runner/GraphQLNodeMap.js.flow +0 -55
  198. package/runner/Sources.js.flow +0 -227
  199. package/runner/StrictMap.js.flow +0 -96
  200. package/runner/compileArtifacts.js.flow +0 -75
  201. package/runner/extractAST.js.flow +0 -98
  202. package/runner/getChangedNodeNames.js.flow +0 -48
  203. package/runner/getSchemaInstance.js.flow +0 -36
  204. package/runner/types.js.flow +0 -37
  205. package/test-utils/TestSchema.js.flow +0 -30
  206. package/test-utils/parseGraphQLText.js.flow +0 -41
  207. package/transforms/ApplyFragmentArgumentTransform.js.flow +0 -524
  208. package/transforms/ClientExtensionsTransform.js.flow +0 -224
  209. package/transforms/ConnectionTransform.js.flow +0 -850
  210. package/transforms/DeclarativeConnectionMutationTransform.js.flow +0 -245
  211. package/transforms/DeferStreamTransform.js.flow +0 -263
  212. package/transforms/DisallowIdAsAlias.js.flow +0 -46
  213. package/transforms/DisallowTypenameOnRoot.js.flow +0 -44
  214. package/transforms/FieldHandleTransform.js.flow +0 -77
  215. package/transforms/FilterCompilerDirectivesTransform.js.flow +0 -33
  216. package/transforms/FilterDirectivesTransform.js.flow +0 -45
  217. package/transforms/FlattenTransform.js.flow +0 -458
  218. package/transforms/GenerateIDFieldTransform.js.flow +0 -151
  219. package/transforms/GenerateTypeNameTransform.js.flow +0 -159
  220. package/transforms/InlineDataFragmentTransform.js.flow +0 -123
  221. package/transforms/InlineFragmentsTransform.js.flow +0 -70
  222. package/transforms/MaskTransform.js.flow +0 -124
  223. package/transforms/MatchTransform.js.flow +0 -587
  224. package/transforms/ReactFlightComponentTransform.js.flow +0 -207
  225. package/transforms/RefetchableFragmentTransform.js.flow +0 -266
  226. package/transforms/RelayDirectiveTransform.js.flow +0 -96
  227. package/transforms/RequiredFieldTransform.js.flow +0 -413
  228. package/transforms/SkipClientExtensionsTransform.js.flow +0 -54
  229. package/transforms/SkipHandleFieldTransform.js.flow +0 -44
  230. package/transforms/SkipRedundantNodesTransform.js.flow +0 -277
  231. package/transforms/SkipSplitOperationTransform.js.flow +0 -37
  232. package/transforms/SkipUnreachableNodeTransform.js.flow +0 -148
  233. package/transforms/SkipUnusedVariablesTransform.js.flow +0 -59
  234. package/transforms/SplitModuleImportTransform.js.flow +0 -97
  235. package/transforms/TestOperationTransform.js.flow +0 -142
  236. package/transforms/TransformUtils.js.flow +0 -26
  237. package/transforms/ValidateGlobalVariablesTransform.js.flow +0 -80
  238. package/transforms/ValidateRequiredArgumentsTransform.js.flow +0 -130
  239. package/transforms/ValidateServerOnlyDirectivesTransform.js.flow +0 -128
  240. package/transforms/ValidateUnusedVariablesTransform.js.flow +0 -88
  241. package/transforms/query-generators/FetchableQueryGenerator.js.flow +0 -188
  242. package/transforms/query-generators/NodeQueryGenerator.js.flow +0 -217
  243. package/transforms/query-generators/QueryQueryGenerator.js.flow +0 -57
  244. package/transforms/query-generators/ViewerQueryGenerator.js.flow +0 -97
  245. package/transforms/query-generators/index.js.flow +0 -89
  246. package/transforms/query-generators/utils.js.flow +0 -76
  247. package/util/CodeMarker.js.flow +0 -79
  248. package/util/DefaultHandleKey.js.flow +0 -17
  249. package/util/RelayCompilerCache.js.flow +0 -86
  250. package/util/Rollout.js.flow +0 -39
  251. package/util/TimeReporter.js.flow +0 -79
  252. package/util/areEqualArgValues.js.flow +0 -126
  253. package/util/argumentContainsVariables.js.flow +0 -38
  254. package/util/dedupeJSONStringify.js.flow +0 -156
  255. package/util/generateAbstractTypeRefinementKey.js.flow +0 -29
  256. package/util/getDefinitionNodeHash.js.flow +0 -24
  257. package/util/getModuleName.js.flow +0 -39
  258. package/util/joinArgumentDefinitions.js.flow +0 -105
  259. package/util/md5.js.flow +0 -19
  260. package/util/murmurHash.js.flow +0 -94
  261. package/util/nullthrowsOSS.js.flow +0 -25
  262. package/util/orList.js.flow +0 -37
  263. package/util/partitionArray.js.flow +0 -37
@@ -1,218 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- */
10
- // flowlint ambiguous-object-type:error
11
- 'use strict';
12
-
13
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
14
-
15
- var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
16
-
17
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
18
-
19
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
20
-
21
- var _require = require('../core/CompilerError'),
22
- createUserError = _require.createUserError;
23
-
24
- var IRTransformer = require('../core/IRTransformer');
25
-
26
- var _require2 = require('relay-runtime'),
27
- ConnectionInterface = _require2.ConnectionInterface;
28
-
29
- var DELETE_RECORD = 'deleteRecord';
30
- var DELETE_EDGE = 'deleteEdge';
31
- var APPEND_EDGE = 'appendEdge';
32
- var PREPEND_EDGE = 'prependEdge';
33
- var APPEND_NODE = 'appendNode';
34
- var PREPEND_NODE = 'prependNode';
35
- var EDGE_LINKED_FIELD_DIRECTIVES = [APPEND_EDGE, PREPEND_EDGE];
36
- var NODE_LINKED_FIELD_DIRECTIVES = [APPEND_NODE, PREPEND_NODE];
37
- var LINKED_FIELD_DIRECTIVES = [].concat(EDGE_LINKED_FIELD_DIRECTIVES, NODE_LINKED_FIELD_DIRECTIVES);
38
- var SCHEMA_EXTENSION = "\n directive @".concat(DELETE_RECORD, " on FIELD\n directive @").concat(DELETE_EDGE, "(\n connections: [ID!]!\n ) on FIELD\n directive @").concat(APPEND_EDGE, "(\n connections: [ID!]!\n ) on FIELD\n directive @").concat(PREPEND_EDGE, "(\n connections: [ID!]!\n ) on FIELD\n directive @").concat(APPEND_NODE, "(\n connections: [ID!]!\n edgeTypeName: String!\n ) on FIELD\n directive @").concat(PREPEND_NODE, "(\n connections: [ID!]!\n edgeTypeName: String!\n ) on FIELD\n");
39
-
40
- function transform(context) {
41
- return IRTransformer.transform(context, {
42
- ScalarField: visitScalarField,
43
- LinkedField: visitLinkedField,
44
- SplitOperation: skip,
45
- Fragment: skip
46
- });
47
- }
48
-
49
- function skip(node) {
50
- return node;
51
- }
52
-
53
- function visitScalarField(field) {
54
- var linkedFieldDirective = field.directives.find(function (directive) {
55
- return LINKED_FIELD_DIRECTIVES.indexOf(directive.name) > -1;
56
- });
57
-
58
- if (linkedFieldDirective != null) {
59
- throw createUserError("Invalid use of @".concat(linkedFieldDirective.name, " on scalar field '").concat(field.name, "'"), [linkedFieldDirective.loc]);
60
- }
61
-
62
- var deleteNodeDirective = field.directives.find(function (directive) {
63
- return directive.name === DELETE_RECORD;
64
- });
65
- var deleteEdgeDirective = field.directives.find(function (directive) {
66
- return directive.name === DELETE_EDGE;
67
- });
68
-
69
- if (deleteNodeDirective != null && deleteEdgeDirective != null) {
70
- throw createUserError("Both @deleteNode and @deleteEdge are used on field '".concat(field.name, "'. Only one directive is supported for now."), [deleteNodeDirective.loc, deleteEdgeDirective.loc]);
71
- }
72
-
73
- var targetDirective = deleteNodeDirective !== null && deleteNodeDirective !== void 0 ? deleteNodeDirective : deleteEdgeDirective;
74
-
75
- if (targetDirective == null) {
76
- return field;
77
- }
78
-
79
- var schema = this.getContext().getSchema();
80
-
81
- if (!schema.isId(schema.getRawType(field.type))) {
82
- throw createUserError("Invalid use of @".concat(targetDirective.name, " on field '").concat(field.name, "'. Expected field to return an ID or list of ID values, got ").concat(schema.getTypeString(field.type), "."), [targetDirective.loc]);
83
- }
84
-
85
- var connectionsArg = targetDirective.args.find(function (arg) {
86
- return arg.name === 'connections';
87
- });
88
- var handle = {
89
- name: targetDirective.name,
90
- key: '',
91
- dynamicKey: null,
92
- filters: null,
93
- handleArgs: connectionsArg ? [connectionsArg] : undefined
94
- };
95
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, field), {}, {
96
- directives: field.directives.filter(function (directive) {
97
- return directive !== targetDirective;
98
- }),
99
- handles: field.handles ? [].concat((0, _toConsumableArray2["default"])(field.handles), [handle]) : [handle]
100
- });
101
- }
102
-
103
- function visitLinkedField(field) {
104
- var transformedField = this.traverse(field);
105
- var deleteDirective = transformedField.directives.find(function (directive) {
106
- return directive.name === DELETE_RECORD;
107
- });
108
-
109
- if (deleteDirective != null) {
110
- throw createUserError("Invalid use of @".concat(deleteDirective.name, " on scalar field '").concat(transformedField.name, "'."), [deleteDirective.loc]);
111
- }
112
-
113
- var edgeDirective = transformedField.directives.find(function (directive) {
114
- return EDGE_LINKED_FIELD_DIRECTIVES.indexOf(directive.name) > -1;
115
- });
116
- var nodeDirective = transformedField.directives.find(function (directive) {
117
- return NODE_LINKED_FIELD_DIRECTIVES.indexOf(directive.name) > -1;
118
- });
119
-
120
- if (edgeDirective == null && nodeDirective == null) {
121
- return transformedField;
122
- }
123
-
124
- if (edgeDirective != null && nodeDirective != null) {
125
- throw createUserError("Invalid use of @".concat(edgeDirective.name, " and @").concat(nodeDirective.name, " on field '").concat(transformedField.name, "' - these directives cannot be used together."), [edgeDirective.loc]);
126
- }
127
-
128
- var targetDirective = edgeDirective !== null && edgeDirective !== void 0 ? edgeDirective : nodeDirective;
129
- var connectionsArg = targetDirective.args.find(function (arg) {
130
- return arg.name === 'connections';
131
- });
132
-
133
- if (connectionsArg == null) {
134
- throw createUserError("Expected the 'connections' argument to be defined on @".concat(targetDirective.name, "."), [targetDirective.loc]);
135
- }
136
-
137
- var schema = this.getContext().getSchema();
138
-
139
- if (edgeDirective) {
140
- var fieldType = schema.getRawType(transformedField.type);
141
- var fields = schema.getFields(fieldType);
142
- var cursorFieldID;
143
- var nodeFieldID;
144
-
145
- var _iterator = (0, _createForOfIteratorHelper2["default"])(fields),
146
- _step;
147
-
148
- try {
149
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
150
- var fieldID = _step.value;
151
- var fieldName = schema.getFieldName(fieldID);
152
-
153
- if (fieldName === ConnectionInterface.get().CURSOR) {
154
- cursorFieldID = fieldID;
155
- } else if (fieldName === ConnectionInterface.get().NODE) {
156
- nodeFieldID = fieldID;
157
- }
158
- } // Edge
159
-
160
- } catch (err) {
161
- _iterator.e(err);
162
- } finally {
163
- _iterator.f();
164
- }
165
-
166
- if (cursorFieldID != null && nodeFieldID != null) {
167
- var handle = {
168
- name: edgeDirective.name,
169
- key: '',
170
- dynamicKey: null,
171
- filters: null,
172
- handleArgs: [connectionsArg]
173
- };
174
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, transformedField), {}, {
175
- directives: transformedField.directives.filter(function (directive) {
176
- return directive !== edgeDirective;
177
- }),
178
- handles: transformedField.handles ? [].concat((0, _toConsumableArray2["default"])(transformedField.handles), [handle]) : [handle]
179
- });
180
- }
181
-
182
- throw createUserError("Unsupported use of @".concat(edgeDirective.name, " on field '").concat(transformedField.name, "', expected an edge field (a field with 'cursor' and 'node' selection)."), [targetDirective.loc]);
183
- } else {
184
- // Node
185
- var edgeTypeNameArg = nodeDirective.args.find(function (arg) {
186
- return arg.name === 'edgeTypeName';
187
- });
188
-
189
- if (!edgeTypeNameArg) {
190
- throw createUserError("Unsupported use of @".concat(nodeDirective.name, " on field '").concat(transformedField.name, "', 'edgeTypeName' argument must be provided."), [targetDirective.loc]);
191
- }
192
-
193
- var rawType = schema.getRawType(transformedField.type);
194
-
195
- if (schema.canHaveSelections(rawType)) {
196
- var _handle = {
197
- name: nodeDirective.name,
198
- key: '',
199
- dynamicKey: null,
200
- filters: null,
201
- handleArgs: [connectionsArg, edgeTypeNameArg]
202
- };
203
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, transformedField), {}, {
204
- directives: transformedField.directives.filter(function (directive) {
205
- return directive !== nodeDirective;
206
- }),
207
- handles: transformedField.handles ? [].concat((0, _toConsumableArray2["default"])(transformedField.handles), [_handle]) : [_handle]
208
- });
209
- }
210
-
211
- throw createUserError("Unsupported use of @".concat(nodeDirective.name, " on field '").concat(transformedField.name, "'. Expected an object, union or interface, but got '").concat(schema.getTypeString(transformedField.type), "'."), [nodeDirective.loc]);
212
- }
213
- }
214
-
215
- module.exports = {
216
- SCHEMA_EXTENSION: SCHEMA_EXTENSION,
217
- transform: transform
218
- };
@@ -1,246 +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 _require = require('../core/CompilerError'),
20
- createUserError = _require.createUserError;
21
-
22
- var getIdentifierForArgumentValue = require('../core/getIdentifierForArgumentValue');
23
-
24
- var IRTransformer = require('../core/IRTransformer');
25
-
26
- var murmurHash = require('../util/murmurHash');
27
-
28
- /**
29
- * This transform finds usages of @defer and @stream, validates them, and
30
- * converts the using node to specialized IR nodes (Defer/Stream).
31
- */
32
- function deferStreamTransform(context) {
33
- return IRTransformer.transform(context, {
34
- // TODO: type IRTransformer to allow changing result type
35
- FragmentSpread: visitFragmentSpread,
36
- // TODO: type IRTransformer to allow changing result type
37
- InlineFragment: visitInlineFragment,
38
- // TODO: type IRTransformer to allow changing result type
39
- LinkedField: visitLinkedField,
40
- ScalarField: visitScalarField
41
- }, function (sourceNode) {
42
- var labels = new Map();
43
- return {
44
- documentName: sourceNode.name,
45
- recordLabel: function recordLabel(label, directive) {
46
- var prevDirective = labels.get(label);
47
-
48
- if (prevDirective) {
49
- var _prevLabelArg$loc;
50
-
51
- var labelArg = directive.args.find(function (_ref) {
52
- var name = _ref.name;
53
- return name === 'label';
54
- });
55
- var prevLabelArg = prevDirective.args.find(function (_ref2) {
56
- var name = _ref2.name;
57
- return name === 'label';
58
- });
59
- var previousLocation = (_prevLabelArg$loc = prevLabelArg === null || prevLabelArg === void 0 ? void 0 : prevLabelArg.loc) !== null && _prevLabelArg$loc !== void 0 ? _prevLabelArg$loc : prevDirective.loc;
60
-
61
- if (labelArg) {
62
- throw createUserError("Invalid use of @".concat(directive.name, ", the provided label is ") + "not unique. Specify a unique 'label' as a literal string.", [labelArg === null || labelArg === void 0 ? void 0 : labelArg.loc, previousLocation]);
63
- } else {
64
- throw createUserError("Invalid use of @".concat(directive.name, ", could not generate a ") + "default label that is unique. Specify a unique 'label' " + 'as a literal string.', [directive.loc, previousLocation]);
65
- }
66
- }
67
-
68
- labels.set(label, directive);
69
- }
70
- };
71
- });
72
- }
73
-
74
- function visitLinkedField(field, state) {
75
- var _getLiteralStringArgu, _ifArg$value, _useCustomizedBatch$v;
76
-
77
- var context = this.getContext();
78
- var schema = context.getSchema();
79
- var transformedField = this.traverse(field, state);
80
- var streamDirective = transformedField.directives.find(function (directive) {
81
- return directive.name === 'stream';
82
- });
83
-
84
- if (streamDirective == null) {
85
- return transformedField;
86
- }
87
-
88
- var type = schema.getNullableType(field.type);
89
-
90
- if (!schema.isList(type)) {
91
- throw createUserError("Invalid use of @stream on non-plural field '".concat(field.name, "'"), [streamDirective.loc]);
92
- }
93
-
94
- transformedField = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, transformedField), {}, {
95
- directives: transformedField.directives.filter(function (directive) {
96
- return directive.name !== 'stream';
97
- })
98
- });
99
- var ifArg = streamDirective.args.find(function (arg) {
100
- return arg.name === 'if';
101
- });
102
-
103
- if (isLiteralFalse(ifArg)) {
104
- return transformedField;
105
- }
106
-
107
- var initialCount = streamDirective.args.find(function (arg) {
108
- return arg.name === 'initial_count';
109
- });
110
-
111
- if (initialCount == null) {
112
- throw createUserError("Invalid use of @stream, the 'initial_count' argument is required.", [streamDirective.loc]);
113
- }
114
-
115
- var useCustomizedBatch = streamDirective.args.find(function (arg) {
116
- return arg.name === 'use_customized_batch';
117
- });
118
- var label = (_getLiteralStringArgu = getLiteralStringArgument(streamDirective, 'label')) !== null && _getLiteralStringArgu !== void 0 ? _getLiteralStringArgu : field.alias;
119
- var transformedLabel = transformLabel(state.documentName, 'stream', label);
120
- state.recordLabel(transformedLabel, streamDirective);
121
- return {
122
- "if": (_ifArg$value = ifArg === null || ifArg === void 0 ? void 0 : ifArg.value) !== null && _ifArg$value !== void 0 ? _ifArg$value : null,
123
- initialCount: initialCount.value,
124
- useCustomizedBatch: (_useCustomizedBatch$v = useCustomizedBatch === null || useCustomizedBatch === void 0 ? void 0 : useCustomizedBatch.value) !== null && _useCustomizedBatch$v !== void 0 ? _useCustomizedBatch$v : null,
125
- kind: 'Stream',
126
- label: transformedLabel,
127
- loc: {
128
- kind: 'Derived',
129
- source: streamDirective.loc
130
- },
131
- metadata: null,
132
- selections: [transformedField]
133
- };
134
- }
135
-
136
- function visitScalarField(field, state) {
137
- var streamDirective = field.directives.find(function (directive) {
138
- return directive.name === 'stream';
139
- });
140
-
141
- if (streamDirective != null) {
142
- throw createUserError("Invalid use of @stream on scalar field '".concat(field.name, "'"), [streamDirective.loc]);
143
- }
144
-
145
- return this.traverse(field, state);
146
- }
147
-
148
- function visitInlineFragment(fragment, state) {
149
- var deferDirective = fragment.directives.find(function (directive) {
150
- return directive.name === 'defer';
151
- });
152
-
153
- if (deferDirective != null) {
154
- throw createUserError('Invalid use of @defer on an inline fragment, @defer is only supported on fragment spreads.', [fragment.loc]);
155
- }
156
-
157
- return this.traverse(fragment, state);
158
- }
159
-
160
- function visitFragmentSpread(spread, state) {
161
- var _getLiteralStringArgu2, _ifArg$value2;
162
-
163
- var transformedSpread = this.traverse(spread, state);
164
- var deferDirective = transformedSpread.directives.find(function (directive) {
165
- return directive.name === 'defer';
166
- });
167
-
168
- if (deferDirective == null) {
169
- return transformedSpread;
170
- }
171
-
172
- transformedSpread = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, transformedSpread), {}, {
173
- directives: transformedSpread.directives.filter(function (directive) {
174
- return directive.name !== 'defer';
175
- })
176
- });
177
- var ifArg = deferDirective.args.find(function (arg) {
178
- return arg.name === 'if';
179
- });
180
-
181
- if (isLiteralFalse(ifArg)) {
182
- return transformedSpread;
183
- }
184
-
185
- var label = (_getLiteralStringArgu2 = getLiteralStringArgument(deferDirective, 'label')) !== null && _getLiteralStringArgu2 !== void 0 ? _getLiteralStringArgu2 : getFragmentSpreadName(spread);
186
- var transformedLabel = transformLabel(state.documentName, 'defer', label);
187
- state.recordLabel(transformedLabel, deferDirective);
188
- return {
189
- "if": (_ifArg$value2 = ifArg === null || ifArg === void 0 ? void 0 : ifArg.value) !== null && _ifArg$value2 !== void 0 ? _ifArg$value2 : null,
190
- kind: 'Defer',
191
- label: transformedLabel,
192
- loc: {
193
- kind: 'Derived',
194
- source: deferDirective.loc
195
- },
196
- selections: [transformedSpread]
197
- };
198
- }
199
-
200
- function getLiteralStringArgument(directive, argName) {
201
- var arg = directive.args.find(function (_ref3) {
202
- var name = _ref3.name;
203
- return name === argName;
204
- });
205
-
206
- if (arg == null) {
207
- return null;
208
- }
209
-
210
- var value = arg.value.kind === 'Literal' ? arg.value.value : null;
211
-
212
- if (value == null || typeof value !== 'string') {
213
- throw createUserError("Expected the '".concat(argName, "' value to @").concat(directive.name, " to be a string literal if provided."), [arg.value.loc]);
214
- }
215
-
216
- return value;
217
- }
218
-
219
- function transformLabel(parentName, directive, label) {
220
- return "".concat(parentName, "$").concat(directive, "$").concat(label);
221
- }
222
-
223
- function isLiteralFalse(arg) {
224
- return arg != null && arg.value.kind === 'Literal' && arg.value.value === false;
225
- }
226
-
227
- function getFragmentSpreadName(fragmentSpread) {
228
- if (fragmentSpread.args.length === 0) {
229
- return fragmentSpread.name;
230
- }
231
-
232
- var sortedArgs = (0, _toConsumableArray2["default"])(fragmentSpread.args).sort(function (a, b) {
233
- return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
234
- }).map(function (argument) {
235
- return {
236
- name: argument.name,
237
- value: getIdentifierForArgumentValue(argument.value)
238
- };
239
- });
240
- var hash = murmurHash(JSON.stringify(sortedArgs));
241
- return "".concat(fragmentSpread.name, "_").concat(hash);
242
- }
243
-
244
- module.exports = {
245
- transform: deferStreamTransform
246
- };
@@ -1,40 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- */
10
- // flowlint ambiguous-object-type:error
11
- 'use strict';
12
-
13
- var _require = require('../core/CompilerError'),
14
- createUserError = _require.createUserError;
15
-
16
- var IRTransformer = require('../core/IRTransformer');
17
-
18
- function visitField(field) {
19
- if (field.alias === 'id' && field.name !== 'id') {
20
- throw createUserError('Relay does not allow aliasing fields to `id`. ' + 'This name is reserved for the globally unique `id` field on ' + '`Node`.', [field.loc]);
21
- }
22
-
23
- return this.traverse(field);
24
- }
25
- /**
26
- * This is not an actual transform (but more a validation)
27
- * Relay does not allow aliasing fields to `id`.
28
- */
29
-
30
-
31
- function disallowIdAsAlias(context) {
32
- return IRTransformer.transform(context, {
33
- ScalarField: visitField,
34
- LinkedField: visitField
35
- });
36
- }
37
-
38
- module.exports = {
39
- transform: disallowIdAsAlias
40
- };
@@ -1,53 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- */
10
- // flowlint ambiguous-object-type:error
11
- 'use strict';
12
-
13
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
14
-
15
- var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
16
-
17
- var _require = require('../core/CompilerError'),
18
- createUserError = _require.createUserError;
19
-
20
- var IRValidator = require('../core/IRValidator');
21
-
22
- function visitRoot(node) {
23
- var _iterator = (0, _createForOfIteratorHelper2["default"])(node.selections),
24
- _step;
25
-
26
- try {
27
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
28
- var selection = _step.value;
29
-
30
- if (selection.kind === 'ScalarField' && selection.name === '__typename') {
31
- throw createUserError('Relay does not allow `__typename` field on Query, Mutation or Subscription', [selection.loc]);
32
- }
33
- }
34
- } catch (err) {
35
- _iterator.e(err);
36
- } finally {
37
- _iterator.f();
38
- }
39
- }
40
-
41
- function stopVisit() {}
42
-
43
- function disallowTypenameOnRoot(context) {
44
- IRValidator.validate(context, {
45
- Root: visitRoot,
46
- Fragment: stopVisit
47
- });
48
- return context;
49
- }
50
-
51
- module.exports = {
52
- transform: disallowTypenameOnRoot
53
- };
@@ -1,79 +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 IRTransformer = require('../core/IRTransformer');
18
-
19
- var SchemaUtils = require('../core/SchemaUtils');
20
-
21
- var invariant = require('invariant');
22
-
23
- var nullthrows = require('nullthrows');
24
-
25
- var _require = require('relay-runtime'),
26
- getRelayHandleKey = _require.getRelayHandleKey;
27
-
28
- function fieldHandleTransform(context) {
29
- return IRTransformer.transform(context, {
30
- LinkedField: visitField,
31
- ScalarField: visitField
32
- });
33
- }
34
- /**
35
- * @internal
36
- */
37
-
38
-
39
- function visitField(field) {
40
- var nextField = field.kind === 'LinkedField' ? this.traverse(field) : field;
41
- var handles = nextField.handles;
42
-
43
- if (!handles || !handles.length) {
44
- return nextField;
45
- } // ensure exactly one handle
46
-
47
-
48
- !(handles.length === 1) ? process.env.NODE_ENV !== "production" ? invariant(false, 'FieldHandleTransform: Expected fields to have at most one ' + '"handle" property, got `%s`.', handles.join(', ')) : invariant(false) : void 0;
49
- var context = this.getContext();
50
- var schema = context.getSchema();
51
- var alias = nextField.alias;
52
- var handle = handles[0];
53
- var name = getRelayHandleKey(handle.name, handle.key, nextField.name);
54
- var filters = handle.filters;
55
- var args = filters ? nextField.args.filter(function (arg) {
56
- return filters.indexOf(arg.name) !== -1;
57
- }) : [];
58
-
59
- if (handle.dynamicKey != null) {
60
- args.push({
61
- kind: 'Argument',
62
- loc: handle.dynamicKey.loc,
63
- name: '__dynamicKey',
64
- type: SchemaUtils.getNullableStringInput(schema),
65
- value: nullthrows(handle.dynamicKey)
66
- });
67
- }
68
-
69
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, nextField), {}, {
70
- args: args,
71
- alias: alias,
72
- name: name,
73
- handles: null
74
- });
75
- }
76
-
77
- module.exports = {
78
- transform: fieldHandleTransform
79
- };
@@ -1,29 +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
- 'use strict';
11
-
12
- var IRTransformer = require('../core/IRTransformer');
13
-
14
- var COMPILE_TIME_DIRECTIVES = new Set(['required']);
15
- /**
16
- * A transform that removes any directives that are only interpreted by the Relay compiler.
17
- */
18
-
19
- function filterDirectivesTransform(context) {
20
- return IRTransformer.transform(context, {
21
- Directive: function Directive(directive) {
22
- return COMPILE_TIME_DIRECTIVES.has(directive.name) ? null : directive;
23
- }
24
- });
25
- }
26
-
27
- module.exports = {
28
- transform: filterDirectivesTransform
29
- };