relay-runtime 18.2.0 → 20.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 (83) hide show
  1. package/experimental.js +1 -1
  2. package/experimental.js.flow +8 -6
  3. package/index.js +1 -1
  4. package/index.js.flow +3 -0
  5. package/lib/experimental.js +5 -2
  6. package/lib/index.js +3 -0
  7. package/lib/multi-actor-environment/ActorSpecificEnvironment.js +1 -1
  8. package/lib/mutations/RelayRecordSourceProxy.js +2 -1
  9. package/lib/mutations/createUpdatableProxy.js +1 -1
  10. package/lib/mutations/validateMutation.js +2 -2
  11. package/lib/network/RelayObservable.js +1 -3
  12. package/lib/network/wrapNetworkWithLogObserver.js +2 -2
  13. package/lib/query/fetchQuery.js +1 -1
  14. package/lib/store/DataChecker.js +12 -8
  15. package/lib/store/OperationExecutor.js +93 -43
  16. package/lib/store/RelayModernEnvironment.js +13 -4
  17. package/lib/store/RelayModernFragmentSpecResolver.js +4 -4
  18. package/lib/store/RelayModernStore.js +49 -24
  19. package/lib/store/RelayPublishQueue.js +11 -15
  20. package/lib/store/RelayReader.js +134 -151
  21. package/lib/store/RelayReferenceMarker.js +14 -7
  22. package/lib/store/RelayResponseNormalizer.js +57 -31
  23. package/lib/store/RelayStoreSubscriptions.js +2 -2
  24. package/lib/store/RelayStoreUtils.js +8 -0
  25. package/lib/store/ResolverFragments.js +2 -2
  26. package/lib/store/createRelayLoggingContext.js +17 -0
  27. package/lib/store/generateTypenamePrefixedDataID.js +9 -0
  28. package/lib/store/live-resolvers/LiveResolverCache.js +4 -2
  29. package/lib/store/live-resolvers/resolverDataInjector.js +4 -4
  30. package/lib/store/normalizeResponse.js +2 -2
  31. package/lib/store/observeFragmentExperimental.js +60 -13
  32. package/lib/store/observeQueryExperimental.js +21 -0
  33. package/lib/util/RelayFeatureFlags.js +7 -1
  34. package/lib/util/handlePotentialSnapshotErrors.js +11 -8
  35. package/multi-actor-environment/ActorSpecificEnvironment.js.flow +1 -0
  36. package/mutations/RelayRecordSourceProxy.js.flow +4 -0
  37. package/mutations/createUpdatableProxy.js.flow +1 -1
  38. package/mutations/validateMutation.js.flow +3 -3
  39. package/network/RelayNetworkTypes.js.flow +3 -0
  40. package/network/RelayObservable.js.flow +1 -5
  41. package/network/wrapNetworkWithLogObserver.js.flow +19 -1
  42. package/package.json +1 -1
  43. package/query/fetchQuery.js.flow +1 -1
  44. package/store/DataChecker.js.flow +16 -4
  45. package/store/OperationExecutor.js.flow +101 -15
  46. package/store/RelayExperimentalGraphResponseTransform.js.flow +4 -4
  47. package/store/RelayModernEnvironment.js.flow +22 -6
  48. package/store/RelayModernFragmentSpecResolver.js.flow +6 -6
  49. package/store/RelayModernSelector.js.flow +2 -0
  50. package/store/RelayModernStore.js.flow +86 -27
  51. package/store/RelayPublishQueue.js.flow +32 -21
  52. package/store/RelayReader.js.flow +168 -97
  53. package/store/RelayReferenceMarker.js.flow +15 -5
  54. package/store/RelayResponseNormalizer.js.flow +104 -69
  55. package/store/RelayStoreSubscriptions.js.flow +2 -2
  56. package/store/RelayStoreTypes.js.flow +34 -4
  57. package/store/RelayStoreUtils.js.flow +29 -0
  58. package/store/ResolverCache.js.flow +2 -2
  59. package/store/ResolverFragments.js.flow +5 -3
  60. package/store/StoreInspector.js.flow +5 -0
  61. package/store/createRelayContext.js.flow +3 -2
  62. package/store/createRelayLoggingContext.js.flow +46 -0
  63. package/store/generateTypenamePrefixedDataID.js.flow +25 -0
  64. package/store/live-resolvers/LiveResolverCache.js.flow +7 -2
  65. package/store/live-resolvers/resolverDataInjector.js.flow +10 -6
  66. package/store/normalizeResponse.js.flow +2 -0
  67. package/store/observeFragmentExperimental.js.flow +82 -28
  68. package/store/observeQueryExperimental.js.flow +61 -0
  69. package/store/waitForFragmentExperimental.js.flow +4 -3
  70. package/util/NormalizationNode.js.flow +2 -1
  71. package/util/RelayConcreteNode.js.flow +2 -0
  72. package/util/RelayError.js.flow +1 -0
  73. package/util/RelayFeatureFlags.js.flow +28 -0
  74. package/util/RelayRuntimeTypes.js.flow +6 -3
  75. package/util/getPaginationVariables.js.flow +2 -0
  76. package/util/handlePotentialSnapshotErrors.js.flow +23 -11
  77. package/util/registerEnvironmentWithDevTools.js.flow +4 -2
  78. package/util/withProvidedVariables.js.flow +1 -0
  79. package/util/withStartAndDuration.js.flow +3 -0
  80. package/relay-runtime-experimental.js +0 -4
  81. package/relay-runtime-experimental.min.js +0 -9
  82. package/relay-runtime.js +0 -4
  83. package/relay-runtime.min.js +0 -9
@@ -14,13 +14,14 @@ var defaultGetDataID = require('./defaultGetDataID');
14
14
  var defaultRelayFieldLogger = require('./defaultRelayFieldLogger');
15
15
  var normalizeResponse = require('./normalizeResponse');
16
16
  var OperationExecutor = require('./OperationExecutor');
17
+ var RelayModernStore = require('./RelayModernStore');
17
18
  var RelayPublishQueue = require('./RelayPublishQueue');
18
19
  var RelayRecordSource = require('./RelayRecordSource');
19
20
  var invariant = require('invariant');
20
21
  var RelayModernEnvironment = /*#__PURE__*/function () {
21
22
  function RelayModernEnvironment(config) {
22
23
  var _this = this;
23
- var _config$log, _config$relayFieldLog, _config$UNSTABLE_defa, _config$getDataID, _config$missingFieldH, _config$handlerProvid, _config$scheduler, _config$isServer, _config$normalizeResp, _config$operationTrac;
24
+ var _config$store, _config$log, _config$relayFieldLog, _config$UNSTABLE_defa, _config$getDataID, _config$missingFieldH, _config$handlerProvid, _config$scheduler, _config$isServer, _config$normalizeResp, _config$operationTrac;
24
25
  this.configName = config.configName;
25
26
  this._treatMissingFieldsAsNull = config.treatMissingFieldsAsNull === true;
26
27
  var operationLoader = config.operationLoader;
@@ -29,6 +30,12 @@ var RelayModernEnvironment = /*#__PURE__*/function () {
29
30
  !(typeof operationLoader === 'object' && typeof operationLoader.get === 'function' && typeof operationLoader.load === 'function') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected `operationLoader` to be an object ' + 'with get() and load() functions, got `%s`.', operationLoader) : invariant(false) : void 0;
30
31
  }
31
32
  }
33
+ var store = (_config$store = config.store) !== null && _config$store !== void 0 ? _config$store : new RelayModernStore(new RelayRecordSource(), {
34
+ log: config.log,
35
+ operationLoader: config.operationLoader,
36
+ getDataID: config.getDataID,
37
+ shouldProcessClientComponents: config.shouldProcessClientComponents
38
+ });
32
39
  this.__log = (_config$log = config.log) !== null && _config$log !== void 0 ? _config$log : emptyFunction;
33
40
  this.relayFieldLogger = (_config$relayFieldLog = config.relayFieldLogger) !== null && _config$relayFieldLog !== void 0 ? _config$relayFieldLog : defaultRelayFieldLogger;
34
41
  this._defaultRenderPolicy = (_config$UNSTABLE_defa = config.UNSTABLE_defaultRenderPolicy) !== null && _config$UNSTABLE_defa !== void 0 ? _config$UNSTABLE_defa : 'partial';
@@ -37,9 +44,9 @@ var RelayModernEnvironment = /*#__PURE__*/function () {
37
44
  this._network = wrapNetworkWithLogObserver(this, config.network);
38
45
  this._getDataID = (_config$getDataID = config.getDataID) !== null && _config$getDataID !== void 0 ? _config$getDataID : defaultGetDataID;
39
46
  this._missingFieldHandlers = (_config$missingFieldH = config.missingFieldHandlers) !== null && _config$missingFieldH !== void 0 ? _config$missingFieldH : [];
40
- this._publishQueue = new RelayPublishQueue(config.store, (_config$handlerProvid = config.handlerProvider) !== null && _config$handlerProvid !== void 0 ? _config$handlerProvid : RelayDefaultHandlerProvider, this._getDataID, this._missingFieldHandlers);
47
+ this._publishQueue = new RelayPublishQueue(store, (_config$handlerProvid = config.handlerProvider) !== null && _config$handlerProvid !== void 0 ? _config$handlerProvid : RelayDefaultHandlerProvider, this._getDataID, this._missingFieldHandlers, this.__log);
41
48
  this._scheduler = (_config$scheduler = config.scheduler) !== null && _config$scheduler !== void 0 ? _config$scheduler : null;
42
- this._store = config.store;
49
+ this._store = store;
43
50
  this.options = config.options;
44
51
  this._isServer = (_config$isServer = config.isServer) !== null && _config$isServer !== void 0 ? _config$isServer : false;
45
52
  this._normalizeResponse = (_config$normalizeResp = config.normalizeResponse) !== null && _config$normalizeResp !== void 0 ? _config$normalizeResp : normalizeResponse;
@@ -199,7 +206,9 @@ var RelayModernEnvironment = /*#__PURE__*/function () {
199
206
  var operation = _ref.operation;
200
207
  return this._execute({
201
208
  createSource: function createSource() {
202
- return _this7.getNetwork().execute(operation.request.node.params, operation.request.variables, operation.request.cacheConfig || {}, null);
209
+ return _this7.getNetwork().execute(operation.request.node.params, operation.request.variables, operation.request.cacheConfig || {}, null, undefined, undefined, undefined, function () {
210
+ return _this7.check(operation);
211
+ });
203
212
  },
204
213
  isClientPayload: false,
205
214
  operation: operation,
@@ -132,14 +132,14 @@ var SelectorResolver = /*#__PURE__*/function () {
132
132
  (0, _defineProperty2["default"])(this, "_onChange", function (snapshot) {
133
133
  _this2._data = snapshot.data;
134
134
  _this2._isMissingData = snapshot.isMissingData;
135
- _this2._errorResponseFields = snapshot.errorResponseFields;
135
+ _this2._fieldErrors = snapshot.fieldErrors;
136
136
  _this2._callback();
137
137
  });
138
138
  var _snapshot = environment.lookup(selector);
139
139
  this._callback = callback;
140
140
  this._data = _snapshot.data;
141
141
  this._isMissingData = _snapshot.isMissingData;
142
- this._errorResponseFields = _snapshot.errorResponseFields;
142
+ this._fieldErrors = _snapshot.fieldErrors;
143
143
  this._environment = environment;
144
144
  this._rootIsQueryRenderer = rootIsQueryRenderer;
145
145
  this._selector = selector;
@@ -182,7 +182,7 @@ var SelectorResolver = /*#__PURE__*/function () {
182
182
  }
183
183
  }
184
184
  }
185
- handlePotentialSnapshotErrors(this._environment, this._errorResponseFields);
185
+ handlePotentialSnapshotErrors(this._environment, this._fieldErrors);
186
186
  return this._data;
187
187
  };
188
188
  _proto2.setSelector = function setSelector(selector) {
@@ -193,7 +193,7 @@ var SelectorResolver = /*#__PURE__*/function () {
193
193
  var snapshot = this._environment.lookup(selector);
194
194
  this._data = recycleNodesInto(this._data, snapshot.data);
195
195
  this._isMissingData = snapshot.isMissingData;
196
- this._errorResponseFields = snapshot.errorResponseFields;
196
+ this._fieldErrors = snapshot.fieldErrors;
197
197
  this._selector = selector;
198
198
  this._subscription = this._environment.subscribe(snapshot, this._onChange);
199
199
  };
@@ -28,7 +28,7 @@ var DEFAULT_RELEASE_BUFFER_SIZE = 10;
28
28
  var RelayModernStore = /*#__PURE__*/function () {
29
29
  function RelayModernStore(source, options) {
30
30
  var _this = this;
31
- var _options$gcReleaseBuf, _options$gcScheduler, _options$getDataID, _options$log, _options$operationLoa, _options$shouldProces, _options$treatMissing;
31
+ var _options$gcReleaseBuf, _options$shouldRetain, _options$gcScheduler, _options$getDataID, _options$log, _options$operationLoa, _options$shouldProces, _options$treatMissing;
32
32
  (0, _defineProperty2["default"])(this, "_gcStep", function () {
33
33
  if (_this._gcRun) {
34
34
  if (_this._gcRun.next().done) {
@@ -50,6 +50,7 @@ var RelayModernStore = /*#__PURE__*/function () {
50
50
  this._currentWriteEpoch = 0;
51
51
  this._gcHoldCounter = 0;
52
52
  this._gcReleaseBufferSize = (_options$gcReleaseBuf = options === null || options === void 0 ? void 0 : options.gcReleaseBufferSize) !== null && _options$gcReleaseBuf !== void 0 ? _options$gcReleaseBuf : DEFAULT_RELEASE_BUFFER_SIZE;
53
+ this._shouldRetainWithinTTL_EXPERIMENTAL = (_options$shouldRetain = options === null || options === void 0 ? void 0 : options.shouldRetainWithinTTL_EXPERIMENTAL) !== null && _options$shouldRetain !== void 0 ? _options$shouldRetain : false;
53
54
  this._gcRun = null;
54
55
  this._gcScheduler = (_options$gcScheduler = options === null || options === void 0 ? void 0 : options.gcScheduler) !== null && _options$gcScheduler !== void 0 ? _options$gcScheduler : resolveImmediate;
55
56
  this._getDataID = (_options$getDataID = options === null || options === void 0 ? void 0 : options.getDataID) !== null && _options$getDataID !== void 0 ? _options$getDataID : defaultGetDataID;
@@ -67,10 +68,10 @@ var RelayModernStore = /*#__PURE__*/function () {
67
68
  this._resolverCache = new LiveResolverCache(function () {
68
69
  return _this._getMutableRecordSource();
69
70
  }, this);
70
- this._storeSubscriptions = new RelayStoreSubscriptions(options === null || options === void 0 ? void 0 : options.log, this._resolverCache);
71
+ this._resolverContext = options === null || options === void 0 ? void 0 : options.resolverContext;
72
+ this._storeSubscriptions = new RelayStoreSubscriptions(options === null || options === void 0 ? void 0 : options.log, this._resolverCache, this._resolverContext);
71
73
  this._updatedRecordIDs = new Set();
72
74
  this._shouldProcessClientComponents = (_options$shouldProces = options === null || options === void 0 ? void 0 : options.shouldProcessClientComponents) !== null && _options$shouldProces !== void 0 ? _options$shouldProces : false;
73
- this._resolverContext = options === null || options === void 0 ? void 0 : options.resolverContext;
74
75
  this._treatMissingFieldsAsNull = (_options$treatMissing = options === null || options === void 0 ? void 0 : options.treatMissingFieldsAsNull) !== null && _options$treatMissing !== void 0 ? _options$treatMissing : false;
75
76
  this._actorIdentifier = options === null || options === void 0 ? void 0 : options.actorIdentifier;
76
77
  initializeRecordSource(this._recordSource);
@@ -107,10 +108,11 @@ var RelayModernStore = /*#__PURE__*/function () {
107
108
  }
108
109
  };
109
110
  _proto.check = function check(operation, options) {
110
- var _options$handlers, _options$getSourceFor, _options$getTargetFor, _options$defaultActor;
111
+ var _ref, _operation$request$no, _operation$request$no2, _options$handlers, _options$getSourceFor, _options$getTargetFor, _options$defaultActor;
111
112
  var selector = operation.root;
112
113
  var source = this._getMutableRecordSource();
113
114
  var globalInvalidationEpoch = this._globalInvalidationEpoch;
115
+ var useExecTimeResolvers = (_ref = (_operation$request$no = operation.request.node.operation.use_exec_time_resolvers) !== null && _operation$request$no !== void 0 ? _operation$request$no : ((_operation$request$no2 = operation.request.node.operation.exec_time_resolvers_enabled_provider) === null || _operation$request$no2 === void 0 ? void 0 : _operation$request$no2.get()) === true) !== null && _ref !== void 0 ? _ref : false;
114
116
  var rootEntry = this._roots.get(operation.request.identifier);
115
117
  var operationLastWrittenAt = rootEntry != null ? rootEntry.epoch : null;
116
118
  if (globalInvalidationEpoch != null) {
@@ -129,7 +131,7 @@ var RelayModernStore = /*#__PURE__*/function () {
129
131
  assertInternalActorIdentifier(actorIdentifier);
130
132
  return source;
131
133
  };
132
- var operationAvailability = DataChecker.check(getSourceForActor, getTargetForActor, (_options$defaultActor = options === null || options === void 0 ? void 0 : options.defaultActorIdentifier) !== null && _options$defaultActor !== void 0 ? _options$defaultActor : INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE, selector, handlers, this._operationLoader, this._getDataID, this._shouldProcessClientComponents, this.__log);
134
+ var operationAvailability = DataChecker.check(getSourceForActor, getTargetForActor, (_options$defaultActor = options === null || options === void 0 ? void 0 : options.defaultActorIdentifier) !== null && _options$defaultActor !== void 0 ? _options$defaultActor : INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE, selector, handlers, this._operationLoader, this._getDataID, this._shouldProcessClientComponents, this.__log, useExecTimeResolvers);
133
135
  return getAvailabilityStatus(operationAvailability, operationLastWrittenAt, rootEntry === null || rootEntry === void 0 ? void 0 : rootEntry.fetchTime, this._queryCacheExpirationTime);
134
136
  };
135
137
  _proto.retain = function retain(operation) {
@@ -150,13 +152,17 @@ var RelayModernStore = /*#__PURE__*/function () {
150
152
  var _queryCacheExpirationTime = _this2._queryCacheExpirationTime;
151
153
  var rootEntryIsStale = rootEntry.fetchTime != null && _queryCacheExpirationTime != null && rootEntry.fetchTime <= Date.now() - _queryCacheExpirationTime;
152
154
  if (rootEntryIsStale) {
153
- _this2._roots["delete"](id);
155
+ if (!_this2._shouldRetainWithinTTL_EXPERIMENTAL) {
156
+ _this2._roots["delete"](id);
157
+ }
154
158
  _this2.scheduleGC();
155
159
  } else {
156
160
  _this2._releaseBuffer.push(id);
157
161
  if (_this2._releaseBuffer.length > _this2._gcReleaseBufferSize) {
158
162
  var _id = _this2._releaseBuffer.shift();
159
- _this2._roots["delete"](_id);
163
+ if (!_this2._shouldRetainWithinTTL_EXPERIMENTAL) {
164
+ _this2._roots["delete"](_id);
165
+ }
160
166
  _this2.scheduleGC();
161
167
  }
162
168
  }
@@ -414,6 +420,9 @@ var RelayModernStore = /*#__PURE__*/function () {
414
420
  while (!gcRun.next().done) {}
415
421
  };
416
422
  _proto._collect = function* _collect() {
423
+ if (this._shouldRetainWithinTTL_EXPERIMENTAL && this._queryCacheExpirationTime == null) {
424
+ return;
425
+ }
417
426
  var log = this.__log;
418
427
  top: while (true) {
419
428
  if (log != null) {
@@ -423,13 +432,29 @@ var RelayModernStore = /*#__PURE__*/function () {
423
432
  }
424
433
  var startEpoch = this._currentWriteEpoch;
425
434
  var references = new Set();
426
- var _iterator2 = (0, _createForOfIteratorHelper2["default"])(this._roots.values()),
435
+ var _iterator2 = (0, _createForOfIteratorHelper2["default"])(this._roots.entries()),
427
436
  _step2;
428
437
  try {
429
438
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
430
- var operation = _step2.value.operation;
439
+ var _ref2, _operation$request$no3, _operation$request$no4;
440
+ var _step2$value = _step2.value,
441
+ _dataID = _step2$value[0],
442
+ _step2$value$ = _step2$value[1],
443
+ operation = _step2$value$.operation,
444
+ refCount = _step2$value$.refCount,
445
+ fetchTime = _step2$value$.fetchTime;
446
+ if (this._shouldRetainWithinTTL_EXPERIMENTAL) {
447
+ var _queryCacheExpirationTime = this._queryCacheExpirationTime;
448
+ !(_queryCacheExpirationTime != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Query cache expiration time should be non-null if executing GC') : invariant(false) : void 0;
449
+ var recordHasExpired = fetchTime == null || fetchTime <= Date.now() - _queryCacheExpirationTime;
450
+ var recordShouldBeCollected = recordHasExpired && refCount === 0 && !this._releaseBuffer.includes(_dataID);
451
+ if (recordShouldBeCollected) {
452
+ continue;
453
+ }
454
+ }
431
455
  var selector = operation.root;
432
- RelayReferenceMarker.mark(this._recordSource, selector, references, this._operationLoader, this._shouldProcessClientComponents);
456
+ var useExecTimeResolvers = (_ref2 = (_operation$request$no3 = operation.request.node.operation.use_exec_time_resolvers) !== null && _operation$request$no3 !== void 0 ? _operation$request$no3 : ((_operation$request$no4 = operation.request.node.operation.exec_time_resolvers_enabled_provider) === null || _operation$request$no4 === void 0 ? void 0 : _operation$request$no4.get()) === true) !== null && _ref2 !== void 0 ? _ref2 : false;
457
+ RelayReferenceMarker.mark(this._recordSource, selector, references, this._operationLoader, this._shouldProcessClientComponents, useExecTimeResolvers);
433
458
  yield;
434
459
  if (startEpoch !== this._currentWriteEpoch) {
435
460
  if (log != null) {
@@ -445,21 +470,20 @@ var RelayModernStore = /*#__PURE__*/function () {
445
470
  } finally {
446
471
  _iterator2.f();
447
472
  }
448
- if (references.size === 0) {
449
- this._recordSource.clear();
450
- } else {
451
- var storeIDs = this._recordSource.getRecordIDs();
452
- for (var ii = 0; ii < storeIDs.length; ii++) {
453
- var dataID = storeIDs[ii];
454
- if (!references.has(dataID)) {
455
- var record = this._recordSource.get(dataID);
456
- if (record != null) {
457
- var maybeResolverSubscription = RelayModernRecord.getValue(record, RELAY_RESOLVER_LIVE_STATE_SUBSCRIPTION_KEY);
458
- if (maybeResolverSubscription != null) {
459
- maybeResolverSubscription();
460
- }
473
+ var storeIDs = this._recordSource.getRecordIDs();
474
+ for (var ii = 0; ii < storeIDs.length; ii++) {
475
+ var dataID = storeIDs[ii];
476
+ if (!references.has(dataID)) {
477
+ var record = this._recordSource.get(dataID);
478
+ if (record != null) {
479
+ var maybeResolverSubscription = RelayModernRecord.getValue(record, RELAY_RESOLVER_LIVE_STATE_SUBSCRIPTION_KEY);
480
+ if (maybeResolverSubscription != null) {
481
+ maybeResolverSubscription();
461
482
  }
462
- this._recordSource.remove(dataID);
483
+ }
484
+ this._recordSource.remove(dataID);
485
+ if (this._shouldRetainWithinTTL_EXPERIMENTAL) {
486
+ this._roots["delete"](dataID);
463
487
  }
464
488
  }
465
489
  }
@@ -476,6 +500,7 @@ var RelayModernStore = /*#__PURE__*/function () {
476
500
  return {
477
501
  path: path,
478
502
  getDataID: this._getDataID,
503
+ log: this.__log,
479
504
  treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
480
505
  shouldProcessClientComponents: this._shouldProcessClientComponents,
481
506
  actorIdentifier: this._actorIdentifier
@@ -4,6 +4,7 @@ var _global$ErrorUtils$ap, _global$ErrorUtils;
4
4
  var RelayRecordSourceMutator = require('../mutations/RelayRecordSourceMutator');
5
5
  var RelayRecordSourceProxy = require('../mutations/RelayRecordSourceProxy');
6
6
  var RelayRecordSourceSelectorProxy = require('../mutations/RelayRecordSourceSelectorProxy');
7
+ var RelayFeatureFlags = require('../util/RelayFeatureFlags');
7
8
  var RelayReader = require('./RelayReader');
8
9
  var RelayRecordSource = require('./RelayRecordSource');
9
10
  var invariant = require('invariant');
@@ -13,7 +14,7 @@ var applyWithGuard = (_global$ErrorUtils$ap = _global === null || _global === vo
13
14
  return callback.apply(context, args);
14
15
  };
15
16
  var RelayPublishQueue = /*#__PURE__*/function () {
16
- function RelayPublishQueue(store, handlerProvider, getDataID, missingFieldHandlers) {
17
+ function RelayPublishQueue(store, handlerProvider, getDataID, missingFieldHandlers, log) {
17
18
  this._hasStoreSnapshot = false;
18
19
  this._handlerProvider = handlerProvider || null;
19
20
  this._pendingBackupRebase = false;
@@ -24,6 +25,7 @@ var RelayPublishQueue = /*#__PURE__*/function () {
24
25
  this._gcHold = null;
25
26
  this._getDataID = getDataID;
26
27
  this._missingFieldHandlers = missingFieldHandlers;
28
+ this._log = log;
27
29
  }
28
30
  var _proto = RelayPublishQueue.prototype;
29
31
  _proto.applyUpdate = function applyUpdate(updater) {
@@ -69,15 +71,11 @@ var RelayPublishQueue = /*#__PURE__*/function () {
69
71
  _proto.run = function run(sourceOperation) {
70
72
  var runWillClearGcHold = this._appliedOptimisticUpdates === 0 && !!this._gcHold;
71
73
  var runIsANoop = !this._pendingBackupRebase && this._pendingOptimisticUpdates.size === 0 && !runWillClearGcHold;
72
- if (process.env.NODE_ENV !== "production") {
73
- process.env.NODE_ENV !== "production" ? warning(!runIsANoop, 'RelayPublishQueue.run was called, but the call would have been a noop.') : void 0;
74
- process.env.NODE_ENV !== "production" ? warning(this._isRunning !== true, 'A store update was detected within another store update. Please ' + "make sure new store updates aren't being executed within an " + 'updater function for a different update.') : void 0;
75
- this._isRunning = true;
76
- }
74
+ process.env.NODE_ENV !== "production" ? warning(!runIsANoop, 'RelayPublishQueue.run was called, but the call would have been a noop.') : void 0;
75
+ RelayFeatureFlags.DISALLOW_NESTED_UPDATES ? !(this._isRunning !== true) ? process.env.NODE_ENV !== "production" ? invariant(false, 'A store update was detected within another store update. Please ' + "make sure new store updates aren't being executed within an " + 'updater function for a different update.') : invariant(false) : void 0 : process.env.NODE_ENV !== "production" ? warning(this._isRunning !== true, 'A store update was detected within another store update. Please ' + "make sure new store updates aren't being executed within an " + 'updater function for a different update.') : void 0;
76
+ this._isRunning = true;
77
77
  if (runIsANoop) {
78
- if (process.env.NODE_ENV !== "production") {
79
- this._isRunning = false;
80
- }
78
+ this._isRunning = false;
81
79
  return [];
82
80
  }
83
81
  if (this._pendingBackupRebase) {
@@ -105,9 +103,7 @@ var RelayPublishQueue = /*#__PURE__*/function () {
105
103
  this._gcHold = null;
106
104
  }
107
105
  }
108
- if (process.env.NODE_ENV !== "production") {
109
- this._isRunning = false;
110
- }
106
+ this._isRunning = false;
111
107
  return this._store.notify(sourceOperation, invalidatedStore);
112
108
  };
113
109
  _proto._publishSourceFromPayload = function _publishSourceFromPayload(pendingPayload) {
@@ -118,7 +114,7 @@ var RelayPublishQueue = /*#__PURE__*/function () {
118
114
  var source = payload.source,
119
115
  fieldPayloads = payload.fieldPayloads;
120
116
  var mutator = new RelayRecordSourceMutator(this._store.getSource(), source);
121
- var recordSourceProxy = new RelayRecordSourceProxy(mutator, this._getDataID, this._handlerProvider, this._missingFieldHandlers);
117
+ var recordSourceProxy = new RelayRecordSourceProxy(mutator, this._getDataID, this._handlerProvider, this._missingFieldHandlers, this._log);
122
118
  if (fieldPayloads && fieldPayloads.length) {
123
119
  fieldPayloads.forEach(function (fieldPayload) {
124
120
  var handler = _this._handlerProvider && _this._handlerProvider(fieldPayload.handle);
@@ -154,7 +150,7 @@ var RelayPublishQueue = /*#__PURE__*/function () {
154
150
  var updater = data.updater;
155
151
  var sink = RelayRecordSource.create();
156
152
  var mutator = new RelayRecordSourceMutator(_this2._store.getSource(), sink);
157
- var recordSourceProxy = new RelayRecordSourceProxy(mutator, _this2._getDataID, _this2._handlerProvider, _this2._missingFieldHandlers);
153
+ var recordSourceProxy = new RelayRecordSourceProxy(mutator, _this2._getDataID, _this2._handlerProvider, _this2._missingFieldHandlers, _this2._log);
158
154
  applyWithGuard(updater, null, [recordSourceProxy], null, 'RelayPublishQueue:commitData');
159
155
  invalidatedStore = invalidatedStore || recordSourceProxy.isStoreMarkedForInvalidation();
160
156
  var idsMarkedForInvalidation = recordSourceProxy.getIDsMarkedForInvalidation();
@@ -168,7 +164,7 @@ var RelayPublishQueue = /*#__PURE__*/function () {
168
164
  var _this3 = this;
169
165
  var sink = RelayRecordSource.create();
170
166
  var mutator = new RelayRecordSourceMutator(this._store.getSource(), sink);
171
- var recordSourceProxy = new RelayRecordSourceProxy(mutator, this._getDataID, this._handlerProvider, this._missingFieldHandlers);
167
+ var recordSourceProxy = new RelayRecordSourceProxy(mutator, this._getDataID, this._handlerProvider, this._missingFieldHandlers, this._log);
172
168
  var processUpdate = function processUpdate(optimisticUpdate) {
173
169
  if (optimisticUpdate.storeUpdater) {
174
170
  var storeUpdater = optimisticUpdate.storeUpdater;