relay-runtime 1.3.0 → 1.5.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 (90) hide show
  1. package/LICENSE +16 -26
  2. package/index.js +3 -6
  3. package/lib/ConvertToExecuteFunction.js +73 -0
  4. package/lib/RelayConcreteNode.js +31 -14
  5. package/lib/RelayConcreteVariables.js +11 -6
  6. package/lib/RelayConnectionHandler.js +2 -4
  7. package/lib/RelayConnectionInterface.js +3 -5
  8. package/lib/RelayCore.js +4 -6
  9. package/lib/RelayDataLoader.js +2 -4
  10. package/lib/RelayDeclarativeMutationConfig.js +316 -0
  11. package/lib/RelayDefaultHandleKey.js +2 -4
  12. package/lib/RelayDefaultHandlerProvider.js +2 -4
  13. package/lib/RelayError.js +2 -6
  14. package/lib/RelayInMemoryRecordSource.js +2 -4
  15. package/lib/RelayInternalTypes.js +2 -5
  16. package/lib/RelayInternals.js +2 -5
  17. package/lib/RelayMarkSweepStore.js +22 -5
  18. package/lib/RelayMetricsRecorder.js +9 -9
  19. package/lib/RelayMockRenderer.js +3 -8
  20. package/lib/RelayModernEnvironment.js +120 -135
  21. package/lib/RelayModernFragmentSpecResolver.js +81 -55
  22. package/lib/RelayModernGraphQLTag.js +8 -17
  23. package/lib/RelayModernOperationSelector.js +8 -8
  24. package/lib/RelayModernRecord.js +8 -8
  25. package/lib/RelayModernSelector.js +54 -43
  26. package/lib/RelayNetwork.js +9 -11
  27. package/lib/RelayNetworkDebug.js +4 -7
  28. package/lib/RelayNetworkLogger.js +2 -4
  29. package/lib/RelayNetworkLoggerTransaction.js +18 -20
  30. package/lib/RelayNetworkTypes.js +2 -4
  31. package/lib/RelayObservable.js +193 -120
  32. package/lib/RelayProfiler.js +7 -7
  33. package/lib/RelayPublishQueue.js +17 -9
  34. package/lib/RelayQueryCaching.js +2 -5
  35. package/lib/RelayQueryResponseCache.js +3 -5
  36. package/lib/RelayReader.js +18 -8
  37. package/lib/RelayRecordProxy.js +12 -11
  38. package/lib/RelayRecordSourceMutator.js +9 -9
  39. package/lib/RelayRecordSourceProxy.js +15 -13
  40. package/lib/RelayRecordSourceSelectorProxy.js +2 -4
  41. package/lib/RelayRecordState.js +2 -4
  42. package/lib/RelayReferenceMarker.js +2 -4
  43. package/lib/RelayResponseNormalizer.js +34 -25
  44. package/lib/RelayRuntime.js +25 -14
  45. package/lib/RelayRuntimeTypes.js +22 -0
  46. package/lib/RelayShallowMock.js +4 -7
  47. package/lib/RelayStoreTypes.js +2 -4
  48. package/lib/RelayStoreUtils.js +66 -26
  49. package/lib/RelayTaskQueue.js +2 -5
  50. package/lib/RelayTypes.js +2 -5
  51. package/lib/RelayViewerHandler.js +4 -5
  52. package/lib/applyRelayModernOptimisticMutation.js +9 -8
  53. package/lib/cloneRelayHandleSourceField.js +4 -11
  54. package/lib/commitLocalUpdate.js +2 -4
  55. package/lib/commitRelayModernMutation.js +24 -22
  56. package/lib/createRelayNetworkLogger.js +25 -27
  57. package/lib/dedent.js +2 -5
  58. package/lib/deepFreeze.js +3 -5
  59. package/lib/deferrableFragmentKey.js +21 -0
  60. package/lib/fetchRelayModernQuery.js +13 -21
  61. package/lib/generateRelayClientID.js +2 -4
  62. package/lib/getRelayHandleKey.js +2 -4
  63. package/lib/hasOverlappingIDs.js +2 -4
  64. package/lib/isCompatibleRelayFragmentType.js +2 -5
  65. package/lib/isPromise.js +2 -5
  66. package/lib/isRelayModernEnvironment.js +2 -4
  67. package/lib/isScalarAndEqual.js +3 -5
  68. package/lib/normalizePayload.js +10 -13
  69. package/lib/normalizeRelayPayload.js +8 -5
  70. package/lib/recycleNodesInto.js +2 -4
  71. package/lib/relayUnstableBatchedUpdates.js +2 -5
  72. package/lib/relayUnstableBatchedUpdates.native.js +2 -5
  73. package/lib/requestRelaySubscription.js +20 -34
  74. package/lib/simpleClone.js +2 -4
  75. package/lib/stableCopy.js +35 -0
  76. package/lib/testEditDistance.js +2 -5
  77. package/lib/throwFailedPromise.js +2 -5
  78. package/package.json +4 -5
  79. package/relay-runtime.js +2307 -2665
  80. package/relay-runtime.min.js +6 -9
  81. package/ARCHITECTURE.md +0 -232
  82. package/PATENTS +0 -33
  83. package/lib/ConvertToObserveFunction.js +0 -39
  84. package/lib/RelayDebugger.js +0 -199
  85. package/lib/RelayRecordSourceInspector.js +0 -289
  86. package/lib/RelayStoreProxyDebugger.js +0 -44
  87. package/lib/formatStorageKey.js +0 -37
  88. package/lib/prettyStringify.js +0 -35
  89. package/lib/setRelayModernMutationConfigs.js +0 -302
  90. package/lib/stableJSONStringify.js +0 -45
package/lib/RelayError.js CHANGED
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Copyright (c) 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
7
  * @providesModule RelayError
10
8
  *
@@ -43,9 +41,7 @@ var RelayError = {
43
41
  * @private
44
42
  */
45
43
  function createError(type, name, format, args) {
46
- /*eslint-disable fb-www/sprintf-like-args */
47
44
  var error = new Error(require('fbjs/lib/sprintf').apply(undefined, [format].concat((0, _toConsumableArray3['default'])(args))));
48
- /*eslint-enable fb-www/sprintf-like-args */
49
45
  error.name = name;
50
46
  error.type = type;
51
47
  error.framesToPop = 2;
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Copyright (c) 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
7
  * @providesModule RelayInMemoryRecordSource
10
8
  *
@@ -1,12 +1,9 @@
1
1
  /**
2
2
  * Copyright (c) 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
- * @providesModule RelayInternalTypes
10
7
  *
11
8
  * @format
12
9
  */
@@ -1,12 +1,9 @@
1
1
  /**
2
2
  * Copyright (c) 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
- * @providesModule RelayInternals
10
7
  *
11
8
  * @format
12
9
  */
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Copyright (c) 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
7
  * @providesModule RelayMarkSweepStore
10
8
  *
@@ -48,6 +46,7 @@ var RelayMarkSweepStore = function () {
48
46
  }
49
47
  }
50
48
  }
49
+ this._gcEnabled = true;
51
50
  this._hasScheduledGC = false;
52
51
  this._index = 0;
53
52
  this._recordSource = source;
@@ -108,6 +107,13 @@ var RelayMarkSweepStore = function () {
108
107
  return { dispose: dispose };
109
108
  };
110
109
 
110
+ // Internal API
111
+
112
+
113
+ RelayMarkSweepStore.prototype.__getUpdatedRecordIDs = function __getUpdatedRecordIDs() {
114
+ return this._updatedRecordIDs;
115
+ };
116
+
111
117
  RelayMarkSweepStore.prototype._updateSubscription = function _updateSubscription(subscription) {
112
118
  var callback = subscription.callback,
113
119
  snapshot = subscription.snapshot;
@@ -137,7 +143,7 @@ var RelayMarkSweepStore = function () {
137
143
  RelayMarkSweepStore.prototype._scheduleGC = function _scheduleGC() {
138
144
  var _this4 = this;
139
145
 
140
- if (this._hasScheduledGC) {
146
+ if (!this._gcEnabled || this._hasScheduledGC) {
141
147
  return;
142
148
  }
143
149
  this._hasScheduledGC = true;
@@ -170,6 +176,17 @@ var RelayMarkSweepStore = function () {
170
176
  }
171
177
  };
172
178
 
179
+ // Internal hooks to enable/disable garbage collection for experimentation
180
+
181
+
182
+ RelayMarkSweepStore.prototype.__enableGC = function __enableGC() {
183
+ this._gcEnabled = true;
184
+ };
185
+
186
+ RelayMarkSweepStore.prototype.__disableGC = function __disableGC() {
187
+ this._gcEnabled = false;
188
+ };
189
+
173
190
  return RelayMarkSweepStore;
174
191
  }();
175
192
 
@@ -1,12 +1,9 @@
1
1
  /**
2
2
  * Copyright (c) 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
- * @providesModule RelayMetricsRecorder
10
7
  *
11
8
  * @format
12
9
  */
@@ -19,6 +16,9 @@ var _classCallCheck3 = _interopRequireDefault(require('babel-runtime/helpers/cla
19
16
 
20
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
21
18
 
19
+ var _require = require('relay-runtime'),
20
+ RelayProfiler = _require.RelayProfiler;
21
+
22
22
  var measurementDefaults = {
23
23
  aggregateTime: 0,
24
24
  callCount: 0
@@ -73,8 +73,8 @@ var RelayMetricsRecorder = function () {
73
73
  this._profileStack = [0];
74
74
  this._startTimesStack = [0];
75
75
 
76
- require('./RelayProfiler').attachAggregateHandler('*', this._measure);
77
- require('./RelayProfiler').attachProfileHandler('*', this._instrumentProfile);
76
+ RelayProfiler.attachAggregateHandler('*', this._measure);
77
+ RelayProfiler.attachProfileHandler('*', this._instrumentProfile);
78
78
  };
79
79
 
80
80
  RelayMetricsRecorder.prototype.stop = function stop() {
@@ -84,8 +84,8 @@ var RelayMetricsRecorder = function () {
84
84
  this._recordingTotalTime += require('fbjs/lib/performanceNow')() - this._recordingStartTime;
85
85
  this._isEnabled = false;
86
86
 
87
- require('./RelayProfiler').detachAggregateHandler('*', this._measure);
88
- require('./RelayProfiler').detachProfileHandler('*', this._instrumentProfile);
87
+ RelayProfiler.detachAggregateHandler('*', this._measure);
88
+ RelayProfiler.detachProfileHandler('*', this._instrumentProfile);
89
89
  };
90
90
 
91
91
  RelayMetricsRecorder.prototype.getMetrics = function getMetrics() {
@@ -1,12 +1,9 @@
1
1
  /**
2
2
  * Copyright (c) 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
- * @providesModule RelayMockRenderer
10
7
  *
11
8
  * @format
12
9
  */
@@ -29,9 +26,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'd
29
26
  * Note: For unit tests, you may need to mock `ReactDOM` as follows:
30
27
  *
31
28
  * ```
32
- * jest
33
- * .disableAutomock()
34
- * .mock('ReactDOM', () => ({}));
29
+ * jest.mock('ReactDOM', () => ({}));
35
30
  * ```
36
31
  *
37
32
  * Currently ReactDOM and ReactTestRenderer cannot both be loaded in the same
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Copyright (c) 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
7
  * @providesModule RelayModernEnvironment
10
8
  *
@@ -17,11 +15,15 @@ var _classCallCheck3 = _interopRequireDefault(require('babel-runtime/helpers/cla
17
15
 
18
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
19
17
 
18
+ var _require = require('./RelayModernOperationSelector'),
19
+ createOperationSelector = _require.createOperationSelector;
20
+
20
21
  var RelayModernEnvironment = function () {
21
22
  function RelayModernEnvironment(config) {
22
23
  var _this = this;
23
24
 
24
25
  (0, _classCallCheck3['default'])(this, RelayModernEnvironment);
26
+ this._deferrableSelections = new Set();
25
27
 
26
28
  this.configName = config.configName;
27
29
  var handlerProvider = config.handlerProvider ? config.handlerProvider : require('./RelayDefaultHandlerProvider');
@@ -34,27 +36,12 @@ var RelayModernEnvironment = function () {
34
36
  return _this._network = newNet;
35
37
  };
36
38
 
37
- if (process.env.NODE_ENV !== 'production') {
38
- var g = typeof global !== 'undefined' ? global : window;
39
-
40
- // Attach the debugger symbol to the global symbol so it can be accessed by
41
- // devtools extension.
42
- if (!g.__RELAY_DEBUGGER__) {
43
- var _require = require('./RelayDebugger'),
44
- RelayDebugger = _require.RelayDebugger;
45
-
46
- g.__RELAY_DEBUGGER__ = new RelayDebugger();
47
- }
48
-
49
- // Setup the runtime part for Native
50
- if (typeof g.registerDevtoolsPlugin === 'function') {
51
- g.registerDevtoolsPlugin(require('relay-debugger-react-native-runtime'));
52
- }
53
-
54
- var envId = g.__RELAY_DEBUGGER__.registerEnvironment(this);
55
- this._debugger = g.__RELAY_DEBUGGER__.getEnvironmentDebugger(envId);
56
- } else {
57
- this._debugger = null;
39
+ // Register this Relay Environment with Relay DevTools if it exists.
40
+ // Note: this must always be the last step in the constructor.
41
+ var _global = typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : undefined;
42
+ var devToolsHook = _global && _global.__RELAY_DEVTOOLS_HOOK__;
43
+ if (devToolsHook) {
44
+ devToolsHook.registerEnvironment(this);
58
45
  }
59
46
  }
60
47
 
@@ -62,8 +49,8 @@ var RelayModernEnvironment = function () {
62
49
  return this._store;
63
50
  };
64
51
 
65
- RelayModernEnvironment.prototype.getDebugger = function getDebugger() {
66
- return this._debugger;
52
+ RelayModernEnvironment.prototype.getNetwork = function getNetwork() {
53
+ return this._network;
67
54
  };
68
55
 
69
56
  RelayModernEnvironment.prototype.applyUpdate = function applyUpdate(optimisticUpdate) {
@@ -129,47 +116,103 @@ var RelayModernEnvironment = function () {
129
116
  return this._store.retain(selector);
130
117
  };
131
118
 
119
+ RelayModernEnvironment.prototype.isSelectorLoading = function isSelectorLoading(selector) {
120
+ var key = require('./deferrableFragmentKey')(selector.dataID, selector.node.name, selector.variables);
121
+ return this._deferrableSelections.has(key);
122
+ };
132
123
  /**
133
- * Returns an Observable of RelayResponsePayload resulting from the provided
134
- * Query or Subscription operation, each of which are normalized and committed
135
- * to the publish queue.
124
+ * Returns an Observable of ExecutePayload resulting from executing the
125
+ * provided Query or Subscription operation, each result of which is then
126
+ * normalized and committed to the publish queue.
136
127
  *
137
128
  * Note: Observables are lazy, so calling this method will do nothing until
138
- * the result is subscribed to: environment.observe({...}).subscribe({...}).
129
+ * the result is subscribed to: environment.execute({...}).subscribe({...}).
139
130
  */
140
131
 
141
132
 
142
- RelayModernEnvironment.prototype.observe = function observe(_ref2) {
133
+ RelayModernEnvironment.prototype.execute = function execute(_ref2) {
143
134
  var _this3 = this;
144
135
 
145
136
  var operation = _ref2.operation,
146
137
  cacheConfig = _ref2.cacheConfig,
147
138
  updater = _ref2.updater;
148
- var node = operation.node,
149
- variables = operation.variables;
150
139
 
151
- return this._network.observe(node, variables, cacheConfig || {}).map(function (payload) {
152
- return require('./normalizePayload')(node, variables, payload);
153
- })['do']({
154
- next: function next(payload) {
155
- _this3._publishQueue.commitPayload(operation, payload, updater);
140
+ var optimisticResponse = void 0;
141
+ return this._network.execute(operation.node, operation.variables, cacheConfig || {})['do']({
142
+ next: function next(executePayload) {
143
+ var responsePayload = require('./normalizePayload')(executePayload);
144
+ var source = responsePayload.source,
145
+ fieldPayloads = responsePayload.fieldPayloads,
146
+ deferrableSelections = responsePayload.deferrableSelections;
147
+ var _iteratorNormalCompletion = true;
148
+ var _didIteratorError = false;
149
+ var _iteratorError = undefined;
150
+
151
+ try {
152
+ for (var _iterator = (deferrableSelections || new Set())[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
153
+ var selectionKey = _step.value;
154
+
155
+ _this3._deferrableSelections.add(selectionKey);
156
+ }
157
+ } catch (err) {
158
+ _didIteratorError = true;
159
+ _iteratorError = err;
160
+ } finally {
161
+ try {
162
+ if (!_iteratorNormalCompletion && _iterator['return']) {
163
+ _iterator['return']();
164
+ }
165
+ } finally {
166
+ if (_didIteratorError) {
167
+ throw _iteratorError;
168
+ }
169
+ }
170
+ }
171
+
172
+ if (executePayload.isOptimistic) {
173
+ require('fbjs/lib/invariant')(optimisticResponse == null, 'environment.execute: only support one optimistic respnose per ' + 'execute.');
174
+ optimisticResponse = {
175
+ source: source,
176
+ fieldPayloads: fieldPayloads
177
+ };
178
+ _this3._publishQueue.applyUpdate(optimisticResponse);
179
+ _this3._publishQueue.run();
180
+ } else {
181
+ if (optimisticResponse) {
182
+ _this3._publishQueue.revertUpdate(optimisticResponse);
183
+ optimisticResponse = undefined;
184
+ }
185
+ var writeSelector = createOperationSelector(operation.node, executePayload.variables, executePayload.operation);
186
+ if (executePayload.operation.kind === 'DeferrableOperation') {
187
+ var fragmentKey = require('./deferrableFragmentKey')(executePayload.variables[executePayload.operation.rootFieldVariable], executePayload.operation.fragmentName, executePayload.variables);
188
+ _this3._deferrableSelections['delete'](fragmentKey);
189
+ }
190
+ _this3._publishQueue.commitPayload(writeSelector, responsePayload, updater);
191
+ _this3._publishQueue.run();
192
+ }
193
+ }
194
+ })['finally'](function () {
195
+ if (optimisticResponse) {
196
+ _this3._publishQueue.revertUpdate(optimisticResponse);
197
+ optimisticResponse = undefined;
156
198
  _this3._publishQueue.run();
157
199
  }
158
200
  });
159
201
  };
160
202
 
161
203
  /**
162
- * Returns an Observable of RelayResponsePayload resulting from the provided
163
- * Mutation operation, which are normalized and committed to the publish queue
164
- * along with an optional optimistic response or updater.
204
+ * Returns an Observable of ExecutePayload resulting from executing the
205
+ * provided Mutation operation, the result of which is then normalized and
206
+ * committed to the publish queue along with an optional optimistic response
207
+ * or updater.
165
208
  *
166
209
  * Note: Observables are lazy, so calling this method will do nothing until
167
210
  * the result is subscribed to:
168
- * environment.observeMutation({...}).subscribe({...}).
211
+ * environment.executeMutation({...}).subscribe({...}).
169
212
  */
170
213
 
171
214
 
172
- RelayModernEnvironment.prototype.observeMutation = function observeMutation(_ref3) {
215
+ RelayModernEnvironment.prototype.executeMutation = function executeMutation(_ref3) {
173
216
  var _this4 = this;
174
217
 
175
218
  var operation = _ref3.operation,
@@ -177,10 +220,6 @@ var RelayModernEnvironment = function () {
177
220
  optimisticUpdater = _ref3.optimisticUpdater,
178
221
  updater = _ref3.updater,
179
222
  uploadables = _ref3.uploadables;
180
- var node = operation.node,
181
- variables = operation.variables;
182
-
183
- var mutationUid = nextMutationUid();
184
223
 
185
224
  var optimisticUpdate = void 0;
186
225
  if (optimisticResponse || optimisticUpdater) {
@@ -191,39 +230,20 @@ var RelayModernEnvironment = function () {
191
230
  };
192
231
  }
193
232
 
194
- return this._network.observe(node, variables, { force: true }, uploadables).map(function (payload) {
195
- return require('./normalizePayload')(node, variables, payload);
196
- })['do']({
233
+ return this._network.execute(operation.node, operation.variables, { force: true }, uploadables)['do']({
197
234
  start: function start() {
198
235
  if (optimisticUpdate) {
199
- _this4._recordDebuggerEvent({
200
- eventName: 'optimistic_update',
201
- mutationUid: mutationUid,
202
- operation: operation,
203
- fn: function fn() {
204
- if (optimisticUpdate) {
205
- _this4._publishQueue.applyUpdate(optimisticUpdate);
206
- }
207
- _this4._publishQueue.run();
208
- }
209
- });
236
+ _this4._publishQueue.applyUpdate(optimisticUpdate);
237
+ _this4._publishQueue.run();
210
238
  }
211
239
  },
212
240
  next: function next(payload) {
213
- _this4._recordDebuggerEvent({
214
- eventName: 'request_commit',
215
- mutationUid: mutationUid,
216
- operation: operation,
217
- payload: payload,
218
- fn: function fn() {
219
- if (optimisticUpdate) {
220
- _this4._publishQueue.revertUpdate(optimisticUpdate);
221
- optimisticUpdate = undefined;
222
- }
223
- _this4._publishQueue.commitPayload(operation, payload, updater);
224
- _this4._publishQueue.run();
225
- }
226
- });
241
+ if (optimisticUpdate) {
242
+ _this4._publishQueue.revertUpdate(optimisticUpdate);
243
+ optimisticUpdate = undefined;
244
+ }
245
+ _this4._publishQueue.commitPayload(operation, require('./normalizePayload')(payload), updater);
246
+ _this4._publishQueue.run();
227
247
  },
228
248
  error: function (_error) {
229
249
  function error(_x) {
@@ -236,39 +256,24 @@ var RelayModernEnvironment = function () {
236
256
 
237
257
  return error;
238
258
  }(function (error) {
239
- _this4._recordDebuggerEvent({
240
- eventName: 'request_error',
241
- mutationUid: mutationUid,
242
- operation: operation,
243
- payload: error,
244
- fn: function fn() {
245
- if (optimisticUpdate) {
246
- _this4._publishQueue.revertUpdate(optimisticUpdate);
247
- }
248
- _this4._publishQueue.run();
249
- }
250
- });
259
+ if (optimisticUpdate) {
260
+ _this4._publishQueue.revertUpdate(optimisticUpdate);
261
+ optimisticUpdate = undefined;
262
+ _this4._publishQueue.run();
263
+ }
251
264
  }),
252
265
  unsubscribe: function unsubscribe() {
253
266
  if (optimisticUpdate) {
254
- _this4._recordDebuggerEvent({
255
- eventName: 'optimistic_revert',
256
- mutationUid: mutationUid,
257
- operation: operation,
258
- fn: function fn() {
259
- if (optimisticUpdate) {
260
- _this4._publishQueue.revertUpdate(optimisticUpdate);
261
- }
262
- _this4._publishQueue.run();
263
- }
264
- });
267
+ _this4._publishQueue.revertUpdate(optimisticUpdate);
268
+ optimisticUpdate = undefined;
269
+ _this4._publishQueue.run();
265
270
  }
266
271
  }
267
272
  });
268
273
  };
269
274
 
270
275
  /**
271
- * @deprecated Use Environment.observe().subscribe()
276
+ * @deprecated Use Environment.execute().subscribe()
272
277
  */
273
278
 
274
279
 
@@ -279,7 +284,8 @@ var RelayModernEnvironment = function () {
279
284
  onNext = _ref4.onNext,
280
285
  operation = _ref4.operation;
281
286
 
282
- return this.observe({ operation: operation, cacheConfig: cacheConfig }).subscribeLegacy({
287
+ require('fbjs/lib/warning')(false, 'environment.sendQuery() is deprecated. Update to the latest ' + 'version of react-relay, and use environment.execute().');
288
+ return this.execute({ operation: operation, cacheConfig: cacheConfig }).subscribeLegacy({
283
289
  onNext: onNext,
284
290
  onError: onError,
285
291
  onCompleted: onCompleted
@@ -287,7 +293,7 @@ var RelayModernEnvironment = function () {
287
293
  };
288
294
 
289
295
  /**
290
- * @deprecated Use Environment.observe().subscribe()
296
+ * @deprecated Use Environment.execute().subscribe()
291
297
  */
292
298
 
293
299
 
@@ -298,7 +304,8 @@ var RelayModernEnvironment = function () {
298
304
  onNext = _ref5.onNext,
299
305
  operation = _ref5.operation;
300
306
 
301
- return this.observe({ operation: operation, cacheConfig: cacheConfig }).subscribeLegacy({
307
+ require('fbjs/lib/warning')(false, 'environment.streamQuery() is deprecated. Update to the latest ' + 'version of react-relay, and use environment.execute().');
308
+ return this.execute({ operation: operation, cacheConfig: cacheConfig }).subscribeLegacy({
302
309
  onNext: onNext,
303
310
  onError: onError,
304
311
  onCompleted: onCompleted
@@ -306,7 +313,7 @@ var RelayModernEnvironment = function () {
306
313
  };
307
314
 
308
315
  /**
309
- * @deprecated Use Environment.observeMutation().subscribe()
316
+ * @deprecated Use Environment.executeMutation().subscribe()
310
317
  */
311
318
 
312
319
 
@@ -319,7 +326,8 @@ var RelayModernEnvironment = function () {
319
326
  updater = _ref6.updater,
320
327
  uploadables = _ref6.uploadables;
321
328
 
322
- return this.observeMutation({
329
+ require('fbjs/lib/warning')(false, 'environment.sendMutation() is deprecated. Update to the latest ' + 'version of react-relay, and use environment.executeMutation().');
330
+ return this.executeMutation({
323
331
  operation: operation,
324
332
  optimisticResponse: optimisticResponse,
325
333
  optimisticUpdater: optimisticUpdater,
@@ -327,10 +335,10 @@ var RelayModernEnvironment = function () {
327
335
  uploadables: uploadables
328
336
  }).subscribeLegacy({
329
337
  // NOTE: sendMutation has a non-standard use of onCompleted() by passing
330
- // it a value. When switching to use observeMutation(), the next()
338
+ // it a value. When switching to use executeMutation(), the next()
331
339
  // Observer should be used to preserve behavior.
332
340
  onNext: function onNext(payload) {
333
- payload.errors && onCompleted && onCompleted(payload.errors);
341
+ onCompleted && onCompleted(payload.response.errors);
334
342
  },
335
343
  onError: onError,
336
344
  onCompleted: onCompleted
@@ -338,7 +346,7 @@ var RelayModernEnvironment = function () {
338
346
  };
339
347
 
340
348
  /**
341
- * @deprecated Use Environment.observe().subscribe()
349
+ * @deprecated Use Environment.execute().subscribe()
342
350
  */
343
351
 
344
352
 
@@ -349,33 +357,14 @@ var RelayModernEnvironment = function () {
349
357
  operation = _ref7.operation,
350
358
  updater = _ref7.updater;
351
359
 
352
- return this.observe({
360
+ require('fbjs/lib/warning')(false, 'environment.sendSubscription() is deprecated. Update to the latest ' + 'version of react-relay, and use environment.execute().');
361
+ return this.execute({
353
362
  operation: operation,
354
363
  updater: updater,
355
364
  cacheConfig: { force: true }
356
365
  }).subscribeLegacy({ onNext: onNext, onError: onError, onCompleted: onCompleted });
357
366
  };
358
367
 
359
- RelayModernEnvironment.prototype._recordDebuggerEvent = function _recordDebuggerEvent(_ref8) {
360
- var eventName = _ref8.eventName,
361
- mutationUid = _ref8.mutationUid,
362
- operation = _ref8.operation,
363
- payload = _ref8.payload,
364
- fn = _ref8.fn;
365
-
366
- if (this._debugger) {
367
- this._debugger.recordMutationEvent({
368
- eventName: eventName,
369
- payload: payload,
370
- fn: fn,
371
- mutation: operation,
372
- seriesId: mutationUid
373
- });
374
- } else {
375
- fn();
376
- }
377
- };
378
-
379
368
  RelayModernEnvironment.prototype.checkSelectorAndUpdateStore = function checkSelectorAndUpdateStore(selector, handlers) {
380
369
  var target = new (require('./RelayInMemoryRecordSource'))();
381
370
  var result = require('./RelayDataLoader').check(this._store.getSource(), target, selector, handlers);
@@ -389,15 +378,11 @@ var RelayModernEnvironment = function () {
389
378
  return RelayModernEnvironment;
390
379
  }();
391
380
 
392
- var mutationUidCounter = 0;
393
- var mutationUidPrefix = Math.random().toString();
394
- function nextMutationUid() {
395
- return mutationUidPrefix + mutationUidCounter++;
396
- }
397
-
398
381
  // Add a sigil for detection by `isRelayModernEnvironment()` to avoid a
399
382
  // realm-specific instanceof check, and to aid in module tree-shaking to
400
383
  // avoid requiring all of RelayRuntime just to detect its environment.
384
+
385
+
401
386
  RelayModernEnvironment.prototype['@@RelayModernEnvironment'] = true;
402
387
 
403
388
  module.exports = RelayModernEnvironment;