react-relay 2.0.0-rc.2 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,530 +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 _defineProperty2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/defineProperty"));
13
-
14
- var _objectSpread3 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/objectSpread"));
15
-
16
- var transactionIDCounter = 0;
17
- /**
18
- * @internal
19
- *
20
- * Coordinates execution of concurrent mutations, including application and
21
- * rollback of optimistic payloads and enqueueing mutations with the same
22
- * collision key.
23
- */
24
-
25
- var RelayMutationQueue =
26
- /*#__PURE__*/
27
- function () {
28
- function RelayMutationQueue(storeData) {
29
- this._collisionQueueMap = {};
30
- this._pendingTransactionMap = {};
31
- this._queue = [];
32
- this._storeData = storeData;
33
- this._willBatchRefreshQueuedData = false;
34
- }
35
- /**
36
- * High-level API for creating a RelayMutationTransaction from a
37
- * RelayMutation.
38
- */
39
-
40
-
41
- var _proto = RelayMutationQueue.prototype;
42
-
43
- _proto.createTransaction = function createTransaction(mutation, callbacks) {
44
- return this.createTransactionWithPendingTransaction(null, function (id, mutationTransaction) {
45
- return new RelayPendingTransaction({
46
- id: id,
47
- mutation: mutation,
48
- mutationTransaction: mutationTransaction,
49
- onFailure: callbacks && callbacks.onFailure,
50
- onSuccess: callbacks && callbacks.onSuccess
51
- });
52
- });
53
- };
54
- /**
55
- * @internal
56
- *
57
- * This is a lower-level API used to create transactions based on:
58
- *
59
- * - An object that conforms to the PendingTransaction type; or
60
- * - A function that can build such an object.
61
- *
62
- * Used by the high-level `createTransaction` API, but also enables us to
63
- * run classic and low-level mutations.
64
- */
65
-
66
-
67
- _proto.createTransactionWithPendingTransaction = function createTransactionWithPendingTransaction(pendingTransaction, transactionBuilder) {
68
- !(pendingTransaction || transactionBuilder) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayMutationQueue: `createTransactionWithPendingTransaction()` ' + 'expects a PendingTransaction or TransactionBuilder.') : require("fbjs/lib/invariant")(false) : void 0;
69
- var id = getNextID();
70
- var mutationTransaction = new (require("./RelayMutationTransaction"))(this, id);
71
- var transaction = pendingTransaction || transactionBuilder(id, mutationTransaction);
72
- this._pendingTransactionMap[id] = transaction;
73
-
74
- this._queue.push(transaction);
75
-
76
- return mutationTransaction;
77
- };
78
-
79
- _proto.getTransaction = function getTransaction(id) {
80
- var transaction = this._pendingTransactionMap[id];
81
-
82
- if (transaction) {
83
- return transaction.mutationTransaction;
84
- }
85
-
86
- return null;
87
- };
88
-
89
- _proto.getError = function getError(id) {
90
- return this._get(id).error;
91
- };
92
-
93
- _proto.getStatus = function getStatus(id) {
94
- return this._get(id).status;
95
- };
96
-
97
- _proto.applyOptimistic = function applyOptimistic(id) {
98
- var transaction = this._get(id);
99
-
100
- transaction.status = require("./RelayMutationTransactionStatus").UNCOMMITTED;
101
- transaction.error = null;
102
-
103
- this._handleOptimisticUpdate(transaction);
104
- };
105
-
106
- _proto.commit = function commit(id) {
107
- var transaction = this._get(id);
108
-
109
- var collisionKey = transaction.getCollisionKey();
110
- var collisionQueue = collisionKey && this._collisionQueueMap[collisionKey];
111
-
112
- if (collisionQueue) {
113
- collisionQueue.push(transaction);
114
- transaction.status = require("./RelayMutationTransactionStatus").COMMIT_QUEUED;
115
- transaction.error = null;
116
- return;
117
- }
118
-
119
- if (collisionKey) {
120
- this._collisionQueueMap[collisionKey] = [transaction];
121
- }
122
-
123
- this._handleCommit(transaction);
124
- };
125
-
126
- _proto.rollback = function rollback(id) {
127
- var transaction = this._get(id);
128
-
129
- var collisionKey = transaction.getCollisionKey();
130
-
131
- if (collisionKey) {
132
- var collisionQueue = this._collisionQueueMap[collisionKey];
133
-
134
- if (collisionQueue) {
135
- var index = collisionQueue.indexOf(transaction);
136
-
137
- if (index !== -1) {
138
- collisionQueue.splice(index, 1);
139
- }
140
-
141
- if (collisionQueue.length === 0) {
142
- delete this._collisionQueueMap[collisionKey];
143
- }
144
- }
145
- }
146
-
147
- this._handleRollback(transaction);
148
- };
149
-
150
- _proto._get = function _get(id) {
151
- var transaction = this._pendingTransactionMap[id];
152
- !transaction ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayMutationQueue: `%s` is not a valid pending transaction ID.', id) : require("fbjs/lib/invariant")(false) : void 0;
153
- return transaction;
154
- };
155
-
156
- _proto._handleOptimisticUpdate = function _handleOptimisticUpdate(transaction) {
157
- var optimisticResponse = transaction.getOptimisticResponse();
158
- var optimisticQuery = transaction.getOptimisticQuery(this._storeData);
159
-
160
- if (optimisticResponse && optimisticQuery) {
161
- var configs = transaction.getOptimisticConfigs() || transaction.getConfigs();
162
-
163
- this._storeData.handleUpdatePayload(optimisticQuery, optimisticResponse, {
164
- configs: configs,
165
- isOptimisticUpdate: true
166
- });
167
- }
168
- };
169
-
170
- _proto._handleCommitFailure = function _handleCommitFailure(transaction, error) {
171
- var status = error ? require("./RelayMutationTransactionStatus").COMMIT_FAILED : require("./RelayMutationTransactionStatus").COLLISION_COMMIT_FAILED;
172
- transaction.status = status;
173
- transaction.error = error;
174
- var shouldRollback = true;
175
- var onFailure = transaction.onFailure;
176
-
177
- if (onFailure) {
178
- var preventAutoRollback = function preventAutoRollback() {
179
- shouldRollback = false;
180
- };
181
-
182
- require("fbjs/lib/ErrorUtils").applyWithGuard(onFailure, null, [transaction.mutationTransaction, preventAutoRollback], null, 'RelayMutationTransaction:onCommitFailure');
183
- }
184
-
185
- if (error) {
186
- this._failCollisionQueue(transaction);
187
- } // Might have already been rolled back via `onFailure`.
188
-
189
-
190
- if (shouldRollback && this._pendingTransactionMap.hasOwnProperty(transaction.id)) {
191
- this._handleRollback(transaction);
192
- }
193
-
194
- this._batchRefreshQueuedData();
195
- };
196
-
197
- _proto._handleCommitSuccess = function _handleCommitSuccess(transaction, response) {
198
- this._advanceCollisionQueue(transaction);
199
-
200
- this._clearPendingTransaction(transaction);
201
-
202
- this._refreshQueuedData();
203
-
204
- this._storeData.handleUpdatePayload(transaction.getQuery(this._storeData), response[transaction.getCallName()], {
205
- configs: transaction.getConfigs(),
206
- isOptimisticUpdate: false
207
- });
208
-
209
- var onSuccess = transaction.onSuccess;
210
-
211
- if (onSuccess) {
212
- require("fbjs/lib/ErrorUtils").applyWithGuard(onSuccess, null, [response], null, 'RelayMutationTransaction:onCommitSuccess');
213
- }
214
- };
215
-
216
- _proto._handleCommit = function _handleCommit(transaction) {
217
- var _this = this;
218
-
219
- transaction.status = require("./RelayMutationTransactionStatus").COMMITTING;
220
- transaction.error = null;
221
- var request = new (require("./RelayMutationRequest"))(transaction.getQuery(this._storeData), transaction.getFiles());
222
-
223
- this._storeData.getNetworkLayer().sendMutation(request);
224
-
225
- request.getPromise().then(function (result) {
226
- return _this._handleCommitSuccess(transaction, result.response);
227
- }, function (error) {
228
- return _this._handleCommitFailure(transaction, error);
229
- })["catch"](function (error) {
230
- setTimeout(function () {
231
- throw error;
232
- }, 0);
233
- });
234
- };
235
-
236
- _proto._handleRollback = function _handleRollback(transaction) {
237
- this._clearPendingTransaction(transaction);
238
-
239
- this._batchRefreshQueuedData();
240
- };
241
-
242
- _proto._clearPendingTransaction = function _clearPendingTransaction(transaction) {
243
- delete this._pendingTransactionMap[transaction.id];
244
- this._queue = this._queue.filter(function (tx) {
245
- return tx !== transaction;
246
- });
247
- };
248
-
249
- _proto._advanceCollisionQueue = function _advanceCollisionQueue(transaction) {
250
- var collisionKey = transaction.getCollisionKey();
251
-
252
- if (collisionKey) {
253
- var collisionQueue = this._collisionQueueMap[collisionKey];
254
-
255
- if (collisionQueue) {
256
- // Remove the transaction that called this function.
257
- collisionQueue.shift();
258
-
259
- if (collisionQueue.length) {
260
- this._handleCommit(collisionQueue[0]);
261
- } else {
262
- delete this._collisionQueueMap[collisionKey];
263
- }
264
- }
265
- }
266
- };
267
-
268
- _proto._failCollisionQueue = function _failCollisionQueue(failedTransaction) {
269
- var _this2 = this;
270
-
271
- var collisionKey = failedTransaction.getCollisionKey();
272
-
273
- if (collisionKey) {
274
- var collisionQueue = this._collisionQueueMap[collisionKey];
275
-
276
- if (collisionQueue) {
277
- // Remove the transaction that called this function.
278
- collisionQueue.forEach(function (queuedTransaction) {
279
- if (queuedTransaction !== failedTransaction) {
280
- _this2._handleCommitFailure(queuedTransaction, null);
281
- }
282
- });
283
- delete this._collisionQueueMap[collisionKey];
284
- }
285
- }
286
- };
287
-
288
- _proto._batchRefreshQueuedData = function _batchRefreshQueuedData() {
289
- var _this3 = this;
290
-
291
- if (!this._willBatchRefreshQueuedData) {
292
- this._willBatchRefreshQueuedData = true;
293
-
294
- require("fbjs/lib/resolveImmediate")(function () {
295
- _this3._willBatchRefreshQueuedData = false;
296
-
297
- _this3._refreshQueuedData();
298
- });
299
- }
300
- };
301
-
302
- _proto._refreshQueuedData = function _refreshQueuedData() {
303
- var _this4 = this;
304
-
305
- this._storeData.clearQueuedData();
306
-
307
- this._queue.forEach(function (transaction) {
308
- return _this4._handleOptimisticUpdate(transaction);
309
- });
310
- };
311
-
312
- return RelayMutationQueue;
313
- }();
314
- /**
315
- * @private
316
- */
317
-
318
-
319
- var RelayPendingTransaction =
320
- /*#__PURE__*/
321
- function () {
322
- // Lazily computed and memoized private properties
323
- function RelayPendingTransaction(transactionData) {
324
- this.error = null;
325
- this.id = transactionData.id;
326
- this.mutation = transactionData.mutation;
327
- this.mutationTransaction = transactionData.mutationTransaction;
328
- this.onFailure = transactionData.onFailure;
329
- this.onSuccess = transactionData.onSuccess;
330
- this.status = require("./RelayMutationTransactionStatus").CREATED;
331
- }
332
-
333
- var _proto2 = RelayPendingTransaction.prototype;
334
-
335
- _proto2.getCallName = function getCallName() {
336
- if (!this._callName) {
337
- this._callName = this.getMutationNode().calls[0].name;
338
- }
339
-
340
- return this._callName;
341
- };
342
-
343
- _proto2.getCollisionKey = function getCollisionKey() {
344
- if (this._collisionKey === undefined) {
345
- this._collisionKey = this.mutation.getCollisionKey() || null;
346
- }
347
-
348
- return this._collisionKey;
349
- };
350
-
351
- _proto2.getConfigs = function getConfigs() {
352
- if (!this._configs) {
353
- this._configs = this.mutation.getConfigs();
354
- }
355
-
356
- return this._configs;
357
- };
358
-
359
- _proto2.getFatQuery = function getFatQuery() {
360
- if (!this._fatQuery) {
361
- var fragment = require("./fromGraphQL").Fragment(this.mutation.getFatQuery());
362
-
363
- !(fragment instanceof require("./RelayQuery").Fragment) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayMutationQueue: Expected `getFatQuery` to return a GraphQL ' + 'Fragment') : require("fbjs/lib/invariant")(false) : void 0;
364
- this._fatQuery = require("nullthrows")(require("./flattenRelayQuery")(fragment, {
365
- // TODO #10341736
366
- // This used to be `preserveEmptyNodes: fragment.isPattern()`. We
367
- // discovered that products were not marking their fat queries as
368
- // patterns (by adding `@relay(pattern: true)`) which was causing
369
- // `preserveEmptyNodes` to be false. This meant that empty fields,
370
- // would be stripped instead of being used to produce an intersection
371
- // with the tracked query. Products were able to do this because the
372
- // Babel Relay plugin doesn't produce validation errors for empty
373
- // fields. It should, and we will make it do so, but for now we're
374
- // going to set this to `true` always, and make the plugin warn when
375
- // it encounters an empty field that supports subselections in a
376
- // non-pattern fragment. Revert this when done.
377
- preserveEmptyNodes: true,
378
- shouldRemoveFragments: true
379
- }));
380
- }
381
-
382
- return this._fatQuery;
383
- };
384
-
385
- _proto2.getFiles = function getFiles() {
386
- if (this._files === undefined) {
387
- this._files = this.mutation.getFiles() || null;
388
- }
389
-
390
- return this._files;
391
- };
392
-
393
- _proto2.getInputVariable = function getInputVariable() {
394
- if (!this._inputVariable) {
395
- var inputVariable = (0, _objectSpread3["default"])({}, this.mutation.getVariables(), (0, _defineProperty2["default"])({}, require("relay-runtime").ConnectionInterface.get().CLIENT_MUTATION_ID, this.id));
396
- this._inputVariable = inputVariable;
397
- }
398
-
399
- return this._inputVariable;
400
- };
401
-
402
- _proto2.getMutationNode = function getMutationNode() {
403
- if (!this._mutationNode) {
404
- var mutationNode = require("./QueryBuilder").getMutation(this.mutation.getMutation());
405
-
406
- !mutationNode ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayMutation: Expected `getMutation` to return a mutation created ' + 'with Relay.QL`mutation { ... }`.') : require("fbjs/lib/invariant")(false) : void 0;
407
- this._mutationNode = mutationNode;
408
- }
409
-
410
- return this._mutationNode;
411
- };
412
-
413
- _proto2.getOptimisticConfigs = function getOptimisticConfigs() {
414
- if (this._optimisticConfigs === undefined) {
415
- this._optimisticConfigs = this.mutation.getOptimisticConfigs() || null;
416
- }
417
-
418
- return this._optimisticConfigs;
419
- };
420
-
421
- _proto2.getOptimisticQuery = function getOptimisticQuery(storeData) {
422
- if (this._optimisticQuery === undefined) {
423
- if (process.env.NODE_ENV !== "production" && console.groupCollapsed && console.groupEnd) {
424
- console.groupCollapsed('Optimistic query for `' + this.getCallName() + '`');
425
- }
426
-
427
- var optimisticResponse = this._getRawOptimisticResponse();
428
-
429
- if (optimisticResponse) {
430
- var optimisticConfigs = this.getOptimisticConfigs();
431
- var tracker = getTracker(storeData);
432
-
433
- if (optimisticConfigs) {
434
- this._optimisticQuery = require("./RelayMutationQuery").buildQuery({
435
- configs: optimisticConfigs,
436
- fatQuery: this.getFatQuery(),
437
- input: this.getInputVariable(),
438
- mutationName: this.mutation.constructor.name,
439
- mutation: this.getMutationNode(),
440
- tracker: tracker
441
- });
442
- } else {
443
- this._optimisticQuery = require("./RelayMutationQuery").buildQueryForOptimisticUpdate({
444
- response: optimisticResponse,
445
- fatQuery: this.getFatQuery(),
446
- mutation: this.getMutationNode()
447
- });
448
- }
449
- } else {
450
- this._optimisticQuery = null;
451
- }
452
-
453
- if (process.env.NODE_ENV !== "production" && console.groupCollapsed && console.groupEnd) {
454
- require("./RelayMutationDebugPrinter").printOptimisticMutation(this._optimisticQuery, optimisticResponse);
455
-
456
- console.groupEnd();
457
- }
458
- }
459
-
460
- return this._optimisticQuery;
461
- };
462
-
463
- _proto2._getRawOptimisticResponse = function _getRawOptimisticResponse() {
464
- if (this._rawOptimisticResponse === undefined) {
465
- var optimisticResponse = this.mutation.getOptimisticResponse() || null;
466
-
467
- if (optimisticResponse) {
468
- optimisticResponse[require("relay-runtime").ConnectionInterface.get().CLIENT_MUTATION_ID] = this.id;
469
- }
470
-
471
- this._rawOptimisticResponse = optimisticResponse;
472
- }
473
-
474
- return this._rawOptimisticResponse;
475
- };
476
-
477
- _proto2.getOptimisticResponse = function getOptimisticResponse() {
478
- if (this._optimisticResponse === undefined) {
479
- var optimisticResponse = this._getRawOptimisticResponse();
480
-
481
- if (optimisticResponse) {
482
- this._optimisticResponse = require("./RelayOptimisticMutationUtils").inferRelayPayloadFromData(optimisticResponse);
483
- } else {
484
- this._optimisticResponse = optimisticResponse;
485
- }
486
- }
487
-
488
- return this._optimisticResponse;
489
- };
490
-
491
- _proto2.getQuery = function getQuery(storeData) {
492
- if (!this._query) {
493
- if (process.env.NODE_ENV !== "production" && console.groupCollapsed && console.groupEnd) {
494
- console.groupCollapsed('Mutation query for `' + this.getCallName() + '`');
495
- }
496
-
497
- var tracker = getTracker(storeData);
498
- this._query = require("./RelayMutationQuery").buildQuery({
499
- configs: this.getConfigs(),
500
- fatQuery: this.getFatQuery(),
501
- input: this.getInputVariable(),
502
- mutationName: this.getMutationNode().name,
503
- mutation: this.getMutationNode(),
504
- tracker: tracker
505
- });
506
-
507
- if (process.env.NODE_ENV !== "production" && console.groupCollapsed && console.groupEnd) {
508
- require("./RelayMutationDebugPrinter").printMutation(this._query);
509
-
510
- console.groupEnd();
511
- }
512
- }
513
-
514
- return this._query;
515
- };
516
-
517
- return RelayPendingTransaction;
518
- }();
519
-
520
- function getTracker(storeData) {
521
- var tracker = storeData.getQueryTracker();
522
- !tracker ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayMutationQueue: a RelayQueryTracker was not configured but an ' + 'attempt to process a RelayMutation instance was made. Either use ' + 'RelayGraphQLMutation (which does not require a tracker), or use ' + '`RelayStoreData.injectQueryTracker()` to configure a tracker. Be ' + 'aware that trackers are provided by default, so if you are seeing ' + 'this error it means that somebody has explicitly intended to opt ' + 'out of query tracking.') : require("fbjs/lib/invariant")(false) : void 0;
523
- return tracker;
524
- }
525
-
526
- function getNextID() {
527
- return require("fbjs/lib/base62")(transactionIDCounter++);
528
- }
529
-
530
- module.exports = RelayMutationQueue;
@@ -1,103 +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
- * strict-local
8
- * @format
9
- */
10
- 'use strict';
11
-
12
- var _inheritsLoose2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/inheritsLoose"));
13
-
14
- /**
15
- * @internal
16
- *
17
- * Instances of these are made available via `RelayNetworkLayer.sendMutation`.
18
- */
19
- var RelayMutationRequest =
20
- /*#__PURE__*/
21
- function (_Deferred) {
22
- (0, _inheritsLoose2["default"])(RelayMutationRequest, _Deferred);
23
-
24
- function RelayMutationRequest(mutation, files) {
25
- var _this;
26
-
27
- _this = _Deferred.call(this) || this;
28
- _this._mutation = mutation;
29
- _this._printedQuery = null;
30
- _this._files = files;
31
- return _this;
32
- }
33
- /**
34
- * @public
35
- *
36
- * Gets a string name used to refer to this request for printing debug output.
37
- */
38
-
39
-
40
- var _proto = RelayMutationRequest.prototype;
41
-
42
- _proto.getDebugName = function getDebugName() {
43
- return this._mutation.getName();
44
- };
45
- /**
46
- * @public
47
- *
48
- * Gets an optional map from name to File objects.
49
- */
50
-
51
-
52
- _proto.getFiles = function getFiles() {
53
- return this._files;
54
- };
55
- /**
56
- * @public
57
- *
58
- * Gets the variables used by the mutation. These variables should be
59
- * serialized and sent in the GraphQL request.
60
- */
61
-
62
-
63
- _proto.getVariables = function getVariables() {
64
- return this._getPrintedQuery().variables;
65
- };
66
- /**
67
- * @public
68
- *
69
- * Gets a string representation of the GraphQL mutation.
70
- */
71
-
72
-
73
- _proto.getQueryString = function getQueryString() {
74
- return this._getPrintedQuery().text;
75
- };
76
- /**
77
- * @public
78
- * @unstable
79
- */
80
-
81
-
82
- _proto.getMutation = function getMutation() {
83
- return this._mutation;
84
- };
85
- /**
86
- * @private
87
- *
88
- * Returns the memoized printed query.
89
- */
90
-
91
-
92
- _proto._getPrintedQuery = function _getPrintedQuery() {
93
- if (!this._printedQuery) {
94
- this._printedQuery = require("./printRelayQuery")(this._mutation);
95
- }
96
-
97
- return this._printedQuery;
98
- };
99
-
100
- return RelayMutationRequest;
101
- }(require("fbjs/lib/Deferred"));
102
-
103
- module.exports = RelayMutationRequest;