react-relay 2.0.0-rc.2 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. package/index.js +2 -2
  2. package/lib/ReactRelayContext.js +6 -3
  3. package/lib/ReactRelayFragmentContainer.js +48 -46
  4. package/lib/ReactRelayFragmentMockRenderer.js +5 -1
  5. package/lib/ReactRelayPaginationContainer.js +102 -68
  6. package/lib/ReactRelayQueryFetcher.js +54 -28
  7. package/lib/ReactRelayQueryRenderer.js +28 -20
  8. package/lib/ReactRelayRefetchContainer.js +70 -58
  9. package/lib/ReactRelayTestMocker.js +56 -43
  10. package/lib/ReactRelayTypes.js +1 -1
  11. package/lib/RelayContext.js +8 -2
  12. package/lib/assertFragmentMap.js +9 -7
  13. package/lib/buildReactRelayContainer.js +32 -23
  14. package/lib/index.js +41 -0
  15. package/lib/isRelayEnvironment.js +1 -1
  16. package/lib/isRelayVariables.js +1 -1
  17. package/lib/readContext.js +7 -4
  18. package/package.json +4 -4
  19. package/react-relay.js +2 -2
  20. package/react-relay.min.js +2 -2
  21. package/classic.js +0 -10
  22. package/compat.js +0 -10
  23. package/lib/ConcreteQuery.js +0 -10
  24. package/lib/GraphQLQueryRunner.js +0 -264
  25. package/lib/GraphQLRange.js +0 -1124
  26. package/lib/GraphQLSegment.js +0 -743
  27. package/lib/GraphQLStoreChangeEmitter.js +0 -141
  28. package/lib/GraphQLStoreQueryResolver.js +0 -288
  29. package/lib/GraphQLStoreRangeUtils.js +0 -126
  30. package/lib/QueryBuilder.js +0 -228
  31. package/lib/ReactRelayClassicExports.js +0 -29
  32. package/lib/ReactRelayCompatContainerBuilder.js +0 -175
  33. package/lib/ReactRelayCompatPublic.js +0 -28
  34. package/lib/ReactRelayContainerProfiler.js +0 -30
  35. package/lib/ReactRelayFragmentContainer-flowtest.js +0 -201
  36. package/lib/ReactRelayPaginationContainer-flowtest.js +0 -213
  37. package/lib/ReactRelayPublic.js +0 -29
  38. package/lib/ReactRelayRefetchContainer-flowtest.js +0 -191
  39. package/lib/RelayCacheProcessor.js +0 -196
  40. package/lib/RelayChangeTracker.js +0 -83
  41. package/lib/RelayClassicContainerUtils.js +0 -49
  42. package/lib/RelayClassicCore.js +0 -34
  43. package/lib/RelayClassicRecordState.js +0 -31
  44. package/lib/RelayCompatContainer.js +0 -25
  45. package/lib/RelayCompatEnvironment.js +0 -27
  46. package/lib/RelayCompatMutations.js +0 -133
  47. package/lib/RelayCompatPaginationContainer.js +0 -27
  48. package/lib/RelayCompatRefetchContainer.js +0 -27
  49. package/lib/RelayCompatTypes.js +0 -10
  50. package/lib/RelayContainer.js +0 -889
  51. package/lib/RelayContainerComparators.js +0 -75
  52. package/lib/RelayContainerProxy.js +0 -21
  53. package/lib/RelayDefaultNetworkLayer.js +0 -192
  54. package/lib/RelayEnvironment.js +0 -449
  55. package/lib/RelayEnvironmentTypes.js +0 -10
  56. package/lib/RelayFetchMode.js +0 -17
  57. package/lib/RelayFragmentPointer.js +0 -161
  58. package/lib/RelayFragmentReference.js +0 -249
  59. package/lib/RelayFragmentSpecResolver.js +0 -305
  60. package/lib/RelayGraphQLMutation.js +0 -288
  61. package/lib/RelayGraphQLTag.js +0 -42
  62. package/lib/RelayInternalTypes.js +0 -15
  63. package/lib/RelayInternals.js +0 -24
  64. package/lib/RelayMetaRoute.js +0 -35
  65. package/lib/RelayMockRenderer.js +0 -71
  66. package/lib/RelayModern-flowtest.js +0 -342
  67. package/lib/RelayModernFlowtest_badref.graphql.js +0 -10
  68. package/lib/RelayModernFlowtest_notref.graphql.js +0 -10
  69. package/lib/RelayModernFlowtest_user.graphql.js +0 -10
  70. package/lib/RelayModernFlowtest_users.graphql.js +0 -10
  71. package/lib/RelayMutation.js +0 -322
  72. package/lib/RelayMutationDebugPrinter.js +0 -47
  73. package/lib/RelayMutationQuery.js +0 -558
  74. package/lib/RelayMutationQueue.js +0 -530
  75. package/lib/RelayMutationRequest.js +0 -103
  76. package/lib/RelayMutationTracker.js +0 -113
  77. package/lib/RelayMutationTransaction.js +0 -92
  78. package/lib/RelayMutationTransactionStatus.js +0 -55
  79. package/lib/RelayNetworkDebug.js +0 -131
  80. package/lib/RelayNetworkLayer.js +0 -185
  81. package/lib/RelayNodeInterface.js +0 -104
  82. package/lib/RelayOperationDescriptor.js +0 -40
  83. package/lib/RelayOptimisticMutationUtils.js +0 -208
  84. package/lib/RelayPendingQueryTracker.js +0 -166
  85. package/lib/RelayPropTypes.js +0 -57
  86. package/lib/RelayPublic.js +0 -44
  87. package/lib/RelayQL.js +0 -128
  88. package/lib/RelayQuery.js +0 -1584
  89. package/lib/RelayQueryCaching.js +0 -33
  90. package/lib/RelayQueryConfig.js +0 -58
  91. package/lib/RelayQueryPath.js +0 -204
  92. package/lib/RelayQueryRequest.js +0 -103
  93. package/lib/RelayQueryTracker.js +0 -86
  94. package/lib/RelayQueryTransform.js +0 -91
  95. package/lib/RelayQueryVisitor.js +0 -93
  96. package/lib/RelayQueryWriter.js +0 -573
  97. package/lib/RelayReadyState.js +0 -83
  98. package/lib/RelayReadyStateRenderer.js +0 -145
  99. package/lib/RelayRecord.js +0 -75
  100. package/lib/RelayRecordStatusMap.js +0 -57
  101. package/lib/RelayRecordStore.js +0 -433
  102. package/lib/RelayRecordWriter.js +0 -601
  103. package/lib/RelayRefQueryDescriptor.js +0 -27
  104. package/lib/RelayRenderer.js +0 -268
  105. package/lib/RelayRootContainer.js +0 -125
  106. package/lib/RelayRoute.js +0 -92
  107. package/lib/RelayRouteFragment.js +0 -44
  108. package/lib/RelaySelector.js +0 -201
  109. package/lib/RelayShallowMock.js +0 -69
  110. package/lib/RelayStaticContainer.js +0 -38
  111. package/lib/RelayStore.js +0 -12
  112. package/lib/RelayStoreConstants.js +0 -20
  113. package/lib/RelayStoreData.js +0 -660
  114. package/lib/RelayTaskQueue.js +0 -189
  115. package/lib/RelayTypes.js +0 -13
  116. package/lib/RelayVariable.js +0 -32
  117. package/lib/RelayVariables.js +0 -92
  118. package/lib/buildRQL.js +0 -160
  119. package/lib/callsFromGraphQL.js +0 -74
  120. package/lib/callsToGraphQL.js +0 -34
  121. package/lib/checkRelayQueryData.js +0 -250
  122. package/lib/createRelayQuery.js +0 -17
  123. package/lib/dedent.js +0 -49
  124. package/lib/diffRelayQuery.js +0 -757
  125. package/lib/directivesToGraphQL.js +0 -39
  126. package/lib/filterRelayQuery.js +0 -29
  127. package/lib/findRelayQueryLeaves.js +0 -293
  128. package/lib/flattenRelayQuery.js +0 -121
  129. package/lib/flattenSplitRelayQueries.js +0 -44
  130. package/lib/forEachRootCallArg.js +0 -40
  131. package/lib/fromGraphQL.js +0 -48
  132. package/lib/generateClientEdgeID.js +0 -22
  133. package/lib/generateClientID.js +0 -27
  134. package/lib/generateConcreteFragmentID.js +0 -30
  135. package/lib/generateForceIndex.js +0 -24
  136. package/lib/generateRQLFieldAlias.js +0 -39
  137. package/lib/getRangeBehavior.js +0 -58
  138. package/lib/getRelayQueries.js +0 -83
  139. package/lib/intersectRelayQuery.js +0 -149
  140. package/lib/isClassicRelayContext.js +0 -20
  141. package/lib/isClassicRelayEnvironment.js +0 -20
  142. package/lib/isCompatibleRelayFragmentType.js +0 -27
  143. package/lib/isRelayContainer.js +0 -16
  144. package/lib/makeLegacyStringishComponentRef.js +0 -52
  145. package/lib/printRelayOSSQuery.js +0 -329
  146. package/lib/printRelayQuery.js +0 -26
  147. package/lib/rangeOperationToMetadataKey.js +0 -25
  148. package/lib/readRelayQueryData.js +0 -551
  149. package/lib/relayUnstableBatchedUpdates.js +0 -12
  150. package/lib/relayUnstableBatchedUpdates.native.js +0 -11
  151. package/lib/restoreRelayCacheData.js +0 -188
  152. package/lib/serializeRelayQueryCall.js +0 -42
  153. package/lib/splitDeferredRelayQueries.js +0 -298
  154. package/lib/stableStringify.js +0 -85
  155. package/lib/testEditDistance.js +0 -112
  156. package/lib/throwFailedPromise.js +0 -26
  157. package/lib/toGraphQL.js +0 -94
  158. package/lib/transformRelayQueryPayload.js +0 -145
  159. package/lib/validateMutationConfig.js +0 -117
  160. package/lib/validateRelayReadQuery.js +0 -112
  161. package/lib/writeRelayQueryPayload.js +0 -44
  162. package/lib/writeRelayUpdatePayload.js +0 -513
  163. package/react-relay-classic.js +0 -4
  164. package/react-relay-classic.min.js +0 -9
  165. package/react-relay-compat.js +0 -4
  166. package/react-relay-compat.min.js +0 -9
package/lib/RelayQuery.js DELETED
@@ -1,1584 +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 _objectSpread2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/objectSpread"));
13
-
14
- var _inheritsLoose2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/inheritsLoose"));
15
-
16
- // conditional field calls/values
17
- var IF = 'if';
18
- var UNLESS = 'unless';
19
- var TRUE = 'true';
20
- var FALSE = 'false';
21
- var SKIP = 'skip';
22
- var INCLUDE = 'include';
23
- var _nextQueryID = 0;
24
- var DEFAULT_FRAGMENT_METADATA = {
25
- isDeferred: false,
26
- isContainerFragment: false,
27
- isTypeConditional: false
28
- };
29
- var EMPTY_DIRECTIVES = [];
30
- var EMPTY_CALLS = [];
31
-
32
- if (process.env.NODE_ENV !== "production") {
33
- Object.freeze(EMPTY_CALLS);
34
- Object.freeze(EMPTY_DIRECTIVES);
35
- }
36
- /**
37
- * A type representing information about the root node:
38
- * - routeName: The name of the route
39
- * - variables: The variables in scope at the root.
40
- *
41
- * This allows route variables to passed down the tree and accessed by arbitrary
42
- * fragments.
43
- */
44
-
45
-
46
- /**
47
- * @internal
48
- *
49
- * Queries in Relay are represented as trees. Possible nodes include the root,
50
- * fields, and fragments. Fields can have children, or they can be leaf nodes.
51
- * Root and fragment nodes must always have children.
52
- *
53
- * `RelayQueryNode` provides access to information such as the field name,
54
- * generated alias, sub-fields, and call values.
55
- *
56
- * Nodes are immutable; query modification is supported via `clone`:
57
- *
58
- * ```
59
- * var next = prev.clone(prev.getChildren().filter(f => ...));
60
- * ```
61
- *
62
- * Note: Mediating access to actual query nodes is necessary so that we can
63
- * replace the current mutable GraphQL nodes with an immutable query
64
- * representation. This class *must not* mutate the underlying `concreteNode`.
65
- * Instead, use an instance variable (see `clone()`).
66
- */
67
- var RelayQueryNode =
68
- /*#__PURE__*/
69
- function () {
70
- RelayQueryNode.create = function create(concreteNode, metaRoute, variables) {
71
- var rootContext = createRootContext(metaRoute, variables);
72
- var node = createNode(concreteNode, rootContext, variables);
73
- !(node instanceof RelayQueryNode) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryNode.create(): ' + 'Expected a GraphQL fragment, mutation, or query.') : require("fbjs/lib/invariant")(false) : void 0;
74
- return node;
75
- };
76
- /**
77
- * @private
78
- *
79
- * Base class for all node types, must not be directly instantiated.
80
- */
81
-
82
-
83
- function RelayQueryNode(concreteNode, rootContext, variables) {
84
- !(this.constructor.name !== 'RelayQueryNode') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryNode: Abstract class cannot be instantiated.') : require("fbjs/lib/invariant")(false) : void 0;
85
- this.__concreteNode__ = concreteNode;
86
- this.__root__ = rootContext;
87
- this.__variables__ = variables; // lazily computed properties
88
-
89
- this.__calls__ = null;
90
- this.__children__ = null;
91
- this.__fieldMap__ = null;
92
- this.__hasDeferredDescendant__ = null;
93
- this.__hasValidatedConnectionCalls__ = null;
94
- this.__serializationKey__ = null;
95
- this.__storageKey__ = null;
96
- }
97
-
98
- var _proto = RelayQueryNode.prototype;
99
-
100
- _proto.canHaveSubselections = function canHaveSubselections() {
101
- return true;
102
- };
103
-
104
- _proto.isGenerated = function isGenerated() {
105
- return false;
106
- };
107
-
108
- _proto.isRefQueryDependency = function isRefQueryDependency() {
109
- return false;
110
- };
111
-
112
- _proto.clone = function clone(children) {
113
- if (!this.canHaveSubselections()) {
114
- // Compact new children *after* this check, for consistency.
115
- !(children.length === 0) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryNode: Cannot add children to field `%s` because it does ' + 'not support sub-selections (sub-fields).', this instanceof RelayQueryField ? this.getSchemaName() : null) : require("fbjs/lib/invariant")(false) : void 0;
116
- return this;
117
- }
118
-
119
- var prevChildren = this.getChildren();
120
- var nextChildren = cloneChildren(prevChildren, children);
121
-
122
- if (!nextChildren.length) {
123
- return null;
124
- } else if (nextChildren === prevChildren) {
125
- return this;
126
- }
127
-
128
- var clone = RelayQueryNode.create(this.__concreteNode__, require("./RelayMetaRoute").get(this.__root__.routeName), this.__variables__);
129
- clone.__children__ = nextChildren;
130
- clone.__calls__ = this.__calls__;
131
- clone.__serializationKey__ = this.__serializationKey__;
132
- clone.__storageKey__ = this.__storageKey__;
133
- return clone;
134
- };
135
-
136
- _proto.getChildren = function getChildren() {
137
- var _this = this;
138
-
139
- var children = this.__children__;
140
-
141
- if (!children) {
142
- var nextChildren = [];
143
- var concreteChildren = this.__concreteNode__.children;
144
-
145
- if (concreteChildren) {
146
- concreteChildren.forEach(function (concreteChild) {
147
- if (concreteChild == null) {
148
- return;
149
- }
150
-
151
- var nodeOrNodes = createNode(concreteChild, _this.__root__, _this.__variables__);
152
-
153
- if (Array.isArray(nodeOrNodes)) {
154
- nodeOrNodes.forEach(function (node) {
155
- if (node && node.isIncluded()) {
156
- nextChildren.push(node);
157
- }
158
- });
159
- } else if (nodeOrNodes && nodeOrNodes.isIncluded()) {
160
- nextChildren.push(nodeOrNodes);
161
- }
162
- });
163
- }
164
-
165
- this.__children__ = nextChildren;
166
- children = nextChildren;
167
- }
168
-
169
- return children;
170
- };
171
-
172
- _proto.isIncluded = function isIncluded() {
173
- // Bail out early since most nodes won't have directives
174
- if (!this.__concreteNode__.directives) {
175
- return true;
176
- }
177
-
178
- return this.getDirectives().every(function (directive) {
179
- if (directive.name === SKIP) {
180
- return !directive.args.some(function (arg) {
181
- return arg.name === IF && !!arg.value;
182
- });
183
- } else if (directive.name === INCLUDE) {
184
- return !directive.args.some(function (arg) {
185
- return arg.name === IF && !arg.value;
186
- });
187
- }
188
-
189
- return true;
190
- });
191
- };
192
-
193
- _proto.getDirectives = function getDirectives() {
194
- var _this2 = this;
195
-
196
- var concreteDirectives = this.__concreteNode__.directives;
197
-
198
- if (concreteDirectives) {
199
- return this.__concreteNode__.directives.map(function (directive) {
200
- return {
201
- args: require("./callsFromGraphQL")(directive.args, _this2.__variables__),
202
- name: directive.name
203
- };
204
- });
205
- }
206
-
207
- return EMPTY_DIRECTIVES;
208
- };
209
-
210
- _proto.getField = function getField(field) {
211
- return this.getFieldByStorageKey(field.getStorageKey());
212
- };
213
-
214
- _proto.getFieldByStorageKey = function getFieldByStorageKey(storageKey) {
215
- var fieldMap = this.__fieldMap__;
216
-
217
- if (!fieldMap) {
218
- fieldMap = {};
219
- var children = this.getChildren();
220
-
221
- for (var ii = 0; ii < children.length; ii++) {
222
- var child = children[ii];
223
-
224
- if (child instanceof RelayQueryField) {
225
- fieldMap[child.getStorageKey()] = child;
226
- }
227
- }
228
-
229
- this.__fieldMap__ = fieldMap;
230
- }
231
-
232
- return fieldMap[storageKey];
233
- };
234
-
235
- _proto.getType = function getType() {
236
- return this.__concreteNode__.type;
237
- };
238
-
239
- _proto.getRoute = function getRoute() {
240
- return require("./RelayMetaRoute").get(this.__root__.routeName);
241
- };
242
-
243
- _proto.getVariables = function getVariables() {
244
- return this.__variables__;
245
- };
246
-
247
- _proto.hasDeferredDescendant = function hasDeferredDescendant() {
248
- var hasDeferredDescendant = this.__hasDeferredDescendant__;
249
-
250
- if (hasDeferredDescendant == null) {
251
- hasDeferredDescendant = this.canHaveSubselections() && this.getChildren().some(function (child) {
252
- return child.hasDeferredDescendant();
253
- });
254
- this.__hasDeferredDescendant__ = hasDeferredDescendant;
255
- }
256
-
257
- return hasDeferredDescendant;
258
- };
259
-
260
- _proto.isAbstract = function isAbstract() {
261
- throw new Error('RelayQueryNode: Abstract function cannot be called.');
262
- };
263
-
264
- _proto.isRequisite = function isRequisite() {
265
- return false;
266
- };
267
- /**
268
- * Determine if `this` and `that` are deeply equal.
269
- */
270
-
271
-
272
- _proto.equals = function equals(that) {
273
- var thisChildren = this.getChildren();
274
- var thatChildren = that.getChildren();
275
- return thisChildren === thatChildren || thisChildren.length === thatChildren.length && thisChildren.every(function (c, ii) {
276
- return c.equals(thatChildren[ii]);
277
- });
278
- };
279
- /**
280
- * Performs a fast comparison of whether `this` and `that` represent identical
281
- * query nodes. Returns true only if the concrete nodes, routes, and variables
282
- * are all the same.
283
- *
284
- * Note that it is possible that this method can return false in cases where
285
- * `equals` would return true. This can happen when the concrete nodes are
286
- * different but structurally identical, or when the route/variables are
287
- * different but do not have an effect on the structure of the query.
288
- */
289
-
290
-
291
- _proto.isEquivalent = function isEquivalent(that) {
292
- return this.__concreteNode__ === that.__concreteNode__ && this.__root__.routeName === that.__root__.routeName && require("fbjs/lib/shallowEqual")(this.__root__.variables, that.__root__.variables) && require("fbjs/lib/shallowEqual")(this.__variables__, that.__variables__);
293
- };
294
-
295
- _proto.createNode = function createNode(concreteNode) {
296
- return RelayQueryNode.create(concreteNode, require("./RelayMetaRoute").get(this.__root__.routeName), this.__variables__);
297
- };
298
-
299
- _proto.getConcreteQueryNode = function getConcreteQueryNode() {
300
- return this.__concreteNode__;
301
- };
302
-
303
- return RelayQueryNode;
304
- }();
305
- /**
306
- * @internal
307
- *
308
- * Wraps access to query root nodes.
309
- */
310
-
311
-
312
- var RelayQueryRoot =
313
- /*#__PURE__*/
314
- function (_RelayQueryNode) {
315
- (0, _inheritsLoose2["default"])(RelayQueryRoot, _RelayQueryNode);
316
-
317
- /**
318
- * Helper to construct a new root query with the given attributes and 'empty'
319
- * route/variables.
320
- */
321
- RelayQueryRoot.build = function build(name, fieldName, value, children, metadata, type, routeName) {
322
- var nextChildren = children ? children.filter(function (child) {
323
- return !!child;
324
- }) : [];
325
-
326
- var batchCallVariable = require("./QueryBuilder").getBatchCallVariable(value);
327
-
328
- var identifyingArgValue;
329
-
330
- if (batchCallVariable) {
331
- identifyingArgValue = batchCallVariable;
332
- } else if (Array.isArray(value)) {
333
- identifyingArgValue = value.map(require("./QueryBuilder").createCallValue);
334
- } else if (value) {
335
- identifyingArgValue = require("./QueryBuilder").createCallValue(value);
336
- }
337
-
338
- var concreteRoot = require("./QueryBuilder").createQuery({
339
- fieldName: fieldName,
340
- identifyingArgValue: identifyingArgValue,
341
- metadata: metadata,
342
- name: name,
343
- type: type
344
- });
345
-
346
- var variables = {};
347
-
348
- var metaRoute = require("./RelayMetaRoute").get(routeName || '$RelayQuery');
349
-
350
- var rootContext = createRootContext(metaRoute, variables);
351
- var root = new RelayQueryRoot(concreteRoot, rootContext, variables);
352
- root.__children__ = nextChildren;
353
- return root;
354
- };
355
-
356
- RelayQueryRoot.create = function create(concreteNode, metaRoute, variables) {
357
- var query = require("./QueryBuilder").getQuery(concreteNode);
358
-
359
- !query ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryRoot.create(): Expected a GraphQL `query { ... }`, got: %s', concreteNode) : require("fbjs/lib/invariant")(false) : void 0;
360
- var rootContext = createRootContext(metaRoute, variables);
361
- return new RelayQueryRoot(query, rootContext, variables);
362
- };
363
-
364
- function RelayQueryRoot(concreteNode, rootContext, variables) {
365
- var _this3;
366
-
367
- _this3 = _RelayQueryNode.call(this, concreteNode, rootContext, variables) || this;
368
- _this3.__batchCall__ = undefined;
369
- _this3.__id__ = undefined;
370
- _this3.__identifyingArg__ = undefined;
371
- _this3.__storageKey__ = undefined; // Ensure IDs are generated in the order that queries are created
372
-
373
- _this3.getID();
374
-
375
- return _this3;
376
- }
377
-
378
- var _proto2 = RelayQueryRoot.prototype;
379
-
380
- _proto2.canHaveSubselections = function canHaveSubselections() {
381
- return true;
382
- };
383
-
384
- _proto2.getName = function getName() {
385
- var name = this.__concreteNode__.name;
386
-
387
- if (!name) {
388
- name = this.getID();
389
- this.__concreteNode__.name = name;
390
- }
391
-
392
- return name;
393
- };
394
-
395
- _proto2.getID = function getID() {
396
- var id = this.__id__;
397
-
398
- if (id == null) {
399
- id = 'q' + _nextQueryID++;
400
- this.__id__ = id;
401
- }
402
-
403
- return id;
404
- };
405
-
406
- _proto2.getBatchCall = function getBatchCall() {
407
- var batchCall = this.__batchCall__;
408
-
409
- if (batchCall === undefined) {
410
- var concreteCalls = this.__concreteNode__.calls;
411
-
412
- if (concreteCalls) {
413
- var callArg = concreteCalls[0] && concreteCalls[0].value;
414
-
415
- if (callArg != null && !Array.isArray(callArg) && callArg.kind === 'BatchCallVariable') {
416
- batchCall = {
417
- refParamName: 'ref_' + callArg.sourceQueryID,
418
- sourceQueryID: callArg.sourceQueryID,
419
- sourceQueryPath: callArg.jsonPath
420
- };
421
- }
422
- }
423
-
424
- batchCall = batchCall || null;
425
- this.__batchCall__ = batchCall;
426
- }
427
-
428
- return batchCall;
429
- };
430
-
431
- _proto2.getCallsWithValues = function getCallsWithValues() {
432
- var calls = this.__calls__;
433
-
434
- if (!calls) {
435
- var concreteCalls = this.__concreteNode__.calls;
436
-
437
- if (concreteCalls) {
438
- calls = require("./callsFromGraphQL")(concreteCalls, this.__variables__);
439
- } else {
440
- calls = EMPTY_CALLS;
441
- }
442
-
443
- this.__calls__ = calls;
444
- }
445
-
446
- return calls;
447
- };
448
-
449
- _proto2.getFieldName = function getFieldName() {
450
- return this.__concreteNode__.fieldName;
451
- };
452
-
453
- _proto2.getIdentifyingArg = function getIdentifyingArg() {
454
- var identifyingArg = this.__identifyingArg__;
455
-
456
- if (!identifyingArg) {
457
- var metadata = this.__concreteNode__.metadata;
458
- var identifyingArgName = metadata.identifyingArgName;
459
-
460
- if (identifyingArgName != null) {
461
- identifyingArg = this.getCallsWithValues().find(function (c) {
462
- return c.name === identifyingArgName;
463
- });
464
-
465
- if (identifyingArg && metadata.identifyingArgType != null) {
466
- identifyingArg.type = metadata.identifyingArgType;
467
- }
468
-
469
- this.__identifyingArg__ = identifyingArg;
470
- }
471
- }
472
-
473
- return identifyingArg;
474
- };
475
-
476
- _proto2.getStorageKey = function getStorageKey() {
477
- var storageKey = this.__storageKey__;
478
-
479
- if (!storageKey) {
480
- var args = this.getCallsWithValues();
481
- var identifyingArg = this.getIdentifyingArg();
482
-
483
- if (identifyingArg) {
484
- args = args.filter(function (arg) {
485
- return arg !== identifyingArg;
486
- });
487
- }
488
-
489
- var field = RelayQueryField.build({
490
- fieldName: this.getFieldName(),
491
- calls: args,
492
- type: this.getType()
493
- });
494
- storageKey = field.getStorageKey();
495
- this.__storageKey__ = storageKey;
496
- }
497
-
498
- return storageKey;
499
- };
500
-
501
- _proto2.hasDeferredDescendant = function hasDeferredDescendant() {
502
- return this.isDeferred() || _RelayQueryNode.prototype.hasDeferredDescendant.call(this);
503
- };
504
-
505
- _proto2.isAbstract = function isAbstract() {
506
- return !!this.__concreteNode__.metadata.isAbstract;
507
- };
508
-
509
- _proto2.isDeferred = function isDeferred() {
510
- return !!this.__concreteNode__.isDeferred;
511
- };
512
-
513
- _proto2.isPlural = function isPlural() {
514
- return !!this.__concreteNode__.metadata.isPlural;
515
- };
516
-
517
- _proto2.cloneWithRoute = function cloneWithRoute(children, metaRoute) {
518
- if (this.__root__.routeName === metaRoute.name) {
519
- return this.clone(children);
520
- }
521
-
522
- var clone = RelayQueryNode.create((0, _objectSpread2["default"])({}, this.__concreteNode__, {
523
- name: metaRoute.name
524
- }), metaRoute, this.__variables__);
525
- clone.__children__ = children;
526
- return clone;
527
- };
528
-
529
- _proto2.equals = function equals(that) {
530
- if (this === that) {
531
- return true;
532
- }
533
-
534
- if (!(that instanceof RelayQueryRoot)) {
535
- return false;
536
- }
537
-
538
- if (!require("fbjs/lib/areEqual")(this.getBatchCall(), that.getBatchCall())) {
539
- return false;
540
- }
541
-
542
- if (this.getFieldName() !== that.getFieldName() || !areCallValuesEqual(this.getCallsWithValues(), that.getCallsWithValues())) {
543
- return false;
544
- }
545
-
546
- return _RelayQueryNode.prototype.equals.call(this, that);
547
- };
548
-
549
- return RelayQueryRoot;
550
- }(RelayQueryNode);
551
- /**
552
- * @internal
553
- *
554
- * Wraps access to OSS GraphQL query nodes created with
555
- *
556
- * graphql`query ...`
557
- *
558
- * Unlike RelayQueryRoot (which represents the semantics of classic GraphQL
559
- * queries), this class supports multiple, arbitrary root fields within a single
560
- * query. Fields may have arbitrary numbers of arguments, return connections,
561
- * have aliases, etc.
562
- */
563
-
564
-
565
- var RelayOSSQuery =
566
- /*#__PURE__*/
567
- function (_RelayQueryNode2) {
568
- (0, _inheritsLoose2["default"])(RelayOSSQuery, _RelayQueryNode2);
569
-
570
- RelayOSSQuery.create = function create(concreteNode, metaRoute, variables) {
571
- var operation = require("./QueryBuilder").getOperationDefinition(concreteNode);
572
-
573
- !operation ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryRoot.create(): Expected a value created with graphql`query { ... }` ' + '(using the `graphql` tag), got: %s', concreteNode) : require("fbjs/lib/invariant")(false) : void 0;
574
- var rootContext = createRootContext(metaRoute, variables);
575
- return new RelayOSSQuery(operation, rootContext, variables);
576
- };
577
-
578
- function RelayOSSQuery(concreteNode, rootContext, variables) {
579
- var _this4;
580
-
581
- !(concreteNode && concreteNode.operation === 'query') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryRoot.create(): Expected a value created with graphql`query { ... }` ' + '(using the `graphql` tag), got: %s', concreteNode) : require("fbjs/lib/invariant")(false) : void 0;
582
- _this4 = _RelayQueryNode2.call(this, concreteNode.node, rootContext, variables) || this;
583
- _this4.__id__ = undefined; // Ensure IDs are generated in the order that queries are created
584
-
585
- _this4.getID();
586
-
587
- return _this4;
588
- }
589
-
590
- var _proto3 = RelayOSSQuery.prototype;
591
-
592
- _proto3.canHaveSubselections = function canHaveSubselections() {
593
- return true;
594
- };
595
-
596
- _proto3.isDeferred = function isDeferred() {
597
- return false;
598
- };
599
-
600
- _proto3.getName = function getName() {
601
- var name = this.__concreteNode__.name;
602
-
603
- if (!name) {
604
- name = this.getID();
605
- this.__concreteNode__.name = name;
606
- }
607
-
608
- return name;
609
- };
610
-
611
- _proto3.getID = function getID() {
612
- var id = this.__id__;
613
-
614
- if (id == null) {
615
- id = 'q' + _nextQueryID++;
616
- this.__id__ = id;
617
- }
618
-
619
- return id;
620
- };
621
-
622
- _proto3.equals = function equals(that) {
623
- if (this === that) {
624
- return true;
625
- }
626
-
627
- if (!(that instanceof RelayOSSQuery)) {
628
- return false;
629
- }
630
-
631
- return _RelayQueryNode2.prototype.equals.call(this, that);
632
- };
633
-
634
- return RelayOSSQuery;
635
- }(RelayQueryNode);
636
- /**
637
- * @internal
638
- *
639
- * Abstract base class for mutations and subscriptions.
640
- */
641
-
642
-
643
- var RelayQueryOperation =
644
- /*#__PURE__*/
645
- function (_RelayQueryNode3) {
646
- (0, _inheritsLoose2["default"])(RelayQueryOperation, _RelayQueryNode3);
647
-
648
- function RelayQueryOperation(concreteNode, rootContext, variables) {
649
- var _this5;
650
-
651
- _this5 = _RelayQueryNode3.call(this, concreteNode, rootContext, variables) || this;
652
- !(_this5.constructor.name !== 'RelayQueryOperation') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryOperation: Abstract class cannot be instantiated.') : require("fbjs/lib/invariant")(false) : void 0;
653
- return _this5;
654
- }
655
-
656
- var _proto4 = RelayQueryOperation.prototype;
657
-
658
- _proto4.canHaveSubselections = function canHaveSubselections() {
659
- return true;
660
- };
661
-
662
- _proto4.getName = function getName() {
663
- return this.__concreteNode__.name;
664
- };
665
-
666
- _proto4.getResponseType = function getResponseType() {
667
- return this.__concreteNode__.responseType;
668
- };
669
-
670
- _proto4.getType = function getType() {
671
- return this.getResponseType();
672
- };
673
-
674
- _proto4.getInputType = function getInputType() {
675
- var inputType = this.__concreteNode__.metadata.inputType;
676
- !inputType ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQuery: Expected operation `%s` to be annotated with the type of ' + 'its argument. Either the babel transform was configured incorrectly, ' + 'or the schema failed to define an argument for this mutation.', this.getCall().name) : require("fbjs/lib/invariant")(false) : void 0;
677
- return inputType;
678
- };
679
-
680
- _proto4.getCall = function getCall() {
681
- var calls = this.__calls__;
682
-
683
- if (!calls) {
684
- var concreteCalls = this.__concreteNode__.calls;
685
-
686
- if (concreteCalls) {
687
- calls = require("./callsFromGraphQL")(concreteCalls, this.__variables__);
688
- } else {
689
- calls = EMPTY_CALLS;
690
- }
691
-
692
- this.__calls__ = calls;
693
- }
694
-
695
- return calls[0];
696
- };
697
-
698
- _proto4.getCallVariableName = function getCallVariableName() {
699
- if (!this.__callVariableName__) {
700
- var concreteCalls = this.__concreteNode__.calls;
701
-
702
- var callVariable = concreteCalls && require("./QueryBuilder").getCallVariable(concreteCalls[0].value);
703
-
704
- !callVariable ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQuery: Expected mutation to have a single argument.') : require("fbjs/lib/invariant")(false) : void 0;
705
- this.__callVariableName__ = callVariable.callVariableName;
706
- }
707
-
708
- return this.__callVariableName__;
709
- };
710
- /**
711
- * Mutations and subscriptions must have a concrete type due to the need for
712
- * requisite top-level fields.
713
- */
714
-
715
-
716
- _proto4.isAbstract = function isAbstract() {
717
- return false;
718
- };
719
-
720
- return RelayQueryOperation;
721
- }(RelayQueryNode);
722
- /**
723
- * @internal
724
- *
725
- * Represents a GraphQL mutation.
726
- */
727
-
728
-
729
- var RelayQueryMutation =
730
- /*#__PURE__*/
731
- function (_RelayQueryOperation) {
732
- (0, _inheritsLoose2["default"])(RelayQueryMutation, _RelayQueryOperation);
733
-
734
- function RelayQueryMutation() {
735
- return _RelayQueryOperation.apply(this, arguments) || this;
736
- }
737
-
738
- /**
739
- * Helper to construct a new mutation with the given attributes and 'empty'
740
- * route/variables.
741
- */
742
- RelayQueryMutation.build = function build(name, responseType, callName, callValue, children, metadata, routeName) {
743
- var nextChildren = children ? children.filter(function (child) {
744
- return !!child;
745
- }) : [];
746
-
747
- var concreteMutation = require("./QueryBuilder").createMutation({
748
- calls: [require("./QueryBuilder").createCall(callName, require("./QueryBuilder").createCallVariable('input'))],
749
- metadata: metadata,
750
- name: name,
751
- responseType: responseType
752
- });
753
-
754
- var variables = {
755
- input: callValue || ''
756
- };
757
-
758
- var metaRoute = require("./RelayMetaRoute").get(routeName || '$RelayQuery');
759
-
760
- var rootContext = createRootContext(metaRoute, variables);
761
- var mutation = new RelayQueryMutation(concreteMutation, rootContext, variables);
762
- mutation.__children__ = nextChildren;
763
- return mutation;
764
- };
765
-
766
- var _proto5 = RelayQueryMutation.prototype;
767
-
768
- _proto5.equals = function equals(that) {
769
- if (this === that) {
770
- return true;
771
- }
772
-
773
- if (!(that instanceof RelayQueryMutation)) {
774
- return false;
775
- }
776
-
777
- if (!require("fbjs/lib/areEqual")(this.getResponseType(), that.getResponseType())) {
778
- return false;
779
- }
780
-
781
- if (!require("fbjs/lib/areEqual")(this.getCall(), that.getCall())) {
782
- return false;
783
- }
784
-
785
- return _RelayQueryOperation.prototype.equals.call(this, that);
786
- };
787
-
788
- return RelayQueryMutation;
789
- }(RelayQueryOperation);
790
- /**
791
- * @internal
792
- *
793
- * Represents a GraphQL subscription.
794
- */
795
-
796
-
797
- var RelayQuerySubscription =
798
- /*#__PURE__*/
799
- function (_RelayQueryOperation2) {
800
- (0, _inheritsLoose2["default"])(RelayQuerySubscription, _RelayQueryOperation2);
801
-
802
- function RelayQuerySubscription() {
803
- return _RelayQueryOperation2.apply(this, arguments) || this;
804
- }
805
-
806
- RelayQuerySubscription.create = function create(concreteNode, metaRoute, variables) {
807
- var subscription = require("./QueryBuilder").getSubscription(concreteNode);
808
-
809
- !subscription ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQuerySubscription.create(): ' + 'Expected a GraphQL `subscription { ... }`, got: %s', concreteNode) : require("fbjs/lib/invariant")(false) : void 0;
810
- var rootContext = createRootContext(metaRoute, variables);
811
- return new RelayQuerySubscription(concreteNode, rootContext, variables);
812
- };
813
-
814
- var _proto6 = RelayQuerySubscription.prototype;
815
-
816
- _proto6.getPublishedPayloadType = function getPublishedPayloadType() {
817
- return this.getResponseType();
818
- };
819
-
820
- _proto6.equals = function equals(that) {
821
- if (this === that) {
822
- return true;
823
- }
824
-
825
- if (!(that instanceof RelayQuerySubscription)) {
826
- return false;
827
- }
828
-
829
- if (!require("fbjs/lib/areEqual")(this.getPublishedPayloadType(), that.getPublishedPayloadType())) {
830
- return false;
831
- }
832
-
833
- if (!require("fbjs/lib/areEqual")(this.getCall(), that.getCall())) {
834
- return false;
835
- }
836
-
837
- return _RelayQueryOperation2.prototype.equals.call(this, that);
838
- };
839
-
840
- return RelayQuerySubscription;
841
- }(RelayQueryOperation);
842
- /**
843
- * @internal
844
- *
845
- * Wraps access to query fragments.
846
- */
847
-
848
-
849
- var RelayQueryFragment =
850
- /*#__PURE__*/
851
- function (_RelayQueryNode4) {
852
- (0, _inheritsLoose2["default"])(RelayQueryFragment, _RelayQueryNode4);
853
-
854
- /**
855
- * Helper to construct a new fragment with the given attributes and 'empty'
856
- * route/variables.
857
- */
858
- RelayQueryFragment.build = function build(name, type, children, metadata, routeName) {
859
- var nextChildren = children ? children.filter(function (child) {
860
- return !!child;
861
- }) : [];
862
-
863
- var concreteFragment = require("./QueryBuilder").createFragment({
864
- name: name,
865
- type: type,
866
- metadata: metadata
867
- });
868
-
869
- var variables = {};
870
-
871
- var metaRoute = require("./RelayMetaRoute").get(routeName || '$RelayQuery');
872
-
873
- var rootContext = createRootContext(metaRoute, variables);
874
- var fragment = new RelayQueryFragment(concreteFragment, rootContext, variables, {
875
- isDeferred: !!(metadata && metadata.isDeferred),
876
- isContainerFragment: !!(metadata && metadata.isContainerFragment),
877
- isTypeConditional: !!(metadata && metadata.isTypeConditional)
878
- });
879
- fragment.__children__ = nextChildren;
880
- return fragment;
881
- };
882
-
883
- RelayQueryFragment.create = function create(concreteNode, metaRoute, variables, metadata) {
884
- var fragment = require("./QueryBuilder").getFragment(concreteNode);
885
-
886
- !fragment ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryFragment.create(): ' + 'Expected a GraphQL `fragment { ... }`, got: %s', concreteNode) : require("fbjs/lib/invariant")(false) : void 0;
887
- var rootContext = createRootContext(metaRoute, variables);
888
- return createMemoizedFragment(fragment, rootContext, variables, metadata || DEFAULT_FRAGMENT_METADATA);
889
- };
890
-
891
- function RelayQueryFragment(concreteNode, rootContext, variables, metadata) {
892
- var _this6;
893
-
894
- _this6 = _RelayQueryNode4.call(this, concreteNode, rootContext, variables) || this;
895
- _this6.__compositeHash__ = null;
896
- _this6.__metadata__ = metadata || DEFAULT_FRAGMENT_METADATA;
897
- _this6.__sourceCompositeHash__ = null;
898
- return _this6;
899
- }
900
-
901
- var _proto7 = RelayQueryFragment.prototype;
902
-
903
- _proto7.canHaveSubselections = function canHaveSubselections() {
904
- return true;
905
- };
906
-
907
- _proto7.getDebugName = function getDebugName() {
908
- return this.__concreteNode__.name;
909
- };
910
- /**
911
- * The "concrete fragment id" uniquely identifies a Relay.QL`fragment ...`
912
- * within the source code of an application and will remain the same across
913
- * runs of a particular version of an application.
914
- */
915
-
916
-
917
- _proto7.getConcreteFragmentID = function getConcreteFragmentID() {
918
- return this.__concreteNode__.id;
919
- };
920
- /**
921
- * The "composite hash" is similar to the concrete instance hash, but it also
922
- * differentiates between varying variable values or route names.
923
- *
924
- * The composite hash is used to:
925
- * - Avoid printing the same fragment twice, in order to reduce upload size.
926
- * - Remember which deferred fragment/data pairs have been fetched.
927
- */
928
-
929
-
930
- _proto7.getCompositeHash = function getCompositeHash() {
931
- var compositeHash = this.__compositeHash__;
932
-
933
- if (!compositeHash) {
934
- compositeHash = require("./generateRQLFieldAlias")(this.getConcreteFragmentID() + '.' + this.__root__.routeName + '.' + require("./stableStringify")(this.__variables__));
935
- this.__compositeHash__ = compositeHash;
936
- }
937
-
938
- return compositeHash;
939
- };
940
-
941
- _proto7.getSourceCompositeHash = function getSourceCompositeHash() {
942
- return this.__sourceCompositeHash__;
943
- };
944
-
945
- _proto7.isAbstract = function isAbstract() {
946
- return !!this.__concreteNode__.metadata.isAbstract;
947
- };
948
-
949
- _proto7.isDeferred = function isDeferred() {
950
- return this.__metadata__.isDeferred;
951
- };
952
-
953
- _proto7.isPattern = function isPattern() {
954
- return !!this.__concreteNode__.metadata.pattern;
955
- };
956
-
957
- _proto7.isPlural = function isPlural() {
958
- var metadata = this.__concreteNode__.metadata;
959
- return Boolean(
960
- /* FB Printer */
961
- metadata.isPlural ||
962
- /* OSS Printer from `@relay` */
963
- metadata.plural);
964
- };
965
-
966
- _proto7.isTrackingEnabled = function isTrackingEnabled() {
967
- var metadata = this.__concreteNode__.metadata;
968
- return !!metadata.isTrackingEnabled;
969
- };
970
-
971
- _proto7.cloneAsPlainFragment = function cloneAsPlainFragment() {
972
- return createMemoizedFragment(this.__concreteNode__, this.__root__, this.__variables__, DEFAULT_FRAGMENT_METADATA);
973
- };
974
-
975
- _proto7.isContainerFragment = function isContainerFragment() {
976
- return this.__metadata__.isContainerFragment;
977
- };
978
-
979
- _proto7.isTypeConditional = function isTypeConditional() {
980
- return this.__metadata__.isTypeConditional;
981
- };
982
-
983
- _proto7.hasDeferredDescendant = function hasDeferredDescendant() {
984
- return this.isDeferred() || _RelayQueryNode4.prototype.hasDeferredDescendant.call(this);
985
- };
986
-
987
- _proto7.clone = function clone(children) {
988
- var clone = _RelayQueryNode4.prototype.clone.call(this, children);
989
-
990
- if (clone !== this && clone instanceof RelayQueryFragment) {
991
- clone.__concreteNode__ = (0, _objectSpread2["default"])({}, clone.__concreteNode__, {
992
- id: require("./generateConcreteFragmentID")()
993
- });
994
- clone.__metadata__ = (0, _objectSpread2["default"])({}, this.__metadata__); // The container checks on the status of a deferred fragment using its
995
- // composite hash. We need to cache this hash in this cloned fragment
996
- // so it can be updated in the store with the correct hash when fetched.
997
-
998
- clone.__sourceCompositeHash__ = this.getCompositeHash();
999
- }
1000
-
1001
- return clone;
1002
- };
1003
-
1004
- _proto7.equals = function equals(that) {
1005
- if (this === that) {
1006
- return true;
1007
- }
1008
-
1009
- if (!(that instanceof RelayQueryFragment)) {
1010
- return false;
1011
- }
1012
-
1013
- if (this.getType() !== that.getType()) {
1014
- return false;
1015
- }
1016
-
1017
- return _RelayQueryNode4.prototype.equals.call(this, that);
1018
- };
1019
-
1020
- return RelayQueryFragment;
1021
- }(RelayQueryNode);
1022
- /**
1023
- * @internal
1024
- *
1025
- * Wraps access to query fields.
1026
- */
1027
-
1028
-
1029
- var RelayQueryField =
1030
- /*#__PURE__*/
1031
- function (_RelayQueryNode5) {
1032
- (0, _inheritsLoose2["default"])(RelayQueryField, _RelayQueryNode5);
1033
-
1034
- RelayQueryField.create = function create(concreteNode, metaRoute, variables) {
1035
- var field = require("./QueryBuilder").getField(concreteNode);
1036
-
1037
- !field ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryField.create(): Expected a GraphQL field, got: %s', concreteNode) : require("fbjs/lib/invariant")(false) : void 0;
1038
- var rootContext = createRootContext(metaRoute, variables);
1039
- return new RelayQueryField(field, rootContext, variables);
1040
- };
1041
- /**
1042
- * Helper to construct a new field with the given attributes and 'empty'
1043
- * route/variables.
1044
- */
1045
-
1046
-
1047
- RelayQueryField.build = function build(_ref) {
1048
- var alias = _ref.alias,
1049
- directives = _ref.directives,
1050
- calls = _ref.calls,
1051
- children = _ref.children,
1052
- fieldName = _ref.fieldName,
1053
- metadata = _ref.metadata,
1054
- routeName = _ref.routeName,
1055
- type = _ref.type;
1056
- var nextChildren = children ? children.filter(function (child) {
1057
- return !!child;
1058
- }) : [];
1059
-
1060
- var concreteField = require("./QueryBuilder").createField({
1061
- alias: alias,
1062
- calls: calls ? require("./callsToGraphQL")(calls) : null,
1063
- directives: directives ? require("./directivesToGraphQL")(directives) : null,
1064
- fieldName: fieldName,
1065
- metadata: metadata,
1066
- type: type
1067
- });
1068
-
1069
- var variables = {};
1070
-
1071
- var metaRoute = require("./RelayMetaRoute").get(routeName || '$RelayQuery');
1072
-
1073
- var rootContext = createRootContext(metaRoute, variables);
1074
- var field = new RelayQueryField(concreteField, rootContext, variables);
1075
- field.__children__ = nextChildren;
1076
- return field;
1077
- };
1078
-
1079
- function RelayQueryField(concreteNode, rootContext, variables) {
1080
- var _this7;
1081
-
1082
- _this7 = _RelayQueryNode5.call(this, concreteNode, rootContext, variables) || this;
1083
- _this7.__debugName__ = undefined;
1084
- _this7.__isRefQueryDependency__ = false;
1085
- _this7.__rangeBehaviorCalls__ = undefined;
1086
- _this7.__shallowHash__ = undefined;
1087
- return _this7;
1088
- }
1089
-
1090
- var _proto8 = RelayQueryField.prototype;
1091
-
1092
- _proto8.canHaveSubselections = function canHaveSubselections() {
1093
- return !!this.__concreteNode__.metadata.canHaveSubselections;
1094
- };
1095
-
1096
- _proto8.isAbstract = function isAbstract() {
1097
- return !!this.__concreteNode__.metadata.isAbstract;
1098
- };
1099
-
1100
- _proto8.isFindable = function isFindable() {
1101
- return !!this.__concreteNode__.metadata.isFindable;
1102
- };
1103
-
1104
- _proto8.isGenerated = function isGenerated() {
1105
- return !!this.__concreteNode__.metadata.isGenerated;
1106
- };
1107
-
1108
- _proto8.isConnection = function isConnection() {
1109
- return !!this.__concreteNode__.metadata.isConnection;
1110
- };
1111
-
1112
- _proto8.isConnectionWithoutNodeID = function isConnectionWithoutNodeID() {
1113
- return !!this.__concreteNode__.metadata.isConnectionWithoutNodeID;
1114
- };
1115
-
1116
- _proto8.isPlural = function isPlural() {
1117
- return !!this.__concreteNode__.metadata.isPlural;
1118
- };
1119
-
1120
- _proto8.isRefQueryDependency = function isRefQueryDependency() {
1121
- return this.__isRefQueryDependency__;
1122
- };
1123
-
1124
- _proto8.isRequisite = function isRequisite() {
1125
- return !!this.__concreteNode__.metadata.isRequisite;
1126
- };
1127
-
1128
- _proto8.getDebugName = function getDebugName() {
1129
- var _this8 = this;
1130
-
1131
- var debugName = this.__debugName__;
1132
-
1133
- if (!debugName) {
1134
- debugName = this.getSchemaName();
1135
- var printedCoreArgs;
1136
- this.getCallsWithValues().forEach(function (arg) {
1137
- if (_this8._isCoreArg(arg)) {
1138
- printedCoreArgs = printedCoreArgs || [];
1139
- printedCoreArgs.push(require("./serializeRelayQueryCall")(arg));
1140
- }
1141
- });
1142
-
1143
- if (printedCoreArgs) {
1144
- debugName += printedCoreArgs.sort().join('');
1145
- }
1146
-
1147
- this.__debugName__ = debugName;
1148
- }
1149
-
1150
- return debugName;
1151
- };
1152
- /**
1153
- * The canonical name for the referenced field in the schema.
1154
- */
1155
-
1156
-
1157
- _proto8.getSchemaName = function getSchemaName() {
1158
- return this.__concreteNode__.fieldName;
1159
- };
1160
- /**
1161
- * An Array of Calls to be used with rangeBehavior config functions.
1162
- *
1163
- * Non-core arguments (like connection and identifying arguments) are dropped.
1164
- * `field(first: 10, foo: "bar", baz: "bat")` => `'baz(bat).foo(bar)'`
1165
- * `username(name: "steve")` => `''`
1166
- */
1167
-
1168
-
1169
- _proto8.getRangeBehaviorCalls = function getRangeBehaviorCalls() {
1170
- var _this9 = this;
1171
-
1172
- !this.isConnection() ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryField: Range behavior keys are associated exclusively with ' + 'connection fields. `getRangeBehaviorCalls()` was called on the ' + 'non-connection field `%s`.', this.getSchemaName()) : require("fbjs/lib/invariant")(false) : void 0;
1173
- var rangeBehaviorCalls = this.__rangeBehaviorCalls__;
1174
-
1175
- if (!rangeBehaviorCalls) {
1176
- rangeBehaviorCalls = this.getCallsWithValues().filter(function (arg) {
1177
- return _this9._isCoreArg(arg);
1178
- });
1179
- this.__rangeBehaviorCalls__ = rangeBehaviorCalls;
1180
- }
1181
-
1182
- return rangeBehaviorCalls;
1183
- };
1184
- /**
1185
- * The name for the field when serializing the query or interpreting query
1186
- * responses from the server. The serialization key is derived from
1187
- * all calls/values and hashed for compactness.
1188
- *
1189
- * Given the GraphQL
1190
- * `field(first: 10, foo: "bar", baz: "bat")`, or
1191
- * `field(baz: "bat", foo: "bar", first: 10)`
1192
- *
1193
- * ...the following serialization key will be produced:
1194
- * `generateRQLFieldAlias('field.bar(bat).first(10).foo(bar)')`
1195
- */
1196
-
1197
-
1198
- _proto8.getSerializationKey = function getSerializationKey() {
1199
- var serializationKey = this.__serializationKey__;
1200
-
1201
- if (!serializationKey) {
1202
- var _key = this.getSchemaName();
1203
-
1204
- var calls = this.getCallsWithValues();
1205
-
1206
- if (calls.length) {
1207
- var alias = this.__concreteNode__.alias;
1208
-
1209
- if (alias != null) {
1210
- _key += '.' + alias;
1211
- }
1212
-
1213
- _key += calls.map(require("./serializeRelayQueryCall")).sort().join('');
1214
- }
1215
-
1216
- serializationKey = require("./generateRQLFieldAlias")(_key);
1217
- this.__serializationKey__ = serializationKey;
1218
- }
1219
-
1220
- return serializationKey;
1221
- };
1222
- /**
1223
- * Returns a hash of the field name and all argument values.
1224
- */
1225
-
1226
-
1227
- _proto8.getShallowHash = function getShallowHash() {
1228
- var shallowHash = this.__shallowHash__;
1229
-
1230
- if (!shallowHash) {
1231
- this.__shallowHash__ = shallowHash = this.getSchemaName() + serializeCalls(this.getCallsWithValues());
1232
- }
1233
-
1234
- return shallowHash;
1235
- };
1236
- /**
1237
- * The name which Relay internals can use to reference this field, without
1238
- * collisions.
1239
- *
1240
- * Given the GraphQL
1241
- * `field(first: 10, foo: "bar", baz: "bat")`, or
1242
- * `field(baz: "bat", foo: "bar", first: 10)`
1243
- *
1244
- * ...the following storage key will be produced:
1245
- * `'field{bar:"bat",foo:"bar"}'`
1246
- */
1247
-
1248
-
1249
- _proto8.getStorageKey = function getStorageKey() {
1250
- var _this10 = this;
1251
-
1252
- var storageKey = this.__storageKey__;
1253
-
1254
- if (!storageKey) {
1255
- this.__storageKey__ = storageKey = this.getSchemaName() + serializeCalls(this.getCallsWithValues().filter(function (call) {
1256
- return _this10._isCoreArg(call);
1257
- }));
1258
- }
1259
-
1260
- return storageKey;
1261
- };
1262
- /**
1263
- * The name by which this field's results should be made available to the
1264
- * application.
1265
- */
1266
-
1267
-
1268
- _proto8.getApplicationName = function getApplicationName() {
1269
- var concreteNode = this.__concreteNode__;
1270
- return concreteNode.alias || concreteNode.fieldName;
1271
- };
1272
-
1273
- _proto8.getInferredRootCallName = function getInferredRootCallName() {
1274
- return this.__concreteNode__.metadata.inferredRootCallName;
1275
- };
1276
-
1277
- _proto8.getInferredPrimaryKey = function getInferredPrimaryKey() {
1278
- return this.__concreteNode__.metadata.inferredPrimaryKey;
1279
- };
1280
-
1281
- _proto8.getCallsWithValues = function getCallsWithValues() {
1282
- var calls = this.__calls__;
1283
-
1284
- if (!calls) {
1285
- var concreteCalls = this.__concreteNode__.calls;
1286
-
1287
- if (concreteCalls) {
1288
- calls = require("./callsFromGraphQL")(concreteCalls, this.__variables__);
1289
- } else {
1290
- calls = EMPTY_CALLS;
1291
- }
1292
-
1293
- this.__calls__ = calls;
1294
- }
1295
-
1296
- return calls;
1297
- };
1298
-
1299
- _proto8.getCallType = function getCallType(callName) {
1300
- var concreteCalls = this.__concreteNode__.calls;
1301
- var concreteCall = concreteCalls && concreteCalls.filter(function (call) {
1302
- return call.name === callName;
1303
- })[0];
1304
-
1305
- if (concreteCall) {
1306
- return concreteCall.metadata.type;
1307
- }
1308
- };
1309
-
1310
- _proto8.equals = function equals(that) {
1311
- if (this === that) {
1312
- return true;
1313
- }
1314
-
1315
- if (!(that instanceof RelayQueryField)) {
1316
- return false;
1317
- }
1318
-
1319
- if (this.getSchemaName() !== that.getSchemaName() || this.getApplicationName() !== that.getApplicationName() || !areCallValuesEqual(this.getCallsWithValues(), that.getCallsWithValues())) {
1320
- return false;
1321
- }
1322
-
1323
- return _RelayQueryNode5.prototype.equals.call(this, that);
1324
- };
1325
-
1326
- _proto8.cloneAsRefQueryDependency = function cloneAsRefQueryDependency() {
1327
- var field = new RelayQueryField(this.__concreteNode__, this.__root__, this.__variables__);
1328
- field.__children__ = [];
1329
- field.__isRefQueryDependency__ = true;
1330
- return field;
1331
- };
1332
-
1333
- _proto8.cloneFieldWithCalls = function cloneFieldWithCalls(children, calls) {
1334
- if (!this.canHaveSubselections()) {
1335
- // Compact new children *after* this check, for consistency.
1336
- !(children.length === 0) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryNode: Cannot add children to field `%s` because it does ' + 'not support sub-selections (sub-fields).', this.getSchemaName()) : require("fbjs/lib/invariant")(false) : void 0;
1337
- } // use `clone()` if call values do not change
1338
-
1339
-
1340
- if (require("fbjs/lib/areEqual")(this.getCallsWithValues(), calls)) {
1341
- var clone = this.clone(children);
1342
- return clone;
1343
- }
1344
-
1345
- var nextChildren = cloneChildren(this.getChildren(), children);
1346
-
1347
- if (!nextChildren.length) {
1348
- return null;
1349
- }
1350
-
1351
- var field = new RelayQueryField(this.__concreteNode__, this.__root__, this.__variables__);
1352
- field.__children__ = nextChildren;
1353
- field.__calls__ = calls;
1354
- return field;
1355
- };
1356
- /**
1357
- * The following types of arguments are non-core:
1358
- * - Range calls such as `first` or `find` on connections.
1359
- * - Conditionals when the field is present.
1360
- */
1361
-
1362
-
1363
- _proto8._isCoreArg = function _isCoreArg(arg) {
1364
- return (// `name(if:true)`, `name(unless:false)`, and `name` are equivalent.
1365
- !(arg.name === IF && String(arg.value) === TRUE) && !(arg.name === UNLESS && String(arg.value) === FALSE) && // Connection arguments can be stripped out.
1366
- !(this.isConnection() && require("relay-runtime").ConnectionInterface.isConnectionCall(arg))
1367
- );
1368
- };
1369
-
1370
- return RelayQueryField;
1371
- }(RelayQueryNode);
1372
-
1373
- function createNode(concreteNode, rootContext, variables) {
1374
- !(typeof concreteNode === 'object' && concreteNode !== null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryNode: Expected a GraphQL object created with `Relay.QL`, got' + '`%s`.', concreteNode) : require("fbjs/lib/invariant")(false) : void 0;
1375
- var kind = concreteNode.kind;
1376
- var type = RelayQueryNode;
1377
-
1378
- if (kind === 'Field') {
1379
- type = RelayQueryField;
1380
- } else if (kind === 'Fragment') {
1381
- var fragment = require("nullthrows")(require("./QueryBuilder").getFragment(concreteNode));
1382
-
1383
- var hoistedRootArgs = fragment.metadata.hoistedRootArgs;
1384
-
1385
- if (hoistedRootArgs) {
1386
- var rootVariables = rootContext.variables;
1387
- var combinedVariables = (0, _objectSpread2["default"])({}, variables);
1388
- hoistedRootArgs.forEach(function (argName) {
1389
- var rootValue = rootVariables[argName];
1390
- !(rootValue !== undefined || variables.hasOwnProperty(argName)) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryNode: Expected root argument `%s` on unmasked fragment `%s` to be provided ' + 'in the query variables. If the route is still using ` RelayClassic.QL`, please make ' + 'sure that the argument is defined in the injected Relay constants module or add the ' + 'argument in the `prepareParams` for that route.', argName, fragment.name) : require("fbjs/lib/invariant")(false) : void 0;
1391
-
1392
- if (rootValue !== undefined) {
1393
- combinedVariables[argName] = rootValue;
1394
- }
1395
- });
1396
- variables = combinedVariables;
1397
- }
1398
-
1399
- type = RelayQueryFragment;
1400
- } else if (kind === 'FragmentSpread') {
1401
- var spread = require("nullthrows")(require("./QueryBuilder").getFragmentSpread(concreteNode));
1402
-
1403
- var _rootVariables = rootContext.variables;
1404
-
1405
- var argumentVariables = require("./RelayVariables").getFragmentSpreadArguments(spread.fragment.node.name, spread.args, variables, _rootVariables);
1406
-
1407
- var fragmentVariables = require("./RelayVariables").getFragmentVariables(spread.fragment, _rootVariables, argumentVariables);
1408
-
1409
- return createMemoizedFragment(spread.fragment.node, rootContext, fragmentVariables, {
1410
- isDeferred: false,
1411
- isContainerFragment: true,
1412
- isTypeConditional: false
1413
- });
1414
- } else if (kind === 'OperationDefinition') {
1415
- type = RelayOSSQuery;
1416
- } else if (kind === 'Query') {
1417
- type = RelayQueryRoot;
1418
- } else if (kind === 'Mutation') {
1419
- type = RelayQueryMutation;
1420
- } else if (kind === 'Subscription') {
1421
- type = RelayQuerySubscription;
1422
- } else if (concreteNode instanceof require("./RelayRouteFragment")) {
1423
- var metaRoute = require("./RelayMetaRoute").get(rootContext.routeName);
1424
-
1425
- var _fragment = concreteNode.getFragmentForRoute(metaRoute); // May be null if no value was defined for this route.
1426
-
1427
-
1428
- if (Array.isArray(_fragment)) {
1429
- // A route-conditional function may return a single fragment reference
1430
- // or an array of fragment references.
1431
- return _fragment.map(function (frag) {
1432
- return createNode(frag, rootContext, variables);
1433
- });
1434
- } else if (_fragment) {
1435
- return createNode(_fragment, rootContext, variables);
1436
- }
1437
-
1438
- return null;
1439
- } else if (concreteNode instanceof require("./RelayFragmentReference")) {
1440
- var _fragment2 = concreteNode.getFragment(variables);
1441
-
1442
- var _metaRoute = require("./RelayMetaRoute").get(rootContext.routeName);
1443
-
1444
- var _fragmentVariables = concreteNode.getVariables(_metaRoute, variables);
1445
-
1446
- if (_fragment2) {
1447
- // the fragment may be null when `if` or `unless` conditions are not met.
1448
- return createMemoizedFragment(_fragment2, rootContext, _fragmentVariables, {
1449
- isDeferred: concreteNode.isDeferred(),
1450
- isContainerFragment: concreteNode.isContainerFragment(),
1451
- isTypeConditional: concreteNode.isTypeConditional()
1452
- });
1453
- }
1454
-
1455
- return null;
1456
- } else {}
1457
-
1458
- return new type(concreteNode, rootContext, variables);
1459
- }
1460
- /**
1461
- * Memoizes the `RelayQueryFragment` equivalent of a given GraphQL fragment
1462
- * for the given route, variables, and deferred status.
1463
- */
1464
-
1465
-
1466
- function createMemoizedFragment(concreteFragment, rootContext, variables, metadata) {
1467
- var cacheKey = rootContext.routeName + ':' + require("./stableStringify")(rootContext.variables) + ':' + require("./stableStringify")(variables) + ':' + require("./stableStringify")(metadata);
1468
-
1469
- var fragment = concreteFragment.__cachedFragment__;
1470
- var fragmentCacheKey = concreteFragment.__cacheKey__;
1471
-
1472
- if (!fragment || fragmentCacheKey !== cacheKey) {
1473
- fragment = new RelayQueryFragment(concreteFragment, rootContext, variables, metadata);
1474
- concreteFragment.__cachedFragment__ = fragment;
1475
- concreteFragment.__cacheKey__ = cacheKey;
1476
- }
1477
-
1478
- return fragment;
1479
- }
1480
- /**
1481
- * Compacts new children and compares them to the previous children.
1482
- * - If all items are equal, returns previous array
1483
- * - If any items differ, returns new array
1484
- */
1485
-
1486
-
1487
- function cloneChildren(prevChildren, nextChildren) {
1488
- var children = [];
1489
- var isSameChildren = true;
1490
- var prevIndex = 0;
1491
-
1492
- for (var ii = 0; ii < nextChildren.length; ii++) {
1493
- var child = nextChildren[ii];
1494
-
1495
- if (child) {
1496
- children.push(child);
1497
- isSameChildren = isSameChildren && child === prevChildren[prevIndex++];
1498
- }
1499
- }
1500
-
1501
- if (isSameChildren && children.length === prevChildren.length) {
1502
- return prevChildren;
1503
- } else {
1504
- return children;
1505
- }
1506
- }
1507
- /**
1508
- * Creates an opaque serialization of calls.
1509
- */
1510
-
1511
-
1512
- function serializeCalls(calls) {
1513
- if (calls.length) {
1514
- var callMap = {};
1515
- calls.forEach(function (call) {
1516
- callMap[call.name] = call.value;
1517
- });
1518
- return require("./stableStringify")(callMap);
1519
- } else {
1520
- return '';
1521
- }
1522
- }
1523
- /**
1524
- * Checks if two sets of calls have equal names and values. This skips testing
1525
- * argument types because type metadata for scalar arguments may be omitted by
1526
- * the Babel plugin.
1527
- */
1528
-
1529
-
1530
- function areCallValuesEqual(thisCalls, thatCalls) {
1531
- if (thisCalls.length !== thatCalls.length) {
1532
- return false;
1533
- }
1534
-
1535
- return thisCalls.every(function (_ref2, ii) {
1536
- var thisName = _ref2.name,
1537
- thisValue = _ref2.value;
1538
- var _thatCalls$ii = thatCalls[ii],
1539
- thatName = _thatCalls$ii.name,
1540
- thatValue = _thatCalls$ii.value;
1541
-
1542
- if (thisName !== thatName) {
1543
- return false;
1544
- }
1545
-
1546
- if (thisValue instanceof require("./RelayVariable")) {
1547
- return thisValue.equals(thatValue);
1548
- }
1549
-
1550
- return require("fbjs/lib/areEqual")(thisValue, thatValue);
1551
- });
1552
- }
1553
-
1554
- function createRootContext(metaRoute, variables) {
1555
- return {
1556
- routeName: metaRoute.name,
1557
- variables: variables
1558
- };
1559
- }
1560
-
1561
- require("relay-runtime").RelayProfiler.instrumentMethods(RelayQueryNode.prototype, {
1562
- clone: '@RelayQueryNode.prototype.clone',
1563
- equals: '@RelayQueryNode.prototype.equals',
1564
- getChildren: '@RelayQueryNode.prototype.getChildren',
1565
- getDirectives: '@RelayQueryNode.prototype.getDirectives',
1566
- hasDeferredDescendant: '@RelayQueryNode.prototype.hasDeferredDescendant',
1567
- getFieldByStorageKey: '@RelayQueryNode.prototype.getFieldByStorageKey'
1568
- });
1569
-
1570
- require("relay-runtime").RelayProfiler.instrumentMethods(RelayQueryField.prototype, {
1571
- getStorageKey: '@RelayQueryField.prototype.getStorageKey',
1572
- getSerializationKey: '@RelayQueryField.prototype.getSerializationKey'
1573
- });
1574
-
1575
- module.exports = {
1576
- Field: RelayQueryField,
1577
- Fragment: RelayQueryFragment,
1578
- Mutation: RelayQueryMutation,
1579
- Node: RelayQueryNode,
1580
- Operation: RelayQueryOperation,
1581
- OSSQuery: RelayOSSQuery,
1582
- Root: RelayQueryRoot,
1583
- Subscription: RelayQuerySubscription
1584
- };