relay-runtime 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.
- package/index.js +1 -1
- package/lib/{generateRelayClientID.js → ClientID.js} +10 -3
- package/lib/ConvertToExecuteFunction.js +6 -4
- package/lib/DataChecker.js +88 -69
- package/lib/NormalizationNode.js +1 -1
- package/lib/ReaderNode.js +1 -1
- package/lib/RelayCombinedEnvironmentTypes.js +1 -1
- package/lib/RelayConcreteNode.js +5 -2
- package/lib/RelayConcreteVariables.js +15 -9
- package/lib/RelayConnectionHandler.js +27 -20
- package/lib/RelayConnectionInterface.js +4 -2
- package/lib/RelayCore.js +48 -15
- package/lib/RelayDeclarativeMutationConfig.js +16 -15
- package/lib/RelayDefaultHandleKey.js +1 -1
- package/lib/RelayDefaultHandlerProvider.js +7 -6
- package/lib/RelayDefaultMissingFieldHandlers.js +26 -0
- package/lib/RelayError.js +7 -2
- package/lib/RelayFeatureFlags.js +16 -0
- package/lib/RelayInMemoryRecordSource.js +8 -2
- package/lib/RelayModernEnvironment.js +159 -237
- package/lib/RelayModernFragmentOwner.js +72 -0
- package/lib/RelayModernFragmentSpecResolver.js +66 -15
- package/lib/RelayModernGraphQLTag.js +9 -5
- package/lib/RelayModernOperationDescriptor.js +9 -6
- package/lib/RelayModernQueryExecutor.js +791 -0
- package/lib/RelayModernRecord.js +44 -24
- package/lib/RelayModernSelector.js +208 -82
- package/lib/RelayModernStore.js +66 -34
- package/lib/RelayNetwork.js +14 -7
- package/lib/RelayNetworkLogger.js +6 -2
- package/lib/RelayNetworkLoggerTransaction.js +8 -4
- package/lib/RelayNetworkTypes.js +1 -1
- package/lib/RelayObservable.js +72 -41
- package/lib/RelayOperationTracker.js +265 -0
- package/lib/RelayProfiler.js +10 -6
- package/lib/RelayPublishQueue.js +66 -47
- package/lib/RelayQueryResponseCache.js +11 -5
- package/lib/RelayReader.js +135 -126
- package/lib/RelayRecordProxy.js +24 -20
- package/lib/RelayRecordSourceMutator.js +88 -25
- package/lib/RelayRecordSourceProxy.js +38 -19
- package/lib/RelayRecordSourceSelectorProxy.js +10 -7
- package/lib/RelayRecordState.js +1 -1
- package/lib/RelayReferenceMarker.js +66 -55
- package/lib/RelayReplaySubject.js +134 -0
- package/lib/RelayResponseNormalizer.js +245 -134
- package/lib/RelayRuntimeTypes.js +1 -1
- package/lib/RelayStoreUtils.js +55 -16
- package/lib/RelayViewerHandler.js +8 -50
- package/lib/StoreInspector.js +171 -0
- package/lib/applyRelayModernOptimisticMutation.js +8 -2
- package/lib/cloneRelayHandleSourceField.js +17 -7
- package/lib/commitLocalUpdate.js +1 -1
- package/lib/commitRelayModernMutation.js +33 -13
- package/lib/createRelayContext.js +27 -0
- package/lib/createRelayNetworkLogger.js +8 -2
- package/lib/deepFreeze.js +1 -1
- package/lib/defaultGetDataID.js +24 -0
- package/lib/fetchQueryInternal.js +232 -0
- package/lib/fetchRelayModernQuery.js +5 -3
- package/lib/getFragmentIdentifier.js +52 -0
- package/lib/getFragmentSpecIdentifier.js +26 -0
- package/lib/getRelayHandleKey.js +8 -2
- package/lib/getRequestParametersIdentifier.js +26 -0
- package/lib/hasOverlappingIDs.js +1 -1
- package/lib/index.js +155 -53
- package/lib/isPromise.js +1 -1
- package/lib/isScalarAndEqual.js +1 -1
- package/lib/normalizeRelayPayload.js +19 -10
- package/lib/recycleNodesInto.js +23 -5
- package/lib/requestRelaySubscription.js +9 -3
- package/lib/validateMutation.js +13 -6
- package/package.json +2 -2
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/lib/normalizePayload.js +0 -37
- package/lib/simpleClone.js +0 -27
|
@@ -10,31 +10,76 @@
|
|
|
10
10
|
*/
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
14
|
+
|
|
15
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
|
|
16
|
+
|
|
17
|
+
var DataChecker = require("./DataChecker");
|
|
18
|
+
|
|
19
|
+
var RelayCore = require("./RelayCore");
|
|
20
|
+
|
|
21
|
+
var RelayDefaultHandlerProvider = require("./RelayDefaultHandlerProvider");
|
|
22
|
+
|
|
23
|
+
var RelayDefaultMissingFieldHandlers = require("./RelayDefaultMissingFieldHandlers");
|
|
24
|
+
|
|
25
|
+
var RelayInMemoryRecordSource = require("./RelayInMemoryRecordSource");
|
|
26
|
+
|
|
27
|
+
var RelayModernQueryExecutor = require("./RelayModernQueryExecutor");
|
|
28
|
+
|
|
29
|
+
var RelayObservable = require("./RelayObservable");
|
|
30
|
+
|
|
31
|
+
var RelayPublishQueue = require("./RelayPublishQueue");
|
|
32
|
+
|
|
33
|
+
var defaultGetDataID = require("./defaultGetDataID");
|
|
34
|
+
|
|
35
|
+
var invariant = require("fbjs/lib/invariant");
|
|
36
|
+
|
|
37
|
+
var normalizeRelayPayload = require("./normalizeRelayPayload");
|
|
38
|
+
|
|
39
|
+
var warning = require("fbjs/lib/warning");
|
|
40
|
+
|
|
13
41
|
var RelayModernEnvironment =
|
|
14
42
|
/*#__PURE__*/
|
|
15
43
|
function () {
|
|
16
44
|
function RelayModernEnvironment(config) {
|
|
17
45
|
var _this = this;
|
|
18
46
|
|
|
47
|
+
var _config$UNSTABLE_DO_N, _config$publishQueue, _config$scheduler, _config$missingFieldH;
|
|
48
|
+
|
|
19
49
|
this.configName = config.configName;
|
|
20
|
-
var handlerProvider = config.handlerProvider ? config.handlerProvider :
|
|
50
|
+
var handlerProvider = config.handlerProvider ? config.handlerProvider : RelayDefaultHandlerProvider;
|
|
21
51
|
var operationLoader = config.operationLoader;
|
|
22
52
|
|
|
23
53
|
if (process.env.NODE_ENV !== "production") {
|
|
24
54
|
if (operationLoader != null) {
|
|
25
|
-
!(typeof operationLoader === 'object' && typeof operationLoader.get === 'function' && typeof operationLoader.load === 'function') ? process.env.NODE_ENV !== "production" ?
|
|
55
|
+
!(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;
|
|
26
56
|
}
|
|
27
57
|
}
|
|
28
58
|
|
|
29
59
|
this._operationLoader = operationLoader;
|
|
30
60
|
this._network = config.network;
|
|
31
|
-
this.
|
|
61
|
+
this._getDataID = (_config$UNSTABLE_DO_N = config.UNSTABLE_DO_NOT_USE_getDataID) !== null && _config$UNSTABLE_DO_N !== void 0 ? _config$UNSTABLE_DO_N : defaultGetDataID;
|
|
62
|
+
this._publishQueue = (_config$publishQueue = config.publishQueue) !== null && _config$publishQueue !== void 0 ? _config$publishQueue : new RelayPublishQueue(config.store, handlerProvider, this._getDataID);
|
|
63
|
+
this._scheduler = (_config$scheduler = config.scheduler) !== null && _config$scheduler !== void 0 ? _config$scheduler : null;
|
|
32
64
|
this._store = config.store;
|
|
33
|
-
this.unstable_internal =
|
|
65
|
+
this.unstable_internal = (0, _objectSpread2["default"])({}, RelayCore, {
|
|
66
|
+
getOperationTracker: function getOperationTracker() {
|
|
67
|
+
return _this._operationTracker;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
34
70
|
|
|
35
71
|
this.__setNet = function (newNet) {
|
|
36
72
|
return _this._network = newNet;
|
|
37
|
-
};
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
if (process.env.NODE_ENV !== "production") {
|
|
76
|
+
var _require = require("./StoreInspector"),
|
|
77
|
+
inspect = _require.inspect;
|
|
78
|
+
|
|
79
|
+
this.DEBUG_inspect = function (dataID) {
|
|
80
|
+
return inspect(_this, dataID);
|
|
81
|
+
};
|
|
82
|
+
} // Register this Relay Environment with Relay DevTools if it exists.
|
|
38
83
|
// Note: this must always be the last step in the constructor.
|
|
39
84
|
|
|
40
85
|
|
|
@@ -46,8 +91,10 @@ function () {
|
|
|
46
91
|
devToolsHook.registerEnvironment(this);
|
|
47
92
|
}
|
|
48
93
|
|
|
49
|
-
|
|
50
|
-
|
|
94
|
+
this._missingFieldHandlers = (_config$missingFieldH = config.missingFieldHandlers) !== null && _config$missingFieldH !== void 0 ? _config$missingFieldH : RelayDefaultMissingFieldHandlers;
|
|
95
|
+
|
|
96
|
+
if (config.operationTracker != null) {
|
|
97
|
+
this._operationTracker = config.operationTracker;
|
|
51
98
|
}
|
|
52
99
|
}
|
|
53
100
|
|
|
@@ -113,8 +160,12 @@ function () {
|
|
|
113
160
|
};
|
|
114
161
|
|
|
115
162
|
_proto.commitPayload = function commitPayload(operationDescriptor, payload) {
|
|
116
|
-
// Do not handle stripped nulls when
|
|
117
|
-
var relayPayload =
|
|
163
|
+
// Do not handle stripped nulls when committing a payload
|
|
164
|
+
var relayPayload = normalizeRelayPayload(operationDescriptor.root, payload, null
|
|
165
|
+
/* errors */
|
|
166
|
+
, {
|
|
167
|
+
getDataID: this._getDataID
|
|
168
|
+
});
|
|
118
169
|
|
|
119
170
|
this._publishQueue.commitPayload(operationDescriptor, relayPayload);
|
|
120
171
|
|
|
@@ -140,9 +191,8 @@ function () {
|
|
|
140
191
|
};
|
|
141
192
|
|
|
142
193
|
_proto._checkSelectorAndHandleMissingFields = function _checkSelectorAndHandleMissingFields(selector, handlers) {
|
|
143
|
-
var target = new
|
|
144
|
-
|
|
145
|
-
var result = require("./DataChecker").check(this._store.getSource(), target, selector, handlers, this._operationLoader);
|
|
194
|
+
var target = new RelayInMemoryRecordSource();
|
|
195
|
+
var result = DataChecker.check(this._store.getSource(), target, selector, handlers, this._operationLoader, this._getDataID);
|
|
146
196
|
|
|
147
197
|
if (target.size() > 0) {
|
|
148
198
|
this._publishQueue.commitSource(target);
|
|
@@ -151,7 +201,7 @@ function () {
|
|
|
151
201
|
}
|
|
152
202
|
|
|
153
203
|
return result;
|
|
154
|
-
}
|
|
204
|
+
}
|
|
155
205
|
/**
|
|
156
206
|
* Returns an Observable of GraphQLResponse resulting from executing the
|
|
157
207
|
* provided Query or Subscription operation, each result of which is then
|
|
@@ -160,7 +210,7 @@ function () {
|
|
|
160
210
|
* Note: Observables are lazy, so calling this method will do nothing until
|
|
161
211
|
* the result is subscribed to: environment.execute({...}).subscribe({...}).
|
|
162
212
|
*/
|
|
163
|
-
|
|
213
|
+
;
|
|
164
214
|
|
|
165
215
|
_proto.execute = function execute(_ref2) {
|
|
166
216
|
var _this3 = this;
|
|
@@ -168,114 +218,26 @@ function () {
|
|
|
168
218
|
var operation = _ref2.operation,
|
|
169
219
|
cacheConfig = _ref2.cacheConfig,
|
|
170
220
|
updater = _ref2.updater;
|
|
171
|
-
return
|
|
172
|
-
var
|
|
173
|
-
var subscriptions = new Set();
|
|
174
|
-
|
|
175
|
-
function start(subscription) {
|
|
176
|
-
// NOTE: store the subscription object on the observer so that it
|
|
177
|
-
// can be cleaned up in complete() or the dispose function.
|
|
178
|
-
this._subscription = subscription;
|
|
179
|
-
subscriptions.add(subscription);
|
|
180
|
-
}
|
|
221
|
+
return RelayObservable.create(function (sink) {
|
|
222
|
+
var source = _this3._network.execute(operation.node.params, operation.variables, cacheConfig || {});
|
|
181
223
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
var _response$extensions;
|
|
194
|
-
|
|
195
|
-
var payload = require("./normalizePayload")(operation, response);
|
|
196
|
-
|
|
197
|
-
var isOptimistic = ((_response$extensions = response.extensions) === null || _response$extensions === void 0 ? void 0 : _response$extensions.isOptimistic) === true;
|
|
198
|
-
processRelayPayload(payload, operation, updater, isOptimistic);
|
|
199
|
-
sink.next(response);
|
|
200
|
-
} // Each RelayResponsePayload contains both data to publish to the store
|
|
201
|
-
// immediately, but may also contain matchPayloads that need to be
|
|
202
|
-
// asynchronously normalized into RelayResponsePayloads, which may
|
|
203
|
-
// themselves have matchPayloads: this function is recursive and relies
|
|
204
|
-
// on GraphQL queries *disallowing* recursion to ensure termination.
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
var processRelayPayload = function processRelayPayload(payload) {
|
|
208
|
-
var operationDescriptor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
209
|
-
var payloadUpdater = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
210
|
-
var isOptimistic = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
211
|
-
var matchPayloads = payload.matchPayloads;
|
|
212
|
-
|
|
213
|
-
if (matchPayloads && matchPayloads.length) {
|
|
214
|
-
var operationLoader = _this3._operationLoader;
|
|
215
|
-
!operationLoader ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayModernEnvironment: Expected an operationLoader to be ' + 'configured when using `@match`.') : require("fbjs/lib/invariant")(false) : void 0;
|
|
216
|
-
matchPayloads.forEach(function (matchPayload) {
|
|
217
|
-
processMatchPayload(processRelayPayload, operationLoader, matchPayload).subscribe({
|
|
218
|
-
complete: complete,
|
|
219
|
-
error: sink.error,
|
|
220
|
-
start: start
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (isOptimistic) {
|
|
226
|
-
!(optimisticResponse === null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'environment.execute: only support one optimistic response per ' + 'execute.') : require("fbjs/lib/invariant")(false) : void 0;
|
|
227
|
-
optimisticResponse = {
|
|
228
|
-
source: payload.source,
|
|
229
|
-
fieldPayloads: payload.fieldPayloads
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
_this3._publishQueue.applyUpdate(optimisticResponse);
|
|
233
|
-
|
|
234
|
-
_this3._publishQueue.run();
|
|
235
|
-
} else {
|
|
236
|
-
if (optimisticResponse !== null) {
|
|
237
|
-
_this3._publishQueue.revertUpdate(optimisticResponse);
|
|
238
|
-
|
|
239
|
-
optimisticResponse = null;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if (operationDescriptor && payloadUpdater) {
|
|
243
|
-
_this3._publishQueue.commitPayload(operationDescriptor, payload, payloadUpdater);
|
|
244
|
-
} else {
|
|
245
|
-
_this3._publishQueue.commitRelayPayload(payload);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
_this3._publishQueue.run();
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
var node = operation.node;
|
|
253
|
-
|
|
254
|
-
_this3._network.execute(node.params, operation.variables, cacheConfig || {}).subscribe({
|
|
255
|
-
complete: complete,
|
|
256
|
-
next: next,
|
|
257
|
-
error: sink.error,
|
|
258
|
-
start: start
|
|
224
|
+
var executor = RelayModernQueryExecutor.execute({
|
|
225
|
+
operation: operation,
|
|
226
|
+
operationLoader: _this3._operationLoader,
|
|
227
|
+
optimisticUpdate: null,
|
|
228
|
+
publishQueue: _this3._publishQueue,
|
|
229
|
+
scheduler: _this3._scheduler,
|
|
230
|
+
sink: sink,
|
|
231
|
+
source: source,
|
|
232
|
+
updater: updater,
|
|
233
|
+
operationTracker: _this3._operationTracker,
|
|
234
|
+
getDataID: _this3._getDataID
|
|
259
235
|
});
|
|
260
|
-
|
|
261
236
|
return function () {
|
|
262
|
-
|
|
263
|
-
subscriptions.forEach(function (sub) {
|
|
264
|
-
return sub.unsubscribe();
|
|
265
|
-
});
|
|
266
|
-
subscriptions.clear();
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
if (optimisticResponse !== null) {
|
|
270
|
-
_this3._publishQueue.revertUpdate(optimisticResponse);
|
|
271
|
-
|
|
272
|
-
optimisticResponse = null;
|
|
273
|
-
|
|
274
|
-
_this3._publishQueue.run();
|
|
275
|
-
}
|
|
237
|
+
return executor.cancel();
|
|
276
238
|
};
|
|
277
239
|
});
|
|
278
|
-
}
|
|
240
|
+
}
|
|
279
241
|
/**
|
|
280
242
|
* Returns an Observable of GraphQLResponse resulting from executing the
|
|
281
243
|
* provided Mutation operation, the result of which is then normalized and
|
|
@@ -286,7 +248,7 @@ function () {
|
|
|
286
248
|
* the result is subscribed to:
|
|
287
249
|
* environment.executeMutation({...}).subscribe({...}).
|
|
288
250
|
*/
|
|
289
|
-
|
|
251
|
+
;
|
|
290
252
|
|
|
291
253
|
_proto.executeMutation = function executeMutation(_ref3) {
|
|
292
254
|
var _this4 = this;
|
|
@@ -296,80 +258,84 @@ function () {
|
|
|
296
258
|
optimisticUpdater = _ref3.optimisticUpdater,
|
|
297
259
|
updater = _ref3.updater,
|
|
298
260
|
uploadables = _ref3.uploadables;
|
|
299
|
-
|
|
261
|
+
return RelayObservable.create(function (sink) {
|
|
262
|
+
var optimisticUpdate;
|
|
300
263
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
operation: operation,
|
|
304
|
-
selectorStoreUpdater: optimisticUpdater,
|
|
305
|
-
response: optimisticResponse || null
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
var node = operation.node;
|
|
310
|
-
return this._network.execute(node.params, operation.variables, {
|
|
311
|
-
force: true
|
|
312
|
-
}, uploadables)["do"]({
|
|
313
|
-
start: function start() {
|
|
314
|
-
if (optimisticUpdate) {
|
|
315
|
-
_this4._publishQueue.applyUpdate(optimisticUpdate);
|
|
316
|
-
|
|
317
|
-
_this4._publishQueue.run();
|
|
318
|
-
}
|
|
319
|
-
},
|
|
320
|
-
next: function next(payload) {
|
|
321
|
-
if (optimisticUpdate) {
|
|
322
|
-
_this4._publishQueue.revertUpdate(optimisticUpdate);
|
|
264
|
+
if (optimisticResponse || optimisticUpdater) {
|
|
265
|
+
var _optimisticResponse;
|
|
323
266
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
_this4._publishQueue.run();
|
|
330
|
-
},
|
|
331
|
-
error: function (_error) {
|
|
332
|
-
function error(_x) {
|
|
333
|
-
return _error.apply(this, arguments);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
error.toString = function () {
|
|
337
|
-
return _error.toString();
|
|
267
|
+
optimisticUpdate = {
|
|
268
|
+
operation: operation,
|
|
269
|
+
selectorStoreUpdater: optimisticUpdater,
|
|
270
|
+
response: (_optimisticResponse = optimisticResponse) !== null && _optimisticResponse !== void 0 ? _optimisticResponse : null
|
|
338
271
|
};
|
|
272
|
+
}
|
|
339
273
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
_this4._publishQueue.revertUpdate(optimisticUpdate);
|
|
344
|
-
|
|
345
|
-
optimisticUpdate = undefined;
|
|
274
|
+
var source = _this4._network.execute(operation.node.params, operation.variables, {
|
|
275
|
+
force: true
|
|
276
|
+
}, uploadables);
|
|
346
277
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
278
|
+
var executor = RelayModernQueryExecutor.execute({
|
|
279
|
+
operation: operation,
|
|
280
|
+
operationLoader: _this4._operationLoader,
|
|
281
|
+
optimisticUpdate: optimisticUpdate,
|
|
282
|
+
publishQueue: _this4._publishQueue,
|
|
283
|
+
scheduler: _this4._scheduler,
|
|
284
|
+
sink: sink,
|
|
285
|
+
source: source,
|
|
286
|
+
updater: updater,
|
|
287
|
+
operationTracker: _this4._operationTracker,
|
|
288
|
+
getDataID: _this4._getDataID
|
|
289
|
+
});
|
|
290
|
+
return function () {
|
|
291
|
+
return executor.cancel();
|
|
292
|
+
};
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Returns an Observable of GraphQLResponse resulting from executing the
|
|
297
|
+
* provided Query or Subscription operation responses, the result of which is
|
|
298
|
+
* then normalized and comitted to the publish queue.
|
|
299
|
+
*
|
|
300
|
+
* Note: Observables are lazy, so calling this method will do nothing until
|
|
301
|
+
* the result is subscribed to:
|
|
302
|
+
* environment.executeWithSource({...}).subscribe({...}).
|
|
303
|
+
*/
|
|
304
|
+
;
|
|
353
305
|
|
|
354
|
-
|
|
306
|
+
_proto.executeWithSource = function executeWithSource(_ref4) {
|
|
307
|
+
var _this5 = this;
|
|
355
308
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
309
|
+
var operation = _ref4.operation,
|
|
310
|
+
source = _ref4.source;
|
|
311
|
+
return RelayObservable.create(function (sink) {
|
|
312
|
+
var executor = RelayModernQueryExecutor.execute({
|
|
313
|
+
operation: operation,
|
|
314
|
+
operationLoader: _this5._operationLoader,
|
|
315
|
+
optimisticUpdate: null,
|
|
316
|
+
publishQueue: _this5._publishQueue,
|
|
317
|
+
scheduler: _this5._scheduler,
|
|
318
|
+
sink: sink,
|
|
319
|
+
source: source,
|
|
320
|
+
getDataID: _this5._getDataID
|
|
321
|
+
});
|
|
322
|
+
return function () {
|
|
323
|
+
return executor.cancel();
|
|
324
|
+
};
|
|
359
325
|
});
|
|
360
|
-
}
|
|
326
|
+
}
|
|
361
327
|
/**
|
|
362
328
|
* @deprecated Use Environment.execute().subscribe()
|
|
363
329
|
*/
|
|
330
|
+
;
|
|
364
331
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'environment.sendQuery() is deprecated. Update to the latest ' + 'version of react-relay, and use environment.execute().') : void 0;
|
|
332
|
+
_proto.sendQuery = function sendQuery(_ref5) {
|
|
333
|
+
var cacheConfig = _ref5.cacheConfig,
|
|
334
|
+
onCompleted = _ref5.onCompleted,
|
|
335
|
+
onError = _ref5.onError,
|
|
336
|
+
onNext = _ref5.onNext,
|
|
337
|
+
operation = _ref5.operation;
|
|
338
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'environment.sendQuery() is deprecated. Update to the latest ' + 'version of react-relay, and use environment.execute().') : void 0;
|
|
373
339
|
return this.execute({
|
|
374
340
|
operation: operation,
|
|
375
341
|
cacheConfig: cacheConfig
|
|
@@ -378,21 +344,21 @@ function () {
|
|
|
378
344
|
onError: onError,
|
|
379
345
|
onCompleted: onCompleted
|
|
380
346
|
});
|
|
381
|
-
}
|
|
347
|
+
}
|
|
382
348
|
/**
|
|
383
349
|
* @deprecated Use Environment.executeMutation().subscribe()
|
|
384
350
|
*/
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
_proto.sendMutation = function sendMutation(
|
|
388
|
-
var onCompleted =
|
|
389
|
-
onError =
|
|
390
|
-
operation =
|
|
391
|
-
optimisticResponse =
|
|
392
|
-
optimisticUpdater =
|
|
393
|
-
updater =
|
|
394
|
-
uploadables =
|
|
395
|
-
process.env.NODE_ENV !== "production" ?
|
|
351
|
+
;
|
|
352
|
+
|
|
353
|
+
_proto.sendMutation = function sendMutation(_ref6) {
|
|
354
|
+
var onCompleted = _ref6.onCompleted,
|
|
355
|
+
onError = _ref6.onError,
|
|
356
|
+
operation = _ref6.operation,
|
|
357
|
+
optimisticResponse = _ref6.optimisticResponse,
|
|
358
|
+
optimisticUpdater = _ref6.optimisticUpdater,
|
|
359
|
+
updater = _ref6.updater,
|
|
360
|
+
uploadables = _ref6.uploadables;
|
|
361
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'environment.sendMutation() is deprecated. Update to the latest ' + 'version of react-relay, and use environment.executeMutation().') : void 0;
|
|
396
362
|
return this.executeMutation({
|
|
397
363
|
operation: operation,
|
|
398
364
|
optimisticResponse: optimisticResponse,
|
|
@@ -418,51 +384,7 @@ function () {
|
|
|
418
384
|
};
|
|
419
385
|
|
|
420
386
|
return RelayModernEnvironment;
|
|
421
|
-
}();
|
|
422
|
-
/**
|
|
423
|
-
* Processes a MatchFieldPayload, asynchronously resolving the fragment,
|
|
424
|
-
* using it to normalize the field data into a RelayResponsePayload.
|
|
425
|
-
* Because @match fields may contain other @match fields, the result of
|
|
426
|
-
* normalizing `matchPayload` may contain *other* MatchFieldPayloads:
|
|
427
|
-
* the processRelayPayload() callback is responsible for publishing
|
|
428
|
-
* both the normalize payload's source as well as recursively calling
|
|
429
|
-
* this function for any matchPayloads it contains.
|
|
430
|
-
*
|
|
431
|
-
* @private
|
|
432
|
-
*/
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
function processMatchPayload(processRelayPayload, operationLoader, matchPayload) {
|
|
436
|
-
return require("./RelayObservable").from(new Promise(function (resolve, reject) {
|
|
437
|
-
operationLoader.load(matchPayload.operationReference).then(resolve, reject);
|
|
438
|
-
})).map(function (operation) {
|
|
439
|
-
if (operation == null) {
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
var selector = {
|
|
444
|
-
dataID: matchPayload.dataID,
|
|
445
|
-
variables: matchPayload.variables,
|
|
446
|
-
node: operation
|
|
447
|
-
};
|
|
448
|
-
var source = new (require("./RelayInMemoryRecordSource"))();
|
|
449
|
-
|
|
450
|
-
var matchRecord = require("./RelayModernRecord").create(matchPayload.dataID, matchPayload.typeName);
|
|
451
|
-
|
|
452
|
-
source.set(matchPayload.dataID, matchRecord);
|
|
453
|
-
|
|
454
|
-
var normalizeResult = require("./RelayResponseNormalizer").normalize(source, selector, matchPayload.data);
|
|
455
|
-
|
|
456
|
-
var relayPayload = {
|
|
457
|
-
errors: null,
|
|
458
|
-
// Errors are handled as part of the parent GraphQLResponse
|
|
459
|
-
fieldPayloads: normalizeResult.fieldPayloads,
|
|
460
|
-
matchPayloads: normalizeResult.matchPayloads,
|
|
461
|
-
source: source
|
|
462
|
-
};
|
|
463
|
-
processRelayPayload(relayPayload);
|
|
464
|
-
});
|
|
465
|
-
} // Add a sigil for detection by `isRelayModernEnvironment()` to avoid a
|
|
387
|
+
}(); // Add a sigil for detection by `isRelayModernEnvironment()` to avoid a
|
|
466
388
|
// realm-specific instanceof check, and to aid in module tree-shaking to
|
|
467
389
|
// avoid requiring all of RelayRuntime just to detect its environment.
|
|
468
390
|
|
|
@@ -0,0 +1,72 @@
|
|
|
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 invariant = require("fbjs/lib/invariant");
|
|
13
|
+
|
|
14
|
+
var mapObject = require("fbjs/lib/mapObject");
|
|
15
|
+
|
|
16
|
+
var _require = require("./RelayStoreUtils"),
|
|
17
|
+
FRAGMENT_OWNER_KEY = _require.FRAGMENT_OWNER_KEY;
|
|
18
|
+
|
|
19
|
+
function getSingularFragmentOwner(fragmentNode, fragmentRef) {
|
|
20
|
+
var _fragmentRef$FRAGMENT;
|
|
21
|
+
|
|
22
|
+
if (fragmentRef == null) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
!(typeof fragmentRef === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernFragmentOwner: Expected value for fragment `%s` to be an object, got ' + '`%s`.', fragmentNode.name, typeof fragmentRef) : invariant(false) : void 0;
|
|
27
|
+
var owner = (_fragmentRef$FRAGMENT = fragmentRef[FRAGMENT_OWNER_KEY]) !== null && _fragmentRef$FRAGMENT !== void 0 ? _fragmentRef$FRAGMENT : null;
|
|
28
|
+
return owner;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getPluralFragmentOwner(fragmentNode, fragmentRef) {
|
|
32
|
+
return fragmentRef.map(function (ref) {
|
|
33
|
+
return getSingularFragmentOwner(fragmentNode, ref);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @public
|
|
38
|
+
* Extracts the fragment owner associated with the given fragment reference.
|
|
39
|
+
* TODO(T39494051) - This helper function will become unnecessary once we're
|
|
40
|
+
* using fragment ownership by default
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
function getFragmentOwner(fragmentNode, fragmentRef) {
|
|
45
|
+
if (Array.isArray(fragmentRef)) {
|
|
46
|
+
return getPluralFragmentOwner(fragmentNode, fragmentRef);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return getSingularFragmentOwner(fragmentNode, fragmentRef);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @public
|
|
53
|
+
* Given a map of key -> fragment nodes, and a map of key -> fragment refs,
|
|
54
|
+
* extracts and returns a map of key -> associated fragment owner.
|
|
55
|
+
* This is useful to construct the argument required by getSelectorsFromObject
|
|
56
|
+
* TODO(T39494051) - This helper function will become unnecessary once we're
|
|
57
|
+
* using fragment ownership by default
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
function getFragmentOwners(fragmentNodes, fragmentRefs) {
|
|
62
|
+
return mapObject(fragmentNodes, function (fragmentNode, key) {
|
|
63
|
+
var fragmentRef = fragmentRefs[key];
|
|
64
|
+
return getFragmentOwner(fragmentNode, // $FlowFixMe - TODO T39154660 Use FragmentPointer type instead of mixed
|
|
65
|
+
fragmentRef);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
module.exports = {
|
|
70
|
+
getFragmentOwner: getFragmentOwner,
|
|
71
|
+
getFragmentOwners: getFragmentOwners
|
|
72
|
+
};
|